|
|
@ -14,12 +14,19 @@ var reTests = []struct {
|
|
|
|
{"a", "bca", []matchIndex{{2, 3}}},
|
|
|
|
{"a", "bca", []matchIndex{{2, 3}}},
|
|
|
|
{"l", "ggllgg", []matchIndex{{2, 3}, {3, 4}}},
|
|
|
|
{"l", "ggllgg", []matchIndex{{2, 3}, {3, 4}}},
|
|
|
|
{"(b|c)", "abdceb", []matchIndex{{1, 2}, {3, 4}, {5, 6}}},
|
|
|
|
{"(b|c)", "abdceb", []matchIndex{{1, 2}, {3, 4}, {5, 6}}},
|
|
|
|
{"a*", "brerereraaaaabbbbb", []matchIndex{{8, 13}}},
|
|
|
|
{"a+", "brerereraaaaabbbbb", []matchIndex{{8, 13}}},
|
|
|
|
|
|
|
|
{"ab+", "qweqweqweaqweqweabbbbbr", []matchIndex{{16, 22}}},
|
|
|
|
|
|
|
|
{"(b|c|A)", "ooaoobocA", []matchIndex{{5, 6}, {7, 8}, {8, 9}}},
|
|
|
|
|
|
|
|
{"ab*", "a", []matchIndex{{0, 1}}},
|
|
|
|
|
|
|
|
{"ab*", "abb", []matchIndex{{0, 3}}},
|
|
|
|
|
|
|
|
{"(abc)*", "abcabcabc", []matchIndex{{0, 9}}},
|
|
|
|
|
|
|
|
{"((abc)|(def))*", "abcdef", []matchIndex{{0, 6}}},
|
|
|
|
|
|
|
|
{"(abc)*|(def)*", "abcdef", []matchIndex{{0, 3}, {3, 6}}},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestFindAllMatches(t *testing.T) {
|
|
|
|
func TestFindAllMatches(t *testing.T) {
|
|
|
|
for _, test := range reTests {
|
|
|
|
for _, test := range reTests {
|
|
|
|
t.Run(test.re+" "+test.str, func(t *testing.T) {
|
|
|
|
t.Run(test.re+" "+test.str, func(t *testing.T) {
|
|
|
|
re_postfix := shuntingYard(test.re)
|
|
|
|
re_postfix := shuntingYard(test.re)
|
|
|
|
startState := thompson(re_postfix)
|
|
|
|
startState := thompson(re_postfix)
|
|
|
|
matchIndices := findAllMatches(startState, test.str)
|
|
|
|
matchIndices := findAllMatches(startState, test.str)
|
|
|
|