github.com/mutagen-io/mutagen@v0.18.0-rc1/pkg/comparison/strings_test.go (about) 1 package comparison 2 3 import ( 4 "testing" 5 ) 6 7 // TestStringSlicesEqual tests StringSlicesEqual. 8 func TestStringSlicesEqual(t *testing.T) { 9 // Set up test cases. 10 testCases := []struct { 11 first []string 12 second []string 13 expected bool 14 }{ 15 {nil, nil, true}, 16 {[]string{}, nil, true}, 17 {nil, []string{}, true}, 18 {[]string{}, []string{}, true}, 19 {[]string{"cat"}, nil, false}, 20 {nil, []string{"dog"}, false}, 21 {[]string{"cat"}, []string{}, false}, 22 {[]string{}, []string{"dog"}, false}, 23 {[]string{"cat"}, []string{"dog"}, false}, 24 {[]string{"cat"}, []string{"cat", "dog"}, false}, 25 {[]string{"cat", "dog"}, []string{"cat"}, false}, 26 {[]string{"cat"}, []string{"cat"}, true}, 27 {[]string{"cat", "dog"}, []string{"cat", "dog"}, true}, 28 {[]string{"cat", "dog"}, []string{"dog", "cat"}, false}, 29 } 30 31 // Process test cases. 32 for _, testCase := range testCases { 33 if equal := StringSlicesEqual(testCase.first, testCase.second); equal != testCase.expected { 34 t.Errorf("unexpected comparison result: %v == %v? %t (expected %t)", 35 testCase.first, testCase.second, 36 equal, testCase.expected, 37 ) 38 } 39 } 40 } 41 42 // TestStringMapsEqual tests StringMapsEqual. 43 func TestStringMapsEqual(t *testing.T) { 44 // Set up test cases. 45 testCases := []struct { 46 first map[string]string 47 second map[string]string 48 expected bool 49 }{ 50 {nil, nil, true}, 51 {map[string]string{}, nil, true}, 52 {nil, map[string]string{}, true}, 53 {map[string]string{}, map[string]string{}, true}, 54 {map[string]string{"cat": "meow"}, nil, false}, 55 {nil, map[string]string{"dog": "bark"}, false}, 56 {map[string]string{"cat": "meow"}, map[string]string{}, false}, 57 {map[string]string{}, map[string]string{"dog": "bark"}, false}, 58 {map[string]string{"cat": "meow"}, map[string]string{"dog": "bark"}, false}, 59 {map[string]string{"cat": "meow"}, map[string]string{"cat": "meow", "dog": "bark"}, false}, 60 {map[string]string{"cat": "meow", "dog": "bark"}, map[string]string{"cat": "meow"}, false}, 61 {map[string]string{"cat": "meow"}, map[string]string{"cat": "meow"}, true}, 62 {map[string]string{"cat": "meow", "dog": "bark"}, map[string]string{"cat": "meow", "dog": "bark"}, true}, 63 } 64 65 // Process test cases. 66 for _, testCase := range testCases { 67 if equal := StringMapsEqual(testCase.first, testCase.second); equal != testCase.expected { 68 t.Errorf("unexpected comparison result: %v == %v? %t (expected %t)", 69 testCase.first, testCase.second, 70 equal, testCase.expected, 71 ) 72 } 73 } 74 }