From 1c4c8764ed118740cd4cee73272ddc6cceb9d959 Mon Sep 17 00:00:00 2001 From: Viacheslav Avramenko Date: Mon, 21 Oct 2019 14:23:06 +0200 Subject: [PATCH] feat: Added exercise for struct update syntax --- exercises/structs/structs2.rs | 45 +++++++++++++++++++++++++++++++++++ info.toml | 4 ++++ src/verify.rs | 6 +---- 3 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 exercises/structs/structs2.rs diff --git a/exercises/structs/structs2.rs b/exercises/structs/structs2.rs new file mode 100644 index 00000000..db381e7b --- /dev/null +++ b/exercises/structs/structs2.rs @@ -0,0 +1,45 @@ +// structs2.rs +// Address all the TODOs to make the tests pass! +// No hints, just do it! + +#[derive(Debug)] +struct Order { + name: String, + year: u32, + made_by_phone: bool, + made_by_mobile: bool, + made_by_email: bool, + item_number: u32, + count: u32, +} + +fn create_order_template() -> Order { + Order { + name: String::from("Bob"), + year: 2019, + made_by_phone: false, + made_by_mobile: false, + made_by_email: true, + item_number: 123, + count: 0, + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn your_order() { + let order_template = create_order_template(); + // TODO: Create your own order using the update syntax and template above! + // let your_order = + assert_eq!(your_order.name, "Hacker in Rust"); + assert_eq!(your_order.year, order_template.year); + assert_eq!(your_order.made_by_phone, order_template.made_by_phone); + assert_eq!(your_order.made_by_mobile, order_template.made_by_mobile); + assert_eq!(your_order.made_by_email, order_template.made_by_email); + assert_eq!(your_order.item_number, order_template.item_number); + assert_eq!(your_order.count, 1); + } +} diff --git a/info.toml b/info.toml index 08114de6..5e353344 100644 --- a/info.toml +++ b/info.toml @@ -82,6 +82,10 @@ mode = "compile" path = "exercises/structs/structs1.rs" mode = "test" +[[exercises]] +path = "exercises/structs/structs2.rs" +mode = "test" + # TESTS [[exercises]] diff --git a/src/verify.rs b/src/verify.rs index 47781807..d066afaf 100644 --- a/src/verify.rs +++ b/src/verify.rs @@ -19,11 +19,7 @@ fn compile_only(exercise: &Exercise) -> Result<(), ()> { let compile_output = exercise.compile(); progress_bar.finish_and_clear(); if compile_output.status.success() { - let formatstr = format!( - "{} Successfully compiled {}!", - Emoji("✅", "✓"), - exercise - ); + let formatstr = format!("{} Successfully compiled {}!", Emoji("✅", "✓"), exercise); println!("{}", style(formatstr).green()); exercise.clean(); Ok(())