| 1 | use crate::{Error, Jargon, Key}; |
| 2 | |
| 3 | #[test] |
| 4 | fn short_key() { |
| 5 | let key: Key = "-a".into(); |
| 6 | |
| 7 | assert_eq!( |
| 8 | key, |
| 9 | Key::Short { |
| 10 | char: '-', |
| 11 | txt: 'a' |
| 12 | } |
| 13 | ) |
| 14 | } |
| 15 | |
| 16 | #[test] |
| 17 | fn long_key() { |
| 18 | let key: Key = "--all".into(); |
| 19 | |
| 20 | assert_eq!( |
| 21 | key, |
| 22 | Key::Long { |
| 23 | char: '-', |
| 24 | txt: "all".to_string() |
| 25 | } |
| 26 | ) |
| 27 | } |
| 28 | |
| 29 | #[test] |
| 30 | fn sub_key() { |
| 31 | let key: Key = "beans".into(); |
| 32 | |
| 33 | assert_eq!( |
| 34 | key, |
| 35 | Key::Sub { |
| 36 | txt: "beans".into(), |
| 37 | } |
| 38 | ) |
| 39 | } |
| 40 | |
| 41 | #[test] |
| 42 | fn dual_key_be() { |
| 43 | let dk: Key = ["-a", "--all"].into(); |
| 44 | |
| 45 | assert_eq!( |
| 46 | dk, |
| 47 | Key::Dual { |
| 48 | char: '-', |
| 49 | s_txt: 'a', |
| 50 | l_txt: "all".to_string(), |
| 51 | } |
| 52 | ) |
| 53 | } |
| 54 | |
| 55 | #[test] |
| 56 | fn dual_key_le() { |
| 57 | let dk: Key = ["--all", "-a"].into(); |
| 58 | |
| 59 | assert_eq!( |
| 60 | dk, |
| 61 | Key::Dual { |
| 62 | char: '-', |
| 63 | s_txt: 'a', |
| 64 | l_txt: "all".to_string(), |
| 65 | } |
| 66 | ) |
| 67 | } |
| 68 | |
| 69 | #[test] |
| 70 | #[should_panic] |
| 71 | fn dual_key_with_sub() { |
| 72 | let _: Key = ["-all", "beans"].into(); |
| 73 | } |
| 74 | |
| 75 | #[test] |
| 76 | fn fmt_short_key() { |
| 77 | let key: Key = "-a".into(); |
| 78 | assert_eq!(format!("{}", key), "-a".to_string(),) |
| 79 | } |
| 80 | |
| 81 | #[test] |
| 82 | fn fmt_long_key() { |
| 83 | let key: Key = "--all".into(); |
| 84 | assert_eq!(format!("{}", key), "--all".to_string(),) |
| 85 | } |
| 86 | |
| 87 | #[test] |
| 88 | fn fmt_dual_key() { |
| 89 | let key: Key = ["-a", "--all"].into(); |
| 90 | assert_eq!(format!("{}", key), "-a, --all".to_string(),) |
| 91 | } |
| 92 | |
| 93 | #[test] |
| 94 | fn fmt_sub_key() { |
| 95 | let key: Key = "beans".into(); |
| 96 | assert_eq!(format!("{}", key), "beans".to_string()) |
| 97 | } |
| 98 | |
| 99 | #[test] |
| 100 | fn jargon() { |
| 101 | let j = Jargon::from_vec(vec![ |
| 102 | "jargon".to_string(), |
| 103 | "-a".to_string(), |
| 104 | "-b".to_string(), |
| 105 | "beans".to_string(), |
| 106 | ]); |
| 107 | |
| 108 | assert_eq!( |
| 109 | j, |
| 110 | Jargon { |
| 111 | 0: [ |
| 112 | "jargon".to_string(), |
| 113 | "-a".to_string(), |
| 114 | "-b".to_string(), |
| 115 | "beans".to_string(), |
| 116 | ] |
| 117 | .to_vec(), |
| 118 | } |
| 119 | ) |
| 120 | } |
| 121 | |
| 122 | #[test] |
| 123 | fn jargon_finish() { |
| 124 | let mut j = Jargon::from_vec(vec![ |
| 125 | "jargon".to_string(), |
| 126 | "-a".to_string(), |
| 127 | "-b".to_string(), |
| 128 | "beans".to_string(), |
| 129 | ]); |
| 130 | |
| 131 | j.contains("-a"); |
| 132 | |
| 133 | assert_eq!(j.finish(), vec!["-b".to_string(), "beans".to_string(),]) |
| 134 | } |
| 135 | |
| 136 | #[test] |
| 137 | #[cfg(feature = "no_mut")] |
| 138 | fn jargon_contains_short_t() { |
| 139 | let j = Jargon::from_vec(vec![ |
| 140 | "jargon".to_string(), |
| 141 | "-a".to_string(), |
| 142 | "-b".to_string(), |
| 143 | "beans".to_string(), |
| 144 | ]); |
| 145 | |
| 146 | assert!(j.contains_nomut("-a")); |
| 147 | |
| 148 | assert_eq!( |
| 149 | j, |
| 150 | Jargon(vec![ |
| 151 | "jargon".to_string(), |
| 152 | "-a".to_string(), |
| 153 | "-b".to_string(), |
| 154 | "beans".to_string(), |
| 155 | ]) |
| 156 | ) |
| 157 | } |
| 158 | |
| 159 | #[test] |
| 160 | #[cfg(feature = "no_mut")] |
| 161 | fn jargon_contains_short_f() { |
| 162 | let j = Jargon::from_vec(vec![ |
| 163 | "jargon".to_string(), |
| 164 | "-b".to_string(), |
| 165 | "beans".to_string(), |
| 166 | ]); |
| 167 | |
| 168 | assert!(!j.contains_nomut("-a")); |
| 169 | |
| 170 | assert_eq!( |
| 171 | j, |
| 172 | Jargon(vec![ |
| 173 | "jargon".to_string(), |
| 174 | "-b".to_string(), |
| 175 | "beans".to_string(), |
| 176 | ]) |
| 177 | ) |
| 178 | } |
| 179 | |
| 180 | #[test] |
| 181 | fn jargon_contains_short_t_rmv() { |
| 182 | let mut j = Jargon::from_vec(vec![ |
| 183 | "jargon".to_string(), |
| 184 | "-a".to_string(), |
| 185 | "-b".to_string(), |
| 186 | "beans".to_string(), |
| 187 | ]); |
| 188 | |
| 189 | assert!(j.contains("-a")); |
| 190 | |
| 191 | assert_eq!( |
| 192 | j, |
| 193 | Jargon(vec![ |
| 194 | "jargon".to_string(), |
| 195 | "-b".to_string(), |
| 196 | "beans".to_string(), |
| 197 | ]) |
| 198 | ) |
| 199 | } |
| 200 | |
| 201 | #[test] |
| 202 | fn jargon_contains_short_f_rmv() { |
| 203 | let mut j = Jargon::from_vec(vec![ |
| 204 | "jargon".to_string(), |
| 205 | "-b".to_string(), |
| 206 | "beans".to_string(), |
| 207 | ]); |
| 208 | |
| 209 | assert!(!j.contains("-a")); |
| 210 | |
| 211 | assert_eq!( |
| 212 | j, |
| 213 | Jargon(vec![ |
| 214 | "jargon".to_string(), |
| 215 | "-b".to_string(), |
| 216 | "beans".to_string(), |
| 217 | ]) |
| 218 | ) |
| 219 | } |
| 220 | |
| 221 | #[test] |
| 222 | #[cfg(feature = "no_mut")] |
| 223 | fn jargon_contains_long_t() { |
| 224 | let j = Jargon::from_vec(vec![ |
| 225 | "jargon".to_string(), |
| 226 | "--all".to_string(), |
| 227 | "-b".to_string(), |
| 228 | "beans".to_string(), |
| 229 | ]); |
| 230 | |
| 231 | assert!(j.contains_nomut("--all")); |
| 232 | |
| 233 | assert_eq!( |
| 234 | j, |
| 235 | Jargon(vec![ |
| 236 | "jargon".to_string(), |
| 237 | "--all".to_string(), |
| 238 | "-b".to_string(), |
| 239 | "beans".to_string(), |
| 240 | ]) |
| 241 | ) |
| 242 | } |
| 243 | |
| 244 | #[test] |
| 245 | #[cfg(feature = "no_mut")] |
| 246 | fn jargon_contains_long_f() { |
| 247 | let j = Jargon::from_vec(vec![ |
| 248 | "jargon".to_string(), |
| 249 | "-b".to_string(), |
| 250 | "beans".to_string(), |
| 251 | ]); |
| 252 | |
| 253 | assert!(!j.contains_nomut("--all")); |
| 254 | |
| 255 | assert_eq!( |
| 256 | j, |
| 257 | Jargon(vec![ |
| 258 | "jargon".to_string(), |
| 259 | "-b".to_string(), |
| 260 | "beans".to_string(), |
| 261 | ]) |
| 262 | ) |
| 263 | } |
| 264 | |
| 265 | #[test] |
| 266 | fn jargon_contains_long_t_rmv() { |
| 267 | let mut j = Jargon::from_vec(vec![ |
| 268 | "jargon".to_string(), |
| 269 | "--all".to_string(), |
| 270 | "-b".to_string(), |
| 271 | "beans".to_string(), |
| 272 | ]); |
| 273 | |
| 274 | assert!(j.contains("--all")); |
| 275 | |
| 276 | assert_eq!( |
| 277 | j, |
| 278 | Jargon(vec![ |
| 279 | "jargon".to_string(), |
| 280 | "-b".to_string(), |
| 281 | "beans".to_string(), |
| 282 | ]) |
| 283 | ) |
| 284 | } |
| 285 | |
| 286 | #[test] |
| 287 | fn jargon_contains_long_f_rmv() { |
| 288 | let mut j = Jargon::from_vec(vec![ |
| 289 | "jargon".to_string(), |
| 290 | "-b".to_string(), |
| 291 | "beans".to_string(), |
| 292 | ]); |
| 293 | |
| 294 | assert!(!j.contains("--all")); |
| 295 | |
| 296 | assert_eq!( |
| 297 | j, |
| 298 | Jargon(vec![ |
| 299 | "jargon".to_string(), |
| 300 | "-b".to_string(), |
| 301 | "beans".to_string(), |
| 302 | ]) |
| 303 | ) |
| 304 | } |
| 305 | |
| 306 | #[test] |
| 307 | #[cfg(feature = "no_mut")] |
| 308 | fn jargon_contains_dual_s_t() { |
| 309 | let j = Jargon::from_vec(vec![ |
| 310 | "jargon".to_string(), |
| 311 | "-a".to_string(), |
| 312 | "-b".to_string(), |
| 313 | "beans".to_string(), |
| 314 | ]); |
| 315 | |
| 316 | assert!(j.contains_nomut(["-a", "--all"])); |
| 317 | |
| 318 | assert_eq!( |
| 319 | j, |
| 320 | Jargon(vec![ |
| 321 | "jargon".to_string(), |
| 322 | "-a".to_string(), |
| 323 | "-b".to_string(), |
| 324 | "beans".to_string(), |
| 325 | ]) |
| 326 | ) |
| 327 | } |
| 328 | |
| 329 | #[test] |
| 330 | #[cfg(feature = "no_mut")] |
| 331 | fn jargon_contains_dual_s_f() { |
| 332 | let j = Jargon::from_vec(vec![ |
| 333 | "jargon".to_string(), |
| 334 | "-b".to_string(), |
| 335 | "beans".to_string(), |
| 336 | ]); |
| 337 | |
| 338 | assert!(!j.contains_nomut(["-a", "--all"])); |
| 339 | |
| 340 | assert_eq!( |
| 341 | j, |
| 342 | Jargon(vec![ |
| 343 | "jargon".to_string(), |
| 344 | "-b".to_string(), |
| 345 | "beans".to_string(), |
| 346 | ]) |
| 347 | ) |
| 348 | } |
| 349 | |
| 350 | #[test] |
| 351 | fn jargon_contains_dual_s_t_rmv() { |
| 352 | let mut j = Jargon::from_vec(vec![ |
| 353 | "jargon".to_string(), |
| 354 | "-a".to_string(), |
| 355 | "-b".to_string(), |
| 356 | "beans".to_string(), |
| 357 | ]); |
| 358 | |
| 359 | assert!(j.contains(["-a", "--all"])); |
| 360 | |
| 361 | assert_eq!( |
| 362 | j, |
| 363 | Jargon(vec![ |
| 364 | "jargon".to_string(), |
| 365 | "-b".to_string(), |
| 366 | "beans".to_string(), |
| 367 | ]) |
| 368 | ) |
| 369 | } |
| 370 | |
| 371 | #[test] |
| 372 | fn jargon_contains_dual_l_f_rmv() { |
| 373 | let mut j = Jargon::from_vec(vec![ |
| 374 | "jargon".to_string(), |
| 375 | "-b".to_string(), |
| 376 | "beans".to_string(), |
| 377 | ]); |
| 378 | |
| 379 | assert!(!j.contains(["-a", "--all"])); |
| 380 | |
| 381 | assert_eq!( |
| 382 | j, |
| 383 | Jargon(vec![ |
| 384 | "jargon".to_string(), |
| 385 | "-b".to_string(), |
| 386 | "beans".to_string(), |
| 387 | ]) |
| 388 | ) |
| 389 | } |
| 390 | |
| 391 | #[test] |
| 392 | #[cfg(feature = "no_mut")] |
| 393 | fn jargon_contains_dual_l_t() { |
| 394 | let j = Jargon::from_vec(vec![ |
| 395 | "jargon".to_string(), |
| 396 | "--all".to_string(), |
| 397 | "-b".to_string(), |
| 398 | "beans".to_string(), |
| 399 | ]); |
| 400 | |
| 401 | assert!(j.contains_nomut(["-a", "--all"])); |
| 402 | |
| 403 | assert_eq!( |
| 404 | j, |
| 405 | Jargon(vec![ |
| 406 | "jargon".to_string(), |
| 407 | "--all".to_string(), |
| 408 | "-b".to_string(), |
| 409 | "beans".to_string(), |
| 410 | ]) |
| 411 | ) |
| 412 | } |
| 413 | |
| 414 | #[test] |
| 415 | #[cfg(feature = "no_mut")] |
| 416 | fn jargon_contains_dual_l_f() { |
| 417 | let j = Jargon::from_vec(vec![ |
| 418 | "jargon".to_string(), |
| 419 | "-b".to_string(), |
| 420 | "beans".to_string(), |
| 421 | ]); |
| 422 | |
| 423 | assert!(!j.contains_nomut(["-a", "--all"])); |
| 424 | |
| 425 | assert_eq!( |
| 426 | j, |
| 427 | Jargon(vec![ |
| 428 | "jargon".to_string(), |
| 429 | "-b".to_string(), |
| 430 | "beans".to_string(), |
| 431 | ]) |
| 432 | ) |
| 433 | } |
| 434 | |
| 435 | #[test] |
| 436 | fn jargon_contains_dual_l_t_rmv() { |
| 437 | let mut j = Jargon::from_vec(vec![ |
| 438 | "jargon".to_string(), |
| 439 | "--all".to_string(), |
| 440 | "-b".to_string(), |
| 441 | "beans".to_string(), |
| 442 | ]); |
| 443 | |
| 444 | assert!(j.contains(["-a", "--all"])); |
| 445 | |
| 446 | assert_eq!( |
| 447 | j, |
| 448 | Jargon(vec![ |
| 449 | "jargon".to_string(), |
| 450 | "-b".to_string(), |
| 451 | "beans".to_string(), |
| 452 | ]) |
| 453 | ) |
| 454 | } |
| 455 | |
| 456 | #[test] |
| 457 | fn jargon_arg_option_short_t() { |
| 458 | let mut j = Jargon::from_vec(vec![ |
| 459 | "jargon_arg_option_short_t".to_string(), |
| 460 | "-a".to_string(), |
| 461 | "hello".to_string(), |
| 462 | "world".to_string(), |
| 463 | ]); |
| 464 | |
| 465 | assert_eq!(j.option_arg("-a"), Some("hello".to_string()),) |
| 466 | } |
| 467 | |
| 468 | #[test] |
| 469 | fn jargon_arg_option_short_fa() { |
| 470 | let mut j = Jargon::from_vec(vec![ |
| 471 | "jargon_arg_option_short_t".to_string(), |
| 472 | "-a".to_string(), |
| 473 | "--hello".to_string(), |
| 474 | "world".to_string(), |
| 475 | ]); |
| 476 | |
| 477 | assert_eq!(j.option_arg::<String, &str>("-a"), None,) |
| 478 | } |
| 479 | |
| 480 | #[test] |
| 481 | fn jargon_arg_option_short_fm() { |
| 482 | let mut j = Jargon::from_vec(vec![ |
| 483 | "jargon_arg_option_short_t".to_string(), |
| 484 | "-a".to_string(), |
| 485 | ]); |
| 486 | |
| 487 | assert_eq!(j.option_arg::<String, &str>("-a"), None,) |
| 488 | } |
| 489 | |
| 490 | #[test] |
| 491 | fn jargon_arg_option_short_f() { |
| 492 | let mut j = Jargon::from_vec(vec![ |
| 493 | "jargon_arg_option_short_t".to_string(), |
| 494 | "hello".to_string(), |
| 495 | "world".to_string(), |
| 496 | ]); |
| 497 | |
| 498 | assert_eq!(j.option_arg::<String, &str>("-a"), None,) |
| 499 | } |
| 500 | |
| 501 | #[test] |
| 502 | fn jargon_arg_option_long_t() { |
| 503 | let mut j = Jargon::from_vec(vec![ |
| 504 | "jargon_arg_option_short_t".to_string(), |
| 505 | "--all".to_string(), |
| 506 | "hello".to_string(), |
| 507 | "world".to_string(), |
| 508 | ]); |
| 509 | |
| 510 | assert_eq!(j.option_arg("--all"), Some("hello".to_string()),) |
| 511 | } |
| 512 | |
| 513 | #[test] |
| 514 | fn jargon_arg_option_long_fa() { |
| 515 | let mut j = Jargon::from_vec(vec![ |
| 516 | "jargon_arg_option_short_t".to_string(), |
| 517 | "--all".to_string(), |
| 518 | "--hello".to_string(), |
| 519 | "world".to_string(), |
| 520 | ]); |
| 521 | |
| 522 | assert_eq!(j.option_arg::<String, &str>("--all"), None,) |
| 523 | } |
| 524 | |
| 525 | #[test] |
| 526 | fn jargon_arg_option_long_fm() { |
| 527 | let mut j = Jargon::from_vec(vec![ |
| 528 | "jargon_arg_option_short_t".to_string(), |
| 529 | "--all".to_string(), |
| 530 | ]); |
| 531 | |
| 532 | assert_eq!(j.option_arg::<String, &str>("--all"), None,) |
| 533 | } |
| 534 | |
| 535 | #[test] |
| 536 | fn jargon_arg_option_long_f() { |
| 537 | let mut j = Jargon::from_vec(vec![ |
| 538 | "jargon_arg_option_short_t".to_string(), |
| 539 | "hello".to_string(), |
| 540 | "world".to_string(), |
| 541 | ]); |
| 542 | |
| 543 | assert_eq!(j.option_arg::<String, &str>("--all"), None,) |
| 544 | } |
| 545 | |
| 546 | #[test] |
| 547 | fn jargon_arg_option_dual_s_t() { |
| 548 | let mut j = Jargon::from_vec(vec![ |
| 549 | "jargon_arg_option_short_t".to_string(), |
| 550 | "-a".to_string(), |
| 551 | "hello".to_string(), |
| 552 | "world".to_string(), |
| 553 | ]); |
| 554 | |
| 555 | assert_eq!(j.option_arg(["-a", "--all"]), Some("hello".to_string()),) |
| 556 | } |
| 557 | |
| 558 | #[test] |
| 559 | fn jargon_arg_option_dual_s_fa() { |
| 560 | let mut j = Jargon::from_vec(vec![ |
| 561 | "jargon_arg_option_short_t".to_string(), |
| 562 | "-a".to_string(), |
| 563 | "--hello".to_string(), |
| 564 | "world".to_string(), |
| 565 | ]); |
| 566 | |
| 567 | assert_eq!(j.option_arg::<String, [&str; 2]>(["-a", "--all"]), None,) |
| 568 | } |
| 569 | |
| 570 | #[test] |
| 571 | fn jargon_arg_option_dual_s_fm() { |
| 572 | let mut j = Jargon::from_vec(vec![ |
| 573 | "jargon_arg_option_short_t".to_string(), |
| 574 | "-a".to_string(), |
| 575 | ]); |
| 576 | |
| 577 | assert_eq!(j.option_arg::<String, [&str; 2]>(["-a", "--all"]), None,) |
| 578 | } |
| 579 | |
| 580 | #[test] |
| 581 | fn jargon_arg_option_dual_s_f() { |
| 582 | let mut j = Jargon::from_vec(vec![ |
| 583 | "jargon_arg_option_short_t".to_string(), |
| 584 | "hello".to_string(), |
| 585 | "world".to_string(), |
| 586 | ]); |
| 587 | |
| 588 | assert_eq!(j.option_arg::<String, [&str; 2]>(["-a", "--all"]), None,) |
| 589 | } |
| 590 | |
| 591 | #[test] |
| 592 | fn jargon_arg_option_dual_l_t() { |
| 593 | let mut j = Jargon::from_vec(vec![ |
| 594 | "jargon_arg_option_short_t".to_string(), |
| 595 | "--all".to_string(), |
| 596 | "hello".to_string(), |
| 597 | "world".to_string(), |
| 598 | ]); |
| 599 | |
| 600 | assert_eq!(j.option_arg::<String, [&str; 2]>(["-a", "--all"]), Some("hello".to_string()),) |
| 601 | } |
| 602 | |
| 603 | #[test] |
| 604 | fn jargon_arg_option_dual_l_fa() { |
| 605 | let mut j = Jargon::from_vec(vec![ |
| 606 | "jargon_arg_option_short_t".to_string(), |
| 607 | "--all".to_string(), |
| 608 | "--hello".to_string(), |
| 609 | "world".to_string(), |
| 610 | ]); |
| 611 | |
| 612 | assert_eq!(j.option_arg::<String, [&str; 2]>(["-a", "--all"]), None,) |
| 613 | } |
| 614 | |
| 615 | #[test] |
| 616 | fn jargon_arg_option_dual_l_fm() { |
| 617 | let mut j = Jargon::from_vec(vec![ |
| 618 | "jargon_arg_option_short_t".to_string(), |
| 619 | "--all".to_string(), |
| 620 | ]); |
| 621 | |
| 622 | assert_eq!(j.option_arg::<String, [&str; 2]>(["-a", "--all"]), None,) |
| 623 | } |
| 624 | |
| 625 | #[test] |
| 626 | fn jargon_arg_option_dual_l_f() { |
| 627 | let mut j = Jargon::from_vec(vec![ |
| 628 | "jargon_arg_option_short_t".to_string(), |
| 629 | "hello".to_string(), |
| 630 | "world".to_string(), |
| 631 | ]); |
| 632 | |
| 633 | assert_eq!(j.option_arg::<String, [&str; 2]>(["-a", "--all"]), None,) |
| 634 | } |
| 635 | |
| 636 | #[test] |
| 637 | fn key_short_is_short() { |
| 638 | let k: Key = "-a".into(); |
| 639 | assert!(k.is_short()) |
| 640 | } |
| 641 | |
| 642 | #[test] |
| 643 | fn key_short_is_long() { |
| 644 | let k: Key = "-a".into(); |
| 645 | assert!(!k.is_long()) |
| 646 | } |
| 647 | |
| 648 | #[test] |
| 649 | fn key_short_is_dual() { |
| 650 | let k: Key = "-a".into(); |
| 651 | assert!(!k.is_dual()) |
| 652 | } |
| 653 | |
| 654 | #[test] |
| 655 | fn key_short_is_sub() { |
| 656 | let k: Key = "-a".into(); |
| 657 | assert!(!k.is_sub()) |
| 658 | } |
| 659 | |
| 660 | #[test] |
| 661 | fn key_long_is_short() { |
| 662 | let k: Key = "--all".into(); |
| 663 | assert!(!k.is_short()) |
| 664 | } |
| 665 | |
| 666 | #[test] |
| 667 | fn key_long_is_long() { |
| 668 | let k: Key = "--all".into(); |
| 669 | assert!(k.is_long()) |
| 670 | } |
| 671 | |
| 672 | #[test] |
| 673 | fn key_long_is_dual() { |
| 674 | let k: Key = "--all".into(); |
| 675 | assert!(!k.is_dual()) |
| 676 | } |
| 677 | |
| 678 | #[test] |
| 679 | fn key_long_is_sub() { |
| 680 | let k: Key = "--all".into(); |
| 681 | assert!(!k.is_sub()) |
| 682 | } |
| 683 | |
| 684 | #[test] |
| 685 | fn key_dual_is_short() { |
| 686 | let k: Key = ["-a", "--all"].into(); |
| 687 | assert!(!k.is_short()) |
| 688 | } |
| 689 | |
| 690 | #[test] |
| 691 | fn key_dual_is_long() { |
| 692 | let k: Key = ["-a", "--all"].into(); |
| 693 | assert!(!k.is_long()) |
| 694 | } |
| 695 | |
| 696 | #[test] |
| 697 | fn key_dual_is_dual() { |
| 698 | let k: Key = ["-a", "--all"].into(); |
| 699 | assert!(k.is_dual()) |
| 700 | } |
| 701 | |
| 702 | #[test] |
| 703 | fn key_dual_is_sub() { |
| 704 | let k: Key = ["-a", "--all"].into(); |
| 705 | assert!(!k.is_sub()) |
| 706 | } |
| 707 | |
| 708 | #[test] |
| 709 | fn key_sub_is_short() { |
| 710 | let k: Key = "subcmd".into(); |
| 711 | assert!(!k.is_short()) |
| 712 | } |
| 713 | |
| 714 | #[test] |
| 715 | fn key_sub_is_long() { |
| 716 | let k: Key = "subcmd".into(); |
| 717 | assert!(!k.is_long()) |
| 718 | } |
| 719 | |
| 720 | #[test] |
| 721 | fn key_sub_is_dual() { |
| 722 | let k: Key = "subcmd".into(); |
| 723 | assert!(!k.is_dual()) |
| 724 | } |
| 725 | |
| 726 | #[test] |
| 727 | fn key_sub_is_sub() { |
| 728 | let k: Key = "subcmd".into(); |
| 729 | assert!(k.is_sub()) |
| 730 | } |
| 731 | |
| 732 | #[test] |
| 733 | fn key_short_char() { |
| 734 | let k: Key = "-a".into(); |
| 735 | assert_eq!(k.char(), '-',) |
| 736 | } |
| 737 | |
| 738 | #[test] |
| 739 | fn key_long_char() { |
| 740 | let k: Key = "--all".into(); |
| 741 | assert_eq!(k.char(), '-') |
| 742 | } |
| 743 | |
| 744 | #[test] |
| 745 | fn key_dual_char() { |
| 746 | let k: Key = ["-a", "--all"].into(); |
| 747 | assert_eq!(k.char(), '-') |
| 748 | } |
| 749 | |
| 750 | #[test] |
| 751 | fn key_sub_char() { |
| 752 | let k: Key = "beans".into(); |
| 753 | assert_eq!(k.char(), '\0',) |
| 754 | } |
| 755 | |
| 756 | #[test] |
| 757 | fn key_short_text() { |
| 758 | let k: Key = "-a".into(); |
| 759 | assert_eq!(k.text(), "a".to_string(),) |
| 760 | } |
| 761 | |
| 762 | #[test] |
| 763 | fn key_long_text() { |
| 764 | let k: Key = "--all".into(); |
| 765 | assert_eq!(k.text(), "all".to_string(),) |
| 766 | } |
| 767 | |
| 768 | #[test] |
| 769 | fn key_dual_text() { |
| 770 | let k: Key = ["-a", "--all"].into(); |
| 771 | assert_eq!(k.text(), "all",) |
| 772 | } |
| 773 | |
| 774 | #[test] |
| 775 | fn key_sub_text() { |
| 776 | let k: Key = "beans".into(); |
| 777 | assert_eq!(k.text(), "beans",) |
| 778 | } |
| 779 | |
| 780 | #[test] |
| 781 | fn from_env() { |
| 782 | let j = Jargon::from_env(); |
| 783 | assert!(!j.0.is_empty()); |
| 784 | } |
| 785 | |
| 786 | #[test] |
| 787 | fn on_sub_v_e() { |
| 788 | let mut j = Jargon::from_vec(vec!["on_sub".to_string(), "subsub".to_string()]); |
| 789 | |
| 790 | fn subsub(v: Vec<String>) { |
| 791 | assert_eq!(v, vec!["subsub".to_string(),]) |
| 792 | } |
| 793 | |
| 794 | j.on_subcommand("subsub", subsub); |
| 795 | } |
| 796 | |
| 797 | #[test] |
| 798 | fn on_sub_v_w() { |
| 799 | let mut j = Jargon::from_vec(vec![ |
| 800 | "on_sub".to_string(), |
| 801 | "subsub".to_string(), |
| 802 | "test".to_string(), |
| 803 | ]); |
| 804 | |
| 805 | fn subsub(v: Vec<String>) { |
| 806 | assert_eq!(v, vec!["subsub".to_string(), "test".to_string(),]) |
| 807 | } |
| 808 | |
| 809 | j.on_subcommand("subsub", subsub); |
| 810 | } |
| 811 | |
| 812 | #[test] |
| 813 | fn on_sub_none() { |
| 814 | let mut j = Jargon::from_vec(vec!["on_sub".to_string(), "test".to_string()]); |
| 815 | |
| 816 | fn subsub(_: Vec<String>) { |
| 817 | panic!() |
| 818 | } |
| 819 | |
| 820 | j.on_subcommand("subsub", subsub); |
| 821 | } |
| 822 | |
| 823 | #[test] |
| 824 | fn on_sub_opt_e() { |
| 825 | let mut j = Jargon::from_vec(vec!["on_sub".to_string(), "subsub".to_string()]); |
| 826 | |
| 827 | fn subsub(_: Vec<String>) -> Option<u8> { |
| 828 | Some(1u8) |
| 829 | } |
| 830 | |
| 831 | assert_eq!(j.opt_on_subcommand("subsub", subsub), Some(1u8),) |
| 832 | } |
| 833 | |
| 834 | #[test] |
| 835 | fn on_sub_opt_w() { |
| 836 | let mut j = Jargon::from_vec(vec![ |
| 837 | "on_sub".to_string(), |
| 838 | "subsub".to_string(), |
| 839 | "test".to_string(), |
| 840 | ]); |
| 841 | |
| 842 | fn subsub(v: Vec<String>) -> Option<u8> { |
| 843 | assert_eq!(v, vec!["subsub".to_string(), "test".to_string(),]); |
| 844 | |
| 845 | Some(1u8) |
| 846 | } |
| 847 | |
| 848 | assert_eq!(j.opt_on_subcommand("subsub", subsub), Some(1u8),) |
| 849 | } |
| 850 | |
| 851 | #[test] |
| 852 | fn on_sub_opt_none() { |
| 853 | let mut j = Jargon::from_vec(vec!["on_sub".to_string(), "test".to_string()]); |
| 854 | |
| 855 | fn subsub(_: Vec<String>) -> Option<u8> { |
| 856 | panic!() |
| 857 | } |
| 858 | |
| 859 | assert_eq!(j.opt_on_subcommand("subsub", subsub), None,) |
| 860 | } |
| 861 | |
| 862 | #[test] |
| 863 | fn on_sub_res_e() { |
| 864 | let mut j = Jargon::from_vec(vec!["on_sub".to_string(), "subsub".to_string()]); |
| 865 | |
| 866 | fn subsub(_: Vec<String>) -> Result<(), Error> { |
| 867 | Ok(()) |
| 868 | } |
| 869 | |
| 870 | assert_eq!(j.res_on_subcommand("subsub", subsub), Ok(())) |
| 871 | } |
| 872 | |
| 873 | #[test] |
| 874 | fn on_sub_res_none() { |
| 875 | let mut j = Jargon::from_vec(vec!["on_sub".to_string(), "test".to_string()]); |
| 876 | |
| 877 | fn subsub(_: Vec<String>) -> Result<(), Error> { |
| 878 | panic!() |
| 879 | } |
| 880 | |
| 881 | assert_eq!( |
| 882 | j.res_on_subcommand("subsub", subsub), |
| 883 | Err(Error::MissingArg("subsub".into())), |
| 884 | ) |
| 885 | } |
| 886 | |
| 887 | #[test] |
| 888 | fn on_sub_res_w() { |
| 889 | let mut j = Jargon::from_vec(vec![ |
| 890 | "on_sub".to_string(), |
| 891 | "subsub".to_string(), |
| 892 | "test".to_string(), |
| 893 | ]); |
| 894 | |
| 895 | fn subsub(_: Vec<String>) -> Result<(), Error> { |
| 896 | Ok(()) |
| 897 | } |
| 898 | |
| 899 | assert_eq!(j.res_on_subcommand("subsub", subsub), Ok(())) |
| 900 | } |
| 901 | |
| 902 | #[test] |
| 903 | fn sub_mut_s_e() { |
| 904 | let mut j: Jargon = Jargon::from_vec(vec!["sub_mut_s".to_string(), "subsub".to_string()]); |
| 905 | |
| 906 | if let Some(v) = j.subcommand("subsub") { |
| 907 | assert_eq!(v, vec!["subsub".to_string(),]) |
| 908 | } |
| 909 | } |
| 910 | |
| 911 | #[test] |
| 912 | fn sub_mut_s_w() { |
| 913 | let mut j: Jargon = Jargon::from_vec(vec![ |
| 914 | "sub_mut_s".to_string(), |
| 915 | "subsub".to_string(), |
| 916 | "test".to_string(), |
| 917 | ]); |
| 918 | |
| 919 | if let Some(v) = j.subcommand("subsub") { |
| 920 | assert_eq!(v, vec!["subsub".to_string(), "test".to_string(),]) |
| 921 | } |
| 922 | } |
| 923 | |
| 924 | #[test] |
| 925 | fn sub_mut_none() { |
| 926 | let mut j: Jargon = Jargon::from_vec(vec!["sub_mut_none".to_string(), "test".to_string()]); |
| 927 | |
| 928 | assert_eq!(j.subcommand("subsub"), None,) |
| 929 | } |
| 930 | |
| 931 | #[test] |
| 932 | #[cfg(feature = "no_mut")] |
| 933 | fn sub_s_e() { |
| 934 | let j: Jargon = Jargon::from_vec(vec!["sub_mut_s".to_string(), "subsub".to_string()]); |
| 935 | |
| 936 | if let Some(v) = j.subcommand_nomut("subsub") { |
| 937 | assert_eq!(v, vec!["subsub".to_string(),]) |
| 938 | } |
| 939 | } |
| 940 | |
| 941 | #[test] |
| 942 | fn sub_s_w() { |
| 943 | let mut j: Jargon = Jargon::from_vec(vec![ |
| 944 | "sub_mut_s".to_string(), |
| 945 | "subsub".to_string(), |
| 946 | "test".to_string(), |
| 947 | ]); |
| 948 | |
| 949 | if let Some(v) = j.subcommand("subsub") { |
| 950 | assert_eq!(v, vec!["subsub".to_string(), "test".to_string(),]) |
| 951 | } |
| 952 | } |
| 953 | |
| 954 | #[test] |
| 955 | fn sub_none() { |
| 956 | let mut j: Jargon = Jargon::from_vec(vec!["sub_mut_none".to_string(), "test".to_string()]); |
| 957 | |
| 958 | assert_eq!(j.subcommand("subsub"), None,) |
| 959 | } |
| 960 | |
| 961 | #[test] |
| 962 | fn fmt_error_missing() { |
| 963 | assert_eq!( |
| 964 | Error::MissingArg("--all".into()).to_string(), |
| 965 | "Missing argument: '--all'".to_string(), |
| 966 | ) |
| 967 | } |
| 968 | |
| 969 | #[test] |
| 970 | fn fmt_error_other() { |
| 971 | let e = Error::Other(std::io::Error::new(std::io::ErrorKind::AddrInUse, "test").to_string()); |
| 972 | assert_eq!(e.to_string(), "test".to_string(),) |
| 973 | } |