| 36 | 36 | | pub lang: Lang, |
| 37 | 37 | | /// Whether to print nothing (`--quiet`). |
| 38 | 38 | | pub quiet: bool, |
| 39 | + | /// Whether to end the greeting with three exclamation marks (`--loud`). |
| 40 | + | pub loud: bool, |
| 39 | 41 | | } |
| 40 | 42 | | |
| 41 | 43 | | impl Default for Options { |
| ⋯ |
| 47 | 49 | | times: 1, |
| 48 | 50 | | lang: Lang::En, |
| 49 | 51 | | quiet: false, |
| 52 | + | loud: false, |
| 50 | 53 | | } |
| 51 | 54 | | } |
| 52 | 55 | | } |
| ⋯ |
| 72 | 75 | | options.version = true; |
| 73 | 76 | | } else if arg == "--quiet" { |
| 74 | 77 | | options.quiet = true; |
| 78 | + | } else if arg == "--loud" { |
| 79 | + | options.loud = true; |
| 75 | 80 | | } else if arg == "--times" { |
| 76 | 81 | | let value = args |
| 77 | 82 | | .next() |
| ⋯ |
| 98 | 103 | | text.to_uppercase() |
| 99 | 104 | | } |
| 100 | 105 | | |
| 106 | + | /// `text` with its final exclamation mark replaced by three. |
| 107 | + | pub fn loud(text: &str) -> String { |
| 108 | + | format!("{}!!!", text.strip_suffix('!').unwrap_or(text)) |
| 109 | + | } |
| 110 | + | |
| 101 | 111 | | /// The greeting for `name`. |
| 102 | 112 | | pub fn greeting(name: &str) -> String { |
| 103 | 113 | | greeting_in(name, Lang::En) |
| ⋯ |
| 136 | 146 | | } |
| 137 | 147 | | |
| 138 | 148 | | #[test] |
| 149 | + | fn parse_args_loud() { |
| 150 | + | assert!(parse_args(args(&["--loud", "Ada"])).unwrap().loud); |
| 151 | + | assert!(!parse_args(args(&["Ada"])).unwrap().loud); |
| 152 | + | } |
| 153 | + | |
| 154 | + | #[test] |
| 155 | + | fn loud_uses_three_exclamation_marks() { |
| 156 | + | assert_eq!(loud(&greeting("Ada")), "Hi, Ada!!!"); |
| 157 | + | } |
| 158 | + | |
| 159 | + | #[test] |
| 139 | 160 | | fn parse_args_no_args() { |
| 140 | 161 | | assert_eq!(parse_args(args(&[])).unwrap().name, None); |
| 141 | 162 | | } |