diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/command.rs | 162 |
1 files changed, 29 insertions, 133 deletions
diff --git a/src/command.rs b/src/command.rs index 9bf4e75..40801e7 100644 --- a/src/command.rs +++ b/src/command.rs | |||
| @@ -105,7 +105,7 @@ fn call_on_app(s: &mut Cursive, input: &str) { | |||
| 105 | } | 105 | } |
| 106 | } | 106 | } |
| 107 | 107 | ||
| 108 | #[derive(PartialEq, Debug)] | 108 | #[derive(PartialEq)] |
| 109 | pub enum Command { | 109 | pub enum Command { |
| 110 | Add(String, Option<u32>, bool), | 110 | Add(String, Option<u32>, bool), |
| 111 | MonthPrev, | 111 | MonthPrev, |
| @@ -220,154 +220,50 @@ mod tests { | |||
| 220 | use super::*; | 220 | use super::*; |
| 221 | 221 | ||
| 222 | #[test] | 222 | #[test] |
| 223 | fn parse_add_command() { | 223 | fn parse_add_command_with_goal() { |
| 224 | let result = Command::from_string("add eat 2"); | 224 | let command: Vec<String> = "eat healthy 3" |
| 225 | .trim() | ||
| 226 | .split(' ') | ||
| 227 | .into_iter() | ||
| 228 | .map(|s| s.to_string()) | ||
| 229 | .collect(); | ||
| 225 | 230 | ||
| 226 | assert!(result.is_ok()); | 231 | let verb = "add".to_owned(); |
| 227 | match result.unwrap() { | 232 | let auto = false; |
| 228 | Command::Add(name, goal, auto) => { | ||
| 229 | assert_eq!(name, "eat"); | ||
| 230 | assert_eq!(goal.unwrap(), 2); | ||
| 231 | assert_eq!(auto, false); | ||
| 232 | } | ||
| 233 | _ => panic!(), | ||
| 234 | } | ||
| 235 | } | ||
| 236 | |||
| 237 | #[test] | ||
| 238 | fn parse_add_command_without_goal() { | ||
| 239 | let result = Command::from_string("add eat"); | ||
| 240 | |||
| 241 | assert!(result.is_ok()); | ||
| 242 | match result.unwrap() { | ||
| 243 | Command::Add(name, goal, auto) => { | ||
| 244 | assert_eq!(name, "eat"); | ||
| 245 | assert!(goal.is_none()); | ||
| 246 | assert_eq!(auto, false); | ||
| 247 | } | ||
| 248 | _ => panic!(), | ||
| 249 | } | ||
| 250 | } | ||
| 251 | |||
| 252 | // #[test] | ||
| 253 | fn parse_add_command_with_long_name() { | ||
| 254 | let result = Command::from_string("add \"eat healthy\" 5"); | ||
| 255 | |||
| 256 | assert!(result.is_ok()); | ||
| 257 | match result.unwrap() { | ||
| 258 | Command::Add(name, goal, auto) => { | ||
| 259 | assert_eq!(name, "eat healthy"); | ||
| 260 | assert_eq!(goal.unwrap(), 5); | ||
| 261 | assert_eq!(auto, false); | ||
| 262 | } | ||
| 263 | _ => panic!(), | ||
| 264 | } | ||
| 265 | } | ||
| 266 | 233 | ||
| 267 | #[test] | 234 | let result = parse_add(verb, command, auto); |
| 268 | fn parse_add_auto_command() { | ||
| 269 | let result = Command::from_string("add-auto eat 2"); | ||
| 270 | 235 | ||
| 271 | assert!(result.is_ok()); | ||
| 272 | match result.unwrap() { | 236 | match result.unwrap() { |
| 273 | Command::Add(name, goal, auto) => { | 237 | Command::Add(name, goal, a) => { |
| 274 | assert_eq!(name, "eat"); | 238 | assert_eq!(name, "eat healthy".to_owned()); |
| 275 | assert_eq!(goal.unwrap(), 2); | 239 | assert_eq!(goal.unwrap(), 3); |
| 276 | assert_eq!(auto, true); | 240 | assert_eq!(a, auto); |
| 277 | } | 241 | } |
| 278 | _ => panic!(), | 242 | _ => panic!(), |
| 279 | } | 243 | } |
| 280 | } | 244 | } |
| 281 | 245 | ||
| 282 | #[test] | 246 | #[test] |
| 283 | fn parse_delete_command() { | 247 | fn parse_add_command_without_goal() { |
| 284 | let result = Command::from_string("delete eat"); | 248 | let command: Vec<String> = "eat healthy" |
| 285 | 249 | .trim() | |
| 286 | assert!(result.is_ok()); | 250 | .split(' ') |
| 287 | match result.unwrap() { | 251 | .into_iter() |
| 288 | Command::Delete(name) => { | 252 | .map(|s| s.to_string()) |
| 289 | assert_eq!(name, "eat"); | 253 | .collect(); |
| 290 | } | ||
| 291 | _ => panic!(), | ||
| 292 | } | ||
| 293 | } | ||
| 294 | |||
| 295 | #[test] | ||
| 296 | fn parse_track_up_command() { | ||
| 297 | let result = Command::from_string("track-up eat"); | ||
| 298 | |||
| 299 | assert!(result.is_ok()); | ||
| 300 | match result.unwrap() { | ||
| 301 | Command::TrackUp(name) => { | ||
| 302 | assert_eq!(name, "eat"); | ||
| 303 | } | ||
| 304 | _ => panic!(), | ||
| 305 | } | ||
| 306 | } | ||
| 307 | 254 | ||
| 308 | #[test] | 255 | let verb = "add".to_owned(); |
| 309 | fn parse_track_down_command() { | 256 | let auto = false; |
| 310 | let result = Command::from_string("track-down eat"); | ||
| 311 | 257 | ||
| 312 | assert!(result.is_ok()); | 258 | let result = parse_add(verb, command, auto); |
| 313 | match result.unwrap() { | ||
| 314 | Command::TrackDown(name) => { | ||
| 315 | assert_eq!(name, "eat"); | ||
| 316 | } | ||
| 317 | _ => panic!(), | ||
| 318 | } | ||
| 319 | } | ||
| 320 | |||
| 321 | #[test] | ||
| 322 | fn parse_help_command() { | ||
| 323 | let result = Command::from_string("help add"); | ||
| 324 | 259 | ||
| 325 | assert!(result.is_ok()); | ||
| 326 | match result.unwrap() { | 260 | match result.unwrap() { |
| 327 | Command::Help(name) => { | 261 | Command::Add(name, goal, a) => { |
| 328 | assert_eq!(name.unwrap(), "add"); | 262 | assert_eq!(name, "eat healthy".to_owned()); |
| 263 | assert!(goal.is_none()); | ||
| 264 | assert_eq!(a, auto); | ||
| 329 | } | 265 | } |
| 330 | _ => panic!(), | 266 | _ => panic!(), |
| 331 | } | 267 | } |
| 332 | } | 268 | } |
| 333 | |||
| 334 | #[test] | ||
| 335 | fn parse_month_prev_command() { | ||
| 336 | let result = Command::from_string("mprev"); | ||
| 337 | |||
| 338 | assert!(result.is_ok()); | ||
| 339 | assert_eq!(result.unwrap(), Command::MonthPrev); | ||
| 340 | } | ||
| 341 | |||
| 342 | #[test] | ||
| 343 | fn parse_month_next_command() { | ||
| 344 | let result = Command::from_string("mnext"); | ||
| 345 | |||
| 346 | assert!(result.is_ok()); | ||
| 347 | assert_eq!(result.unwrap(), Command::MonthNext); | ||
| 348 | } | ||
| 349 | |||
| 350 | #[test] | ||
| 351 | fn parse_quit_command() { | ||
| 352 | let result = Command::from_string("q"); | ||
| 353 | |||
| 354 | assert!(result.is_ok()); | ||
| 355 | assert_eq!(result.unwrap(), Command::Quit); | ||
| 356 | } | ||
| 357 | |||
| 358 | #[test] | ||
| 359 | fn parse_write_command() { | ||
| 360 | let result = Command::from_string("w"); | ||
| 361 | |||
| 362 | assert!(result.is_ok()); | ||
| 363 | assert_eq!(result.unwrap(), Command::Write); | ||
| 364 | } | ||
| 365 | |||
| 366 | #[test] | ||
| 367 | fn parse_no_command() { | ||
| 368 | let result = Command::from_string(""); | ||
| 369 | |||
| 370 | assert!(result.is_ok()); | ||
| 371 | assert_eq!(result.unwrap(), Command::Blank); | ||
| 372 | } | ||
| 373 | } | 269 | } |
