mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-11 21:29:18 +00:00
feat: add strings5.rs exercise
This commit is contained in:
parent
b3322e36ae
commit
e3796dcc72
30
exercises/strings/strings5.rs
Normal file
30
exercises/strings/strings5.rs
Normal file
@ -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.");
|
||||
}
|
||||
}
|
||||
@ -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]]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user