| 40 | 40 | | pub loud: bool, |
| 41 | 41 | | /// Whether to print a goodbye after the greeting (`--bye`). |
| 42 | 42 | | pub bye: bool, |
| 43 | + | /// Whether to print a wave after the greeting (`--wave`). |
| 44 | + | pub wave: bool, |
| 43 | 45 | | } |
| 44 | 46 | | |
| 45 | 47 | | impl Default for Options { |
| ⋯ |
| 53 | 55 | | quiet: false, |
| 54 | 56 | | loud: false, |
| 55 | 57 | | bye: false, |
| 58 | + | wave: false, |
| 56 | 59 | | } |
| 57 | 60 | | } |
| 58 | 61 | | } |
| ⋯ |
| 82 | 85 | | options.loud = true; |
| 83 | 86 | | } else if arg == "--bye" { |
| 84 | 87 | | options.bye = true; |
| 88 | + | } else if arg == "--wave" { |
| 89 | + | options.wave = true; |
| 85 | 90 | | } else if arg == "--times" { |
| 86 | 91 | | let value = args |
| 87 | 92 | | .next() |
| ⋯ |
| 129 | 134 | | } |
| 130 | 135 | | } |
| 131 | 136 | | |
| 137 | + | /// The wave printed by `--wave`. |
| 138 | + | pub fn wave() -> &'static str { |
| 139 | + | "o/" |
| 140 | + | } |
| 141 | + | |
| 132 | 142 | | /// The farewell for `name`. |
| 133 | 143 | | pub fn farewell(name: &str) -> String { |
| 134 | 144 | | let trimmed = name.trim(); |
| ⋯ |
| 157 | 167 | | } |
| 158 | 168 | | |
| 159 | 169 | | #[test] |
| 170 | + | fn parse_args_wave() { |
| 171 | + | assert!(parse_args(args(&["--wave", "Ada"])).unwrap().wave); |
| 172 | + | assert!(!parse_args(args(&["Ada"])).unwrap().wave); |
| 173 | + | } |
| 174 | + | |
| 175 | + | #[test] |
| 176 | + | fn wave_is_o_slash() { |
| 177 | + | assert_eq!(wave(), "o/"); |
| 178 | + | } |
| 179 | + | |
| 180 | + | #[test] |
| 160 | 181 | | fn parse_args_loud() { |
| 161 | 182 | | assert!(parse_args(args(&["--loud", "Ada"])).unwrap().loud); |
| 162 | 183 | | assert!(parse_args(args(&["-L", "Ada"])).unwrap().loud); |