Running all tests case-insensitive with the same match indices wasn't a good idea

master
Aadhavan Srinivasan 5 days ago
parent 4a45d1c95e
commit 94c8044eb7

@ -427,27 +427,6 @@ func TestFindAllMatches(t *testing.T) {
} }
}) })
} }
fmt.Printf("----------------CASE INSENSITIVE MATCHING----------------")
// Case-insensitive run, with test string case-swapped
for _, test := range reTests {
t.Run(test.re+" "+swapCase(test.str), func(t *testing.T) {
regComp, err := Compile(test.re, append(test.flags, RE_CASE_INSENSITIVE)...)
if err != nil {
if test.result != nil {
panic(fmt.Errorf("Test Error: %v", err))
}
} else {
matchIndices := FindAllMatches(regComp, swapCase(test.str))
zeroGroups := make([]Group, len(matchIndices))
for i, m := range matchIndices {
zeroGroups[i] = m[0]
}
if !slices.Equal(test.result, zeroGroups) {
t.Errorf("Wanted %v Got %v\n", test.result, zeroGroups)
}
}
})
}
} }
func TestFindString(t *testing.T) { func TestFindString(t *testing.T) {
@ -473,30 +452,6 @@ func TestFindString(t *testing.T) {
} }
}) })
} }
fmt.Printf("----------------CASE INSENSITIVE MATCHING----------------")
// Case-insensitive run, with test string case-swapped
for _, test := range reTests {
t.Run(test.re+" "+swapCase(test.str), func(t *testing.T) {
regComp, err := Compile(test.re, append(test.flags, RE_CASE_INSENSITIVE)...)
if err != nil {
if test.result != nil {
panic(err)
}
} else {
foundString := FindString(regComp, swapCase(test.str))
if len(test.result) == 0 {
if foundString != "" {
t.Errorf("Expected no match got %v\n", foundString)
}
} else {
expectedString := test.str[test.result[0].startIdx:test.result[0].endIdx]
if foundString != expectedString {
t.Errorf("Wanted %v Got %v\n", expectedString, foundString)
}
}
}
})
}
} }
func TestFindAllGroups(t *testing.T) { func TestFindAllGroups(t *testing.T) {
@ -520,26 +475,4 @@ func TestFindAllGroups(t *testing.T) {
} }
}) })
} }
fmt.Printf("----------------CASE INSENSITIVE MATCHING----------------")
// Case-insensitive run, with test string case-swapped
for _, test := range groupTests {
t.Run(test.re+" "+swapCase(test.str), func(t *testing.T) {
regComp, err := Compile(test.re, append(test.flags, RE_CASE_INSENSITIVE)...)
if err != nil {
if test.result != nil {
panic(err)
}
}
matchIndices := FindAllMatches(regComp, swapCase(test.str))
for i := range matchIndices {
for j := range matchIndices[i] {
if matchIndices[i][j].isValid() {
if test.result[i][j] != matchIndices[i][j] {
t.Errorf("Wanted %v Got %v\n", test.result, matchIndices)
}
}
}
}
})
}
} }

Loading…
Cancel
Save