Changed type from matchIndex to MatchIndex

master
Aadhavan Srinivasan 2 months ago
parent 9a073aa514
commit 9201ed49bd

@ -8,107 +8,107 @@ import (
var reTests = []struct { var reTests = []struct {
re string re string
str string str string
result []matchIndex result []MatchIndex
}{ }{
{"a", "abc", []matchIndex{{0, 1}}}, {"a", "abc", []MatchIndex{{0, 1}}},
{"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}}}, {"ab+", "qweqweqweaqweqweabbbbbr", []MatchIndex{{16, 22}}},
{"(b|c|A)", "ooaoobocA", []matchIndex{{5, 6}, {7, 8}, {8, 9}}}, {"(b|c|A)", "ooaoobocA", []MatchIndex{{5, 6}, {7, 8}, {8, 9}}},
{"ab*", "a", []matchIndex{{0, 1}}}, {"ab*", "a", []MatchIndex{{0, 1}}},
{"ab*", "abb", []matchIndex{{0, 3}}}, {"ab*", "abb", []MatchIndex{{0, 3}}},
{"a*b", "aaab", []matchIndex{{0, 4}}}, {"a*b", "aaab", []MatchIndex{{0, 4}}},
{"a*b", "qwqw", []matchIndex{}}, {"a*b", "qwqw", []MatchIndex{}},
{"(abc)*", "abcabcabc", []matchIndex{{0, 9}, {9, 9}}}, {"(abc)*", "abcabcabc", []MatchIndex{{0, 9}, {9, 9}}},
{"((abc)|(def))*", "abcdef", []matchIndex{{0, 6}, {6, 6}}}, {"((abc)|(def))*", "abcdef", []MatchIndex{{0, 6}, {6, 6}}},
{"(abc)*|(def)*", "abcdef", []matchIndex{{0, 3}, {3, 6}, {6, 6}}}, {"(abc)*|(def)*", "abcdef", []MatchIndex{{0, 3}, {3, 6}, {6, 6}}},
{"b*a*a", "bba", []matchIndex{{0, 3}}}, {"b*a*a", "bba", []MatchIndex{{0, 3}}},
{"(ab)+", "abcabddd", []matchIndex{{0, 2}, {3, 5}}}, {"(ab)+", "abcabddd", []MatchIndex{{0, 2}, {3, 5}}},
{"a(b(c|d)*)*", "abccbd", []matchIndex{{0, 6}}}, {"a(b(c|d)*)*", "abccbd", []MatchIndex{{0, 6}}},
{"a(b|c)*d+", "abccdd", []matchIndex{{0, 6}}}, {"a(b|c)*d+", "abccdd", []MatchIndex{{0, 6}}},
{"a*", "", []matchIndex{{0, 0}}}, {"a*", "", []MatchIndex{{0, 0}}},
{"a|b", "c", []matchIndex{}}, {"a|b", "c", []MatchIndex{}},
{"(a|b)*c", "aabbc", []matchIndex{{0, 5}}}, {"(a|b)*c", "aabbc", []MatchIndex{{0, 5}}},
{"a(b|b)", "ab", []matchIndex{{0, 2}}}, {"a(b|b)", "ab", []MatchIndex{{0, 2}}},
{"a*", "aaaaaaaa", []matchIndex{{0, 8}, {8, 8}}}, {"a*", "aaaaaaaa", []MatchIndex{{0, 8}, {8, 8}}},
{"ab?", "ab", []matchIndex{{0, 2}}}, {"ab?", "ab", []MatchIndex{{0, 2}}},
{"a?b", "ab", []matchIndex{{0, 2}}}, {"a?b", "ab", []MatchIndex{{0, 2}}},
{"a?", "", []matchIndex{{0, 0}}}, {"a?", "", []MatchIndex{{0, 0}}},
{"a?b?c", "a", []matchIndex{}}, {"a?b?c", "a", []MatchIndex{}},
{"a?b?c?", "ab", []matchIndex{{0, 2}, {2, 2}}}, {"a?b?c?", "ab", []MatchIndex{{0, 2}, {2, 2}}},
{"a?b?c?", "ac", []matchIndex{{0, 2}, {2, 2}}}, {"a?b?c?", "ac", []MatchIndex{{0, 2}, {2, 2}}},
{"a?b?c", "abc", []matchIndex{{0, 3}}}, {"a?b?c", "abc", []MatchIndex{{0, 3}}},
{"a?b?c", "acb", []matchIndex{{0, 2}}}, {"a?b?c", "acb", []MatchIndex{{0, 2}}},
{"[abc]", "defadefbdefce", []matchIndex{{3, 4}, {7, 8}, {11, 12}}}, {"[abc]", "defadefbdefce", []MatchIndex{{3, 4}, {7, 8}, {11, 12}}},
{"[ab]c", "ab", []matchIndex{}}, {"[ab]c", "ab", []MatchIndex{}},
{"g[ab]c", "gac", []matchIndex{{0, 3}}}, {"g[ab]c", "gac", []MatchIndex{{0, 3}}},
{"g[ab]c", "gbc", []matchIndex{{0, 3}}}, {"g[ab]c", "gbc", []MatchIndex{{0, 3}}},
{"g[ab]c", "gc", []matchIndex{}}, {"g[ab]c", "gc", []MatchIndex{}},
{"g[ab]c", "gfc", []matchIndex{}}, {"g[ab]c", "gfc", []MatchIndex{}},
{"[ab]*", "aabbbabaababab", []matchIndex{{0, 14}, {14, 14}}}, {"[ab]*", "aabbbabaababab", []MatchIndex{{0, 14}, {14, 14}}},
{"[ab]+", "aabbbablaababab", []matchIndex{{0, 7}, {8, 15}}}, {"[ab]+", "aabbbablaababab", []MatchIndex{{0, 7}, {8, 15}}},
{"[Ff]r[Uu]it", "fruit", []matchIndex{{0, 5}}}, {"[Ff]r[Uu]it", "fruit", []MatchIndex{{0, 5}}},
{"[Ff]r[Uu]it", "FrUit", []matchIndex{{0, 5}}}, {"[Ff]r[Uu]it", "FrUit", []MatchIndex{{0, 5}}},
{"[Ff]r[Uu|]it", "Fr|it", []matchIndex{{0, 5}}}, {"[Ff]r[Uu|]it", "Fr|it", []MatchIndex{{0, 5}}},
{"[Ff]r([Uu]|[pP])it", "Frpit", []matchIndex{{0, 5}}}, {"[Ff]r([Uu]|[pP])it", "Frpit", []MatchIndex{{0, 5}}},
{"[Ff]r[Uu]|[pP]it", "Frpit", []matchIndex{{2, 5}}}, {"[Ff]r[Uu]|[pP]it", "Frpit", []MatchIndex{{2, 5}}},
{"[a-zA-Z]+", "Hello, how is it going?", []matchIndex{{0, 5}, {7, 10}, {11, 13}, {14, 16}, {17, 22}}}, {"[a-zA-Z]+", "Hello, how is it going?", []MatchIndex{{0, 5}, {7, 10}, {11, 13}, {14, 16}, {17, 22}}},
{".+", "Hello, how is it going?", []matchIndex{{0, 23}}}, {".+", "Hello, how is it going?", []MatchIndex{{0, 23}}},
{"a.", "a ", []matchIndex{{0, 2}}}, {"a.", "a ", []MatchIndex{{0, 2}}},
{"a.b", "a/b", []matchIndex{{0, 3}}}, {"a.b", "a/b", []MatchIndex{{0, 3}}},
{".", "a ", []matchIndex{{0, 1}, {1, 2}}}, {".", "a ", []MatchIndex{{0, 1}, {1, 2}}},
{"a.", "a ", []matchIndex{{0, 2}}}, {"a.", "a ", []MatchIndex{{0, 2}}},
{".+b", "abc", []matchIndex{{0, 2}}}, {".+b", "abc", []MatchIndex{{0, 2}}},
{`\d`, "1a0a3s'''34343s", []matchIndex{{0, 1}, {2, 3}, {4, 5}, {9, 10}, {10, 11}, {11, 12}, {12, 13}, {13, 14}}}, {`\d`, "1a0a3s'''34343s", []MatchIndex{{0, 1}, {2, 3}, {4, 5}, {9, 10}, {10, 11}, {11, 12}, {12, 13}, {13, 14}}},
{`\\`, `a\b\c\qwe\`, []matchIndex{{1, 2}, {3, 4}, {5, 6}, {9, 10}}}, {`\\`, `a\b\c\qwe\`, []MatchIndex{{1, 2}, {3, 4}, {5, 6}, {9, 10}}},
{`\W`, `"Hello", he said. How are you doing?`, []matchIndex{{0, 1}, {6, 7}, {7, 8}, {8, 9}, {11, 12}, {16, 17}, {17, 18}, {21, 22}, {25, 26}, {29, 30}, {35, 36}}}, {`\W`, `"Hello", he said. How are you doing?`, []MatchIndex{{0, 1}, {6, 7}, {7, 8}, {8, 9}, {11, 12}, {16, 17}, {17, 18}, {21, 22}, {25, 26}, {29, 30}, {35, 36}}},
{`\w`, ";';';';';'qwe12", []matchIndex{{10, 11}, {11, 12}, {12, 13}, {13, 14}, {14, 15}}}, {`\w`, ";';';';';'qwe12", []MatchIndex{{10, 11}, {11, 12}, {12, 13}, {13, 14}, {14, 15}}},
{`\s`, "a b c d", []matchIndex{{1, 2}, {3, 4}, {5, 6}, {6, 7}}}, {`\s`, "a b c d", []MatchIndex{{1, 2}, {3, 4}, {5, 6}, {6, 7}}},
{`\<`, "<HTML><body>", []matchIndex{{0, 1}, {6, 7}}}, {`\<`, "<HTML><body>", []MatchIndex{{0, 1}, {6, 7}}},
{`\(.+\)`, "Not (paranthesized), (so) is (this) not", []matchIndex{{4, 35}}}, {`\(.+\)`, "Not (paranthesized), (so) is (this) not", []MatchIndex{{4, 35}}},
{"[^abc]+", "qarbtopsaplpclkpasdmb prejip0r,p", []matchIndex{{0, 1}, {2, 3}, {4, 8}, {9, 12}, {13, 16}, {17, 20}, {21, 32}}}, {"[^abc]+", "qarbtopsaplpclkpasdmb prejip0r,p", []MatchIndex{{0, 1}, {2, 3}, {4, 8}, {9, 12}, {13, 16}, {17, 20}, {21, 32}}},
{"[^a]+", "qqqaq", []matchIndex{{0, 3}, {4, 5}}}, {"[^a]+", "qqqaq", []MatchIndex{{0, 3}, {4, 5}}},
{"[^0-9]+", "a1b2c3dd", []matchIndex{{0, 1}, {2, 3}, {4, 5}, {6, 8}}}, {"[^0-9]+", "a1b2c3dd", []MatchIndex{{0, 1}, {2, 3}, {4, 5}, {6, 8}}},
{"[^abc]+", "ababababbababaccacacacaca", []matchIndex{}}, {"[^abc]+", "ababababbababaccacacacaca", []MatchIndex{}},
{`\([^)]+\)`, "Not (paranthesized), (so) is (this) not", []matchIndex{{4, 19}, {21, 25}, {29, 35}}}, {`\([^)]+\)`, "Not (paranthesized), (so) is (this) not", []MatchIndex{{4, 19}, {21, 25}, {29, 35}}},
{"^ab", "ab bab", []matchIndex{{0, 2}}}, {"^ab", "ab bab", []MatchIndex{{0, 2}}},
{"^aaaa^", "aaaaaaaa", []matchIndex{}}, {"^aaaa^", "aaaaaaaa", []MatchIndex{}},
{"^([bB][Gg])", "bG", []matchIndex{{0, 2}}}, {"^([bB][Gg])", "bG", []MatchIndex{{0, 2}}},
{"b$", "ba", []matchIndex{}}, {"b$", "ba", []MatchIndex{}},
{"(boy|girl)$", "girlf", []matchIndex{}}, {"(boy|girl)$", "girlf", []MatchIndex{}},
{`\bint\b`, "print int integer", []matchIndex{{6, 9}}}, {`\bint\b`, "print int integer", []MatchIndex{{6, 9}}},
{`int\b`, "ints", []matchIndex{}}, {`int\b`, "ints", []MatchIndex{}},
{`int(\b|a)`, "inta", []matchIndex{{0, 4}}}, {`int(\b|a)`, "inta", []MatchIndex{{0, 4}}},
{`\b\d+\b`, "511 a3 43", []matchIndex{{0, 3}, {7, 9}}}, {`\b\d+\b`, "511 a3 43", []MatchIndex{{0, 3}, {7, 9}}},
{`\Bint\B`, "prints int integer print", []matchIndex{{2, 5}}}, {`\Bint\B`, "prints int integer print", []MatchIndex{{2, 5}}},
{`^`, "5^3^2", []matchIndex{{0, 0}}}, {`^`, "5^3^2", []MatchIndex{{0, 0}}},
{`\^`, "5^3^2", []matchIndex{{1, 2}, {3, 4}}}, {`\^`, "5^3^2", []MatchIndex{{1, 2}, {3, 4}}},
{`pool$`, "pool carpool", []matchIndex{{8, 12}}}, {`pool$`, "pool carpool", []MatchIndex{{8, 12}}},
{`^int$`, "print int integer", []matchIndex{}}, {`^int$`, "print int integer", []MatchIndex{}},
{`^int$`, "int", []matchIndex{{0, 3}}}, {`^int$`, "int", []MatchIndex{{0, 3}}},
{`b*`, "aaaaaaaaaaqweqwe", []matchIndex{{0, 0}, {1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}, {7, 7}, {8, 8}, {9, 9}, {10, 10}, {11, 11}, {12, 12}, {13, 13}, {14, 14}, {15, 15}, {16, 16}}}, {`b*`, "aaaaaaaaaaqweqwe", []MatchIndex{{0, 0}, {1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}, {7, 7}, {8, 8}, {9, 9}, {10, 10}, {11, 11}, {12, 12}, {13, 13}, {14, 14}, {15, 15}, {16, 16}}},
{"a{4}", "aabaaa", []matchIndex{}}, {"a{4}", "aabaaa", []MatchIndex{}},
{"ab{5}", "abbbbbab", []matchIndex{{0, 6}}}, {"ab{5}", "abbbbbab", []MatchIndex{{0, 6}}},
{"(a|b){3,4}", "aba", []matchIndex{{0, 3}}}, {"(a|b){3,4}", "aba", []MatchIndex{{0, 3}}},
{"(a|b){3,4}", "ababaa", []matchIndex{{0, 4}}}, {"(a|b){3,4}", "ababaa", []MatchIndex{{0, 4}}},
{"(bc){5,}", "bcbcbcbcbcbcbcbc", []matchIndex{{0, 16}}}, {"(bc){5,}", "bcbcbcbcbcbcbcbc", []MatchIndex{{0, 16}}},
{`\d{3,4}`, "1209", []matchIndex{{0, 4}}}, {`\d{3,4}`, "1209", []MatchIndex{{0, 4}}},
{`\d{3,4}`, "109", []matchIndex{{0, 3}}}, {`\d{3,4}`, "109", []MatchIndex{{0, 3}}},
{`\d{3,4}`, "5", []matchIndex{}}, {`\d{3,4}`, "5", []MatchIndex{}},
{`\d{3,4}`, "123135", []matchIndex{{0, 4}}}, {`\d{3,4}`, "123135", []MatchIndex{{0, 4}}},
{`\d{3,4}`, "89a-0", []matchIndex{}}, {`\d{3,4}`, "89a-0", []MatchIndex{}},
{`\d{3,4}`, "ababab555", []matchIndex{{6, 9}}}, {`\d{3,4}`, "ababab555", []MatchIndex{{6, 9}}},
{`\bpaint\b`, "paints", []matchIndex{}}, {`\bpaint\b`, "paints", []MatchIndex{}},
{`\b\w{5}\b`, "paint", []matchIndex{{0, 5}}}, {`\b\w{5}\b`, "paint", []MatchIndex{{0, 5}}},
} }
func TestFindAllMatches(t *testing.T) { func TestFindAllMatches(t *testing.T) {

Loading…
Cancel
Save