Skip to content

Commit d0a1783

Browse files
committed
fix(enums3): add test for message
closes #1548
1 parent 30291a3 commit d0a1783

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

exercises/enums/enums3.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ struct State {
1717
color: (u8, u8, u8),
1818
position: Point,
1919
quit: bool,
20+
message: String
2021
}
2122

2223
impl State {
@@ -28,9 +29,7 @@ impl State {
2829
self.quit = true;
2930
}
3031

31-
fn echo(&self, s: String) {
32-
println!("{}", s);
33-
}
32+
fn echo(&mut self, s: String) { self.message = s }
3433

3534
fn move_position(&mut self, p: Point) {
3635
self.position = p;
@@ -52,6 +51,7 @@ mod tests {
5251
quit: false,
5352
position: Point { x: 0, y: 0 },
5453
color: (0, 0, 0),
54+
message: "hello world".to_string(),
5555
};
5656
state.process(Message::ChangeColor(255, 0, 255));
5757
state.process(Message::Echo(String::from("hello world")));
@@ -62,5 +62,6 @@ mod tests {
6262
assert_eq!(state.position.x, 10);
6363
assert_eq!(state.position.y, 15);
6464
assert_eq!(state.quit, true);
65+
assert_eq!(state.message, "hello world");
6566
}
6667
}

0 commit comments

Comments
 (0)