@@ -656,6 +656,46 @@ func TestFlagSetParse(t *testing.T) {
656
656
testParse (NewFlagSet ("test" , ContinueOnError ), t )
657
657
}
658
658
659
+ func TestParseRepeated (t * testing.T ) {
660
+ fs := NewFlagSet ("test repeated" , ContinueOnError )
661
+
662
+ t .Run ("first parse" , func (t * testing.T ) {
663
+ err := fs .Parse ([]string {"foo" , "bar" })
664
+ if err != nil {
665
+ t .Fatal ("expected no error, got " , err )
666
+ }
667
+
668
+ argsAfterFirst := fs .Args ()
669
+ if ! reflect .DeepEqual (argsAfterFirst , []string {"foo" , "bar" }) {
670
+ t .Fatalf ("expected args [foo bar], got %v" , argsAfterFirst )
671
+ }
672
+ })
673
+
674
+ t .Run ("re-parse with fewer args" , func (t * testing.T ) {
675
+ err := fs .Parse ([]string {"baz" })
676
+ if err != nil {
677
+ t .Fatal ("expected no error, got " , err )
678
+ }
679
+
680
+ argsAfterSecond := fs .Args ()
681
+ if ! reflect .DeepEqual (argsAfterSecond , []string {"baz" }) {
682
+ t .Fatalf ("expected args [baz], got %v" , argsAfterSecond )
683
+ }
684
+ })
685
+
686
+ t .Run ("re-parse with no args" , func (t * testing.T ) {
687
+ err := fs .Parse ([]string {})
688
+ if err != nil {
689
+ t .Fatal ("expected no error, got " , err )
690
+ }
691
+
692
+ argsAfterThird := fs .Args ()
693
+ if ! reflect .DeepEqual (argsAfterThird , []string {}) {
694
+ t .Fatalf ("expected args [], got %v" , argsAfterThird )
695
+ }
696
+ })
697
+ }
698
+
659
699
func TestChangedHelper (t * testing.T ) {
660
700
f := NewFlagSet ("changedtest" , ContinueOnError )
661
701
f .Bool ("changed" , false , "changed bool" )
0 commit comments