1fn trim_me(input: &str) -> &str {
2 // TODO: Remove whitespace from both ends of a string.
3 input.trim()
4}
5
6fn compose_me(input: &str) -> String {
7 // TODO: Add " world!" to the string! There are multiple ways to do this.
8 format!("{} world!", input)
9}
10
11fn replace_me(input: &str) -> String {
12 // TODO: Replace "cars" in the string with "balloons".
13 input.replace("cars", "balloons")
14}
15
16fn main() {
17 // You can optionally experiment here.
18}
19
20#[cfg(test)]
21mod tests {
22 use super::*;
23
24 #[test]
25 fn trim_a_string() {
26 assert_eq!(trim_me("Hello! "), "Hello!");
27 assert_eq!(trim_me(" What's up!"), "What's up!");
28 assert_eq!(trim_me(" Hola! "), "Hola!");
29 }
30
31 #[test]
32 fn compose_a_string() {
33 assert_eq!(compose_me("Hello"), "Hello world!");
34 assert_eq!(compose_me("Goodbye"), "Goodbye world!");
35 }
36
37 #[test]
38 fn replace_a_string() {
39 assert_eq!(
40 replace_me("I think cars are cool"),
41 "I think balloons are cool",
42 );
43 assert_eq!(
44 replace_me("I love to look at cars"),
45 "I love to look at balloons",
46 );
47 }
48}