@@ -672,69 +672,83 @@ func TestContainsNotContainsOnNilValue(t *testing.T) {
672
672
}
673
673
674
674
func TestSubsetNotSubset (t * testing.T ) {
675
-
676
- // MTestCase adds a custom message to the case
677
675
cases := []struct {
678
- expected interface {}
679
- actual interface {}
680
- result bool
681
- message string
676
+ list interface {}
677
+ subset interface {}
678
+ result bool
679
+ message string
682
680
}{
683
681
// cases that are expected to contain
684
- {[]int {1 , 2 , 3 }, nil , true , "given subset is nil" },
685
- {[]int {1 , 2 , 3 }, []int {}, true , "any set contains the nil set" },
686
- {[]int {1 , 2 , 3 }, []int {1 , 2 }, true , "[1, 2, 3] contains [1, 2]" },
687
- {[]int {1 , 2 , 3 }, []int {1 , 2 , 3 }, true , "[1, 2, 3] contains [1, 2, 3" },
688
- {[]string {"hello" , "world" }, []string {"hello" }, true , "[ \ " hello\" , \" world \" ] contains [ \ " hello\" ]" },
682
+ {[]int {1 , 2 , 3 }, nil , true , `nil is the empty set which is a subset of every set` },
683
+ {[]int {1 , 2 , 3 }, []int {}, true , `[] is a subset of ['\x01' '\x02' '\x03']` },
684
+ {[]int {1 , 2 , 3 }, []int {1 , 2 }, true , `['\x01' '\x02'] is a subset of ['\x01' '\x02' '\x03']` },
685
+ {[]int {1 , 2 , 3 }, []int {1 , 2 , 3 }, true , `['\x01' '\x02' '\x03'] is a subset of ['\x01' '\x02' '\x03']` },
686
+ {[]string {"hello" , "world" }, []string {"hello" }, true , `[ "hello"] is a subset of [ "hello" "world"]` },
689
687
{map [string ]string {
690
688
"a" : "x" ,
691
689
"c" : "z" ,
692
690
"b" : "y" ,
693
691
}, map [string ]string {
694
692
"a" : "x" ,
695
693
"b" : "y" ,
696
- }, true , `{ "a": "x", "b": "y", "c": "z"} contains { "a": "x", "b": "y"} ` },
694
+ }, true , `map[ "a":"x" "b":"y"] is a subset of map[ "a":"x" "b":"y" "c":"z"] ` },
697
695
698
696
// cases that are expected not to contain
699
- {[]string {"hello" , "world" }, []string {"hello" , "testify" }, false , "[ \ " hello\ " , \ " world\" ] does not contain [ \" hello \" , \" testify\" ]" },
700
- {[]int {1 , 2 , 3 }, []int {4 , 5 }, false , "[ 1, 2, 3] does not contain [4, 5" },
701
- {[]int {1 , 2 , 3 }, []int {1 , 5 }, false , "[ 1, 2, 3] does not contain [1, 5]" },
697
+ {[]string {"hello" , "world" }, []string {"hello" , "testify" }, false , `[]string{ "hello", "world"} does not contain " testify"` },
698
+ {[]int {1 , 2 , 3 }, []int {4 , 5 }, false , `[]int{ 1, 2, 3} does not contain 4` },
699
+ {[]int {1 , 2 , 3 }, []int {1 , 5 }, false , `[]int{ 1, 2, 3} does not contain 5` },
702
700
{map [string ]string {
703
701
"a" : "x" ,
704
702
"c" : "z" ,
705
703
"b" : "y" ,
706
704
}, map [string ]string {
707
705
"a" : "x" ,
708
706
"b" : "z" ,
709
- }, false , `{ "a": "x", "b": "y", "c": "z"} does not contain { "a": "x", "b": "z"}` },
707
+ }, false , `map[string]string{"a":"x", "b":"y", "c":"z"} does not contain map[string]string{"a":"x", "b":"z"}` },
708
+ {map [string ]string {
709
+ "a" : "x" ,
710
+ "b" : "y" ,
711
+ }, map [string ]string {
712
+ "a" : "x" ,
713
+ "b" : "y" ,
714
+ "c" : "z" ,
715
+ }, false , `map[string]string{"a":"x", "b":"y"} does not contain map[string]string{"a":"x", "b":"y", "c":"z"}` },
710
716
}
711
717
712
718
for _ , c := range cases {
713
719
t .Run ("SubSet: " + c .message , func (t * testing.T ) {
714
720
715
- mockT := new (testing. T )
716
- res := Subset (mockT , c .expected , c .actual )
721
+ mockT := new (mockTestingT )
722
+ res := Subset (mockT , c .list , c .subset )
717
723
718
724
if res != c .result {
719
- if res {
720
- t .Errorf ("Subset should return true: %s" , c .message )
721
- } else {
722
- t .Errorf ("Subset should return false: %s" , c .message )
725
+ t .Errorf ("Subset should return %t: %s" , c .result , c .message )
726
+ }
727
+ if ! c .result {
728
+ expectedFail := c .message
729
+ actualFail := mockT .errorString ()
730
+ if ! strings .Contains (actualFail , expectedFail ) {
731
+ t .Log (actualFail )
732
+ t .Errorf ("Subset failure should contain %q but was %q" , expectedFail , actualFail )
723
733
}
724
734
}
725
735
})
726
736
}
727
737
for _ , c := range cases {
728
738
t .Run ("NotSubSet: " + c .message , func (t * testing.T ) {
729
- mockT := new (testing. T )
730
- res := NotSubset (mockT , c .expected , c .actual )
739
+ mockT := new (mockTestingT )
740
+ res := NotSubset (mockT , c .list , c .subset )
731
741
732
742
// NotSubset should match the inverse of Subset. If it doesn't, something is wrong
733
- if res == Subset (mockT , c .expected , c .actual ) {
734
- if res {
735
- t .Errorf ("NotSubset should return true: %s" , c .message )
736
- } else {
737
- t .Errorf ("NotSubset should return false: %s" , c .message )
743
+ if res == Subset (mockT , c .list , c .subset ) {
744
+ t .Errorf ("NotSubset should return %t: %s" , ! c .result , c .message )
745
+ }
746
+ if c .result {
747
+ expectedFail := c .message
748
+ actualFail := mockT .errorString ()
749
+ if ! strings .Contains (actualFail , expectedFail ) {
750
+ t .Log (actualFail )
751
+ t .Errorf ("NotSubset failure should contain %q but was %q" , expectedFail , actualFail )
738
752
}
739
753
}
740
754
})
0 commit comments