@@ -626,6 +626,7 @@ fn test_multi() {
626
626
opts. optopt ( "e" , "" , "encrypt" , "ENCRYPT" ) ;
627
627
opts. optopt ( "" , "encrypt" , "encrypt" , "ENCRYPT" ) ;
628
628
opts. optopt ( "f" , "" , "flag" , "FLAG" ) ;
629
+ let no_opts: & [ & str ] = & [ ] ;
629
630
630
631
let args_single = vec ! [ "-e" . to_string( ) , "foo" . to_string( ) ] ;
631
632
let matches_single = & match opts. parse ( & args_single) {
@@ -639,6 +640,12 @@ fn test_multi() {
639
640
assert ! ( !matches_single. opts_present( & [ "thing" . to_string( ) ] ) ) ;
640
641
assert ! ( !matches_single. opts_present( & [ ] ) ) ;
641
642
643
+ assert ! ( matches_single. opts_present_any( & [ "e" ] ) ) ;
644
+ assert ! ( matches_single. opts_present_any( & [ "encrypt" , "e" ] ) ) ;
645
+ assert ! ( matches_single. opts_present_any( & [ "e" , "encrypt" ] ) ) ;
646
+ assert ! ( !matches_single. opts_present_any( & [ "encrypt" ] ) ) ;
647
+ assert ! ( !matches_single. opts_present_any( no_opts) ) ;
648
+
642
649
assert_eq ! ( matches_single. opts_str( & [ "e" . to_string( ) ] ) . unwrap( ) , "foo" ) ;
643
650
assert_eq ! (
644
651
matches_single
@@ -653,11 +660,23 @@ fn test_multi() {
653
660
"foo"
654
661
) ;
655
662
663
+ assert_eq ! ( matches_single. opts_str_first( & [ "e" ] ) . unwrap( ) , "foo" ) ;
664
+ assert_eq ! (
665
+ matches_single. opts_str_first( & [ "e" , "encrypt" ] ) . unwrap( ) ,
666
+ "foo"
667
+ ) ;
668
+ assert_eq ! (
669
+ matches_single. opts_str_first( & [ "encrypt" , "e" ] ) . unwrap( ) ,
670
+ "foo"
671
+ ) ;
672
+ assert_eq ! ( matches_single. opts_str_first( & [ "encrypt" ] ) , None ) ;
673
+ assert_eq ! ( matches_single. opts_str_first( no_opts) , None ) ;
674
+
656
675
let args_both = vec ! [
657
676
"-e" . to_string( ) ,
658
677
"foo" . to_string( ) ,
659
678
"--encrypt" . to_string( ) ,
660
- "foo " . to_string( ) ,
679
+ "bar " . to_string( ) ,
661
680
] ;
662
681
let matches_both = & match opts. parse ( & args_both) {
663
682
Ok ( m) => m,
@@ -671,10 +690,17 @@ fn test_multi() {
671
690
assert ! ( !matches_both. opts_present( & [ "thing" . to_string( ) ] ) ) ;
672
691
assert ! ( !matches_both. opts_present( & [ ] ) ) ;
673
692
693
+ assert ! ( matches_both. opts_present_any( & [ "e" ] ) ) ;
694
+ assert ! ( matches_both. opts_present_any( & [ "encrypt" ] ) ) ;
695
+ assert ! ( matches_both. opts_present_any( & [ "encrypt" , "e" ] ) ) ;
696
+ assert ! ( matches_both. opts_present_any( & [ "e" , "encrypt" ] ) ) ;
697
+ assert ! ( !matches_both. opts_present_any( & [ "f" ] ) ) ;
698
+ assert ! ( !matches_both. opts_present_any( no_opts) ) ;
699
+
674
700
assert_eq ! ( matches_both. opts_str( & [ "e" . to_string( ) ] ) . unwrap( ) , "foo" ) ;
675
701
assert_eq ! (
676
702
matches_both. opts_str( & [ "encrypt" . to_string( ) ] ) . unwrap( ) ,
677
- "foo "
703
+ "bar "
678
704
) ;
679
705
assert_eq ! (
680
706
matches_both
@@ -686,8 +712,24 @@ fn test_multi() {
686
712
matches_both
687
713
. opts_str( & [ "encrypt" . to_string( ) , "e" . to_string( ) ] )
688
714
. unwrap( ) ,
715
+ "bar"
716
+ ) ;
717
+
718
+ assert_eq ! ( matches_both. opts_str_first( & [ "e" ] ) . unwrap( ) , "foo" ) ;
719
+ assert_eq ! (
720
+ matches_both. opts_str_first( & [ "encrypt" ] ) . unwrap( ) ,
721
+ "bar"
722
+ ) ;
723
+ assert_eq ! (
724
+ matches_both. opts_str_first( & [ "e" , "encrypt" ] ) . unwrap( ) ,
689
725
"foo"
690
726
) ;
727
+ assert_eq ! (
728
+ matches_both. opts_str_first( & [ "encrypt" , "e" ] ) . unwrap( ) ,
729
+ "bar"
730
+ ) ;
731
+ assert_eq ! ( matches_both. opts_str_first( & [ "f" ] ) , None ) ;
732
+ assert_eq ! ( matches_both. opts_str_first( no_opts) , None ) ;
691
733
}
692
734
693
735
#[ test]
0 commit comments