@@ -626,6 +626,7 @@ fn test_multi() {
626626 opts. optopt ( "e" , "" , "encrypt" , "ENCRYPT" ) ;
627627 opts. optopt ( "" , "encrypt" , "encrypt" , "ENCRYPT" ) ;
628628 opts. optopt ( "f" , "" , "flag" , "FLAG" ) ;
629+ let no_opts: & [ & str ] = & [ ] ;
629630
630631 let args_single = vec ! [ "-e" . to_string( ) , "foo" . to_string( ) ] ;
631632 let matches_single = & match opts. parse ( & args_single) {
@@ -639,6 +640,12 @@ fn test_multi() {
639640 assert ! ( !matches_single. opts_present( & [ "thing" . to_string( ) ] ) ) ;
640641 assert ! ( !matches_single. opts_present( & [ ] ) ) ;
641642
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+
642649 assert_eq ! ( matches_single. opts_str( & [ "e" . to_string( ) ] ) . unwrap( ) , "foo" ) ;
643650 assert_eq ! (
644651 matches_single
@@ -653,11 +660,23 @@ fn test_multi() {
653660 "foo"
654661 ) ;
655662
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+
656675 let args_both = vec ! [
657676 "-e" . to_string( ) ,
658677 "foo" . to_string( ) ,
659678 "--encrypt" . to_string( ) ,
660- "foo " . to_string( ) ,
679+ "bar " . to_string( ) ,
661680 ] ;
662681 let matches_both = & match opts. parse ( & args_both) {
663682 Ok ( m) => m,
@@ -671,10 +690,17 @@ fn test_multi() {
671690 assert ! ( !matches_both. opts_present( & [ "thing" . to_string( ) ] ) ) ;
672691 assert ! ( !matches_both. opts_present( & [ ] ) ) ;
673692
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+
674700 assert_eq ! ( matches_both. opts_str( & [ "e" . to_string( ) ] ) . unwrap( ) , "foo" ) ;
675701 assert_eq ! (
676702 matches_both. opts_str( & [ "encrypt" . to_string( ) ] ) . unwrap( ) ,
677- "foo "
703+ "bar "
678704 ) ;
679705 assert_eq ! (
680706 matches_both
@@ -686,8 +712,24 @@ fn test_multi() {
686712 matches_both
687713 . opts_str( & [ "encrypt" . to_string( ) , "e" . to_string( ) ] )
688714 . 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( ) ,
689725 "foo"
690726 ) ;
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 ) ;
691733}
692734
693735#[ test]
0 commit comments