Merge pull request #1549 from IVIURRAY/enums3-message-test
fix(enums3): add test for message
This commit is contained in:
commit
0d2a1bdef1
|
@ -17,6 +17,7 @@ struct State {
|
||||||
color: (u8, u8, u8),
|
color: (u8, u8, u8),
|
||||||
position: Point,
|
position: Point,
|
||||||
quit: bool,
|
quit: bool,
|
||||||
|
message: String
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
|
@ -28,9 +29,7 @@ impl State {
|
||||||
self.quit = true;
|
self.quit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn echo(&self, s: String) {
|
fn echo(&mut self, s: String) { self.message = s }
|
||||||
println!("{}", s);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn move_position(&mut self, p: Point) {
|
fn move_position(&mut self, p: Point) {
|
||||||
self.position = p;
|
self.position = p;
|
||||||
|
@ -52,6 +51,7 @@ mod tests {
|
||||||
quit: false,
|
quit: false,
|
||||||
position: Point { x: 0, y: 0 },
|
position: Point { x: 0, y: 0 },
|
||||||
color: (0, 0, 0),
|
color: (0, 0, 0),
|
||||||
|
message: "hello world".to_string(),
|
||||||
};
|
};
|
||||||
state.process(Message::ChangeColor(255, 0, 255));
|
state.process(Message::ChangeColor(255, 0, 255));
|
||||||
state.process(Message::Echo(String::from("hello world")));
|
state.process(Message::Echo(String::from("hello world")));
|
||||||
|
@ -62,5 +62,6 @@ mod tests {
|
||||||
assert_eq!(state.position.x, 10);
|
assert_eq!(state.position.x, 10);
|
||||||
assert_eq!(state.position.y, 15);
|
assert_eq!(state.position.y, 15);
|
||||||
assert_eq!(state.quit, true);
|
assert_eq!(state.quit, true);
|
||||||
|
assert_eq!(state.message, "hello world");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue