github.com/prebid/prebid-server/v2@v2.18.0/util/sliceutil/containstring_test.go (about) 1 package sliceutil 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestContainsStringIgnoreCase(t *testing.T) { 10 testCases := []struct { 11 description string 12 givenSlice []string 13 givenValue string 14 expected bool 15 }{ 16 { 17 description: "Nil", 18 givenSlice: nil, 19 givenValue: "a", 20 expected: false, 21 }, 22 { 23 description: "Empty", 24 givenSlice: []string{}, 25 givenValue: "a", 26 expected: false, 27 }, 28 { 29 description: "One - Match - Same Case", 30 givenSlice: []string{"a"}, 31 givenValue: "a", 32 expected: true, 33 }, 34 { 35 description: "One - Match - Different Case", 36 givenSlice: []string{"a"}, 37 givenValue: "A", 38 expected: true, 39 }, 40 { 41 description: "One - No Match", 42 givenSlice: []string{"a"}, 43 givenValue: "z", 44 expected: false, 45 }, 46 { 47 description: "Many - Match - Same Case", 48 givenSlice: []string{"a", "b"}, 49 givenValue: "b", 50 expected: true, 51 }, 52 { 53 description: "Many - Match - Different Case", 54 givenSlice: []string{"a", "b"}, 55 givenValue: "B", 56 expected: true, 57 }, 58 { 59 description: "Many - No Match", 60 givenSlice: []string{"a", "b"}, 61 givenValue: "z", 62 expected: false, 63 }, 64 } 65 66 for _, test := range testCases { 67 result := ContainsStringIgnoreCase(test.givenSlice, test.givenValue) 68 assert.Equal(t, test.expected, result, test.description) 69 } 70 }