From e3796dcc72f120014ff4ff370859f5886616eb3c Mon Sep 17 00:00:00 2001 From: Michal Bazynski Date: Fri, 14 Oct 2022 14:20:08 +0200 Subject: [PATCH] feat: add strings5.rs exercise --- exercises/strings/strings5.rs | 30 ++++++++++++++++++++++++++++++ info.toml | 6 ++++++ 2 files changed, 36 insertions(+) create mode 100644 exercises/strings/strings5.rs diff --git a/exercises/strings/strings5.rs b/exercises/strings/strings5.rs new file mode 100644 index 00000000..e5a57163 --- /dev/null +++ b/exercises/strings/strings5.rs @@ -0,0 +1,30 @@ +// strings5.rs +// println!, print!, and format! use the same system for created formatted text. +// Make all tests pass by only changing the first parameter to each format! call. +// Execute `rustlings hint strings5` or use the `hint` watch subcommand for a hint. + +// I AM NOT DONE + +#[cfg(test)] +mod tests { + + //TODO only change first parameter in each format! call. + #[test] + fn greeting() { + let world = "world"; + //The basic usage you probably saw used in println! statements + assert_eq!(format!("Hello, !", world), "Hello, world!"); + + //There is a way to get the same result inline, without passing world as an argument. + assert_eq!(format!("Hello, {}!"), "Hello, world!"); + } + + #[test] + fn bond() { + //You can use the same argument multiple times, + //as well as specicfy which argument should be used for a given {} placeholder. + assert_eq!(format!("My name is {}. {} {}.", "James", "Bond"), "My name is Bond. James Bond."); + //There are also ways to specify how numbers should be displayed. + assert_eq!(format!("My code number is {}.", 7), "My code number is 007."); + } +} diff --git a/info.toml b/info.toml index a840f9ba..ada76267 100644 --- a/info.toml +++ b/info.toml @@ -460,6 +460,12 @@ path = "exercises/strings/strings4.rs" mode = "compile" hint = "No hints this time ;)" +[[exercises]] +name = "strings5" +path = "exercises/strings/strings5.rs" +mode = "test" +hint = "You can find documentation for println! / format! syntax at https://doc.rust-lang.org/std/fmt/index.html" + # MODULES [[exercises]]