summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIVIURARY <haydn.murray1@yahoo.co.uk>2023-06-08 22:14:25 +0100
committerIVIURARY <haydn.murray1@yahoo.co.uk>2023-06-08 22:14:25 +0100
commitd0a17830831121fcdbc27a1833ccbbc17bc0c02d (patch)
tree90795312632f54c2b28c7eb265cd730f47f08d8c
parent30291a3c253f08a4191cfd544ba36867612ebb7a (diff)
fix(enums3): add test for message
closes #1548
-rw-r--r--exercises/enums/enums3.rs7
1 files changed, 4 insertions, 3 deletions
diff --git a/exercises/enums/enums3.rs b/exercises/enums/enums3.rs
index a2a9d58..e75d443 100644
--- a/exercises/enums/enums3.rs
+++ b/exercises/enums/enums3.rs
@@ -17,6 +17,7 @@ struct State {
color: (u8, u8, u8),
position: Point,
quit: bool,
+ message: String
}
impl State {
@@ -28,9 +29,7 @@ impl State {
self.quit = true;
}
- fn echo(&self, s: String) {
- println!("{}", s);
- }
+ fn echo(&mut self, s: String) { self.message = s }
fn move_position(&mut self, p: Point) {
self.position = p;
@@ -52,6 +51,7 @@ mod tests {
quit: false,
position: Point { x: 0, y: 0 },
color: (0, 0, 0),
+ message: "hello world".to_string(),
};
state.process(Message::ChangeColor(255, 0, 255));
state.process(Message::Echo(String::from("hello world")));
@@ -62,5 +62,6 @@ mod tests {
assert_eq!(state.position.x, 10);
assert_eq!(state.position.y, 15);
assert_eq!(state.quit, true);
+ assert_eq!(state.message, "hello world");
}
}