You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
747 B
Go
32 lines
747 B
Go
package main
|
|
|
|
import (
|
|
"slices"
|
|
"testing"
|
|
)
|
|
|
|
var reTests = []struct {
|
|
re string
|
|
str string
|
|
result []matchIndex
|
|
}{
|
|
{"a", "abc", []matchIndex{{0, 1}}},
|
|
{"a", "bca", []matchIndex{{2, 3}}},
|
|
{"l", "ggllgg", []matchIndex{{2, 3}, {3, 4}}},
|
|
{"(b|c)", "abdceb", []matchIndex{{1, 2}, {3, 4}, {5, 6}}},
|
|
{"a*", "brerereraaaaabbbbb", []matchIndex{{8, 13}}},
|
|
}
|
|
|
|
func TestFindAllMatches(t *testing.T) {
|
|
for _, test := range reTests {
|
|
t.Run(test.re+" "+test.str, func(t *testing.T) {
|
|
re_postfix := shuntingYard(test.re)
|
|
startState := thompson(re_postfix)
|
|
matchIndices := findAllMatches(startState, test.str)
|
|
if !slices.Equal(test.result, matchIndices) {
|
|
t.Errorf("Wanted %v Got %v\n", test.result, matchIndices)
|
|
}
|
|
})
|
|
}
|
|
}
|