From 80ea2620647c19148310f98f38f16a0ee14c7488 Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Mon, 9 Dec 2024 01:06:18 -0500 Subject: [PATCH] Updated test-case structs to reflect the name of the new type --- re_test.go | 274 +++++++++++++++++++++++++++-------------------------- 1 file changed, 140 insertions(+), 134 deletions(-) diff --git a/re_test.go b/re_test.go index b32b4ce..ef8c2d5 100644 --- a/re_test.go +++ b/re_test.go @@ -8,160 +8,166 @@ import ( var reTests = []struct { re string str string - result []MatchIndex + result []Group // Stores all zero-groups in the match }{ - {"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}}}, - {"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}}}, - {"a*b", "aaab", []MatchIndex{{0, 4}}}, - {"a*b", "qwqw", []MatchIndex{}}, - {"(abc)*", "abcabcabc", []MatchIndex{{0, 9}, {9, 9}}}, - {"((abc)|(def))*", "abcdef", []MatchIndex{{0, 6}, {6, 6}}}, - {"(abc)*|(def)*", "abcdef", []MatchIndex{{0, 3}, {3, 6}, {6, 6}}}, - {"b*a*a", "bba", []MatchIndex{{0, 3}}}, - {"(ab)+", "abcabddd", []MatchIndex{{0, 2}, {3, 5}}}, - {"a(b(c|d)*)*", "abccbd", []MatchIndex{{0, 6}}}, - {"a(b|c)*d+", "abccdd", []MatchIndex{{0, 6}}}, - {"a*", "", []MatchIndex{{0, 0}}}, - {"a|b", "c", []MatchIndex{}}, - {"(a|b)*c", "aabbc", []MatchIndex{{0, 5}}}, - {"a(b|b)", "ab", []MatchIndex{{0, 2}}}, - {"a*", "aaaaaaaa", []MatchIndex{{0, 8}, {8, 8}}}, + {"a", "abc", []Group{{0, 1}}}, + {"a", "bca", []Group{{2, 3}}}, + {"l", "ggllgg", []Group{{2, 3}, {3, 4}}}, + {"(b|c)", "abdceb", []Group{{1, 2}, {3, 4}, {5, 6}}}, + {"a+", "brerereraaaaabbbbb", []Group{{8, 13}}}, + {"ab+", "qweqweqweaqweqweabbbbbr", []Group{{16, 22}}}, + {"(b|c|A)", "ooaoobocA", []Group{{5, 6}, {7, 8}, {8, 9}}}, + {"ab*", "a", []Group{{0, 1}}}, + {"ab*", "abb", []Group{{0, 3}}}, + {"a*b", "aaab", []Group{{0, 4}}}, + {"a*b", "qwqw", []Group{}}, + {"(abc)*", "abcabcabc", []Group{{0, 9}, {9, 9}}}, + {"((abc)|(def))*", "abcdef", []Group{{0, 6}, {6, 6}}}, + {"(abc)*|(def)*", "abcdef", []Group{{0, 3}, {3, 6}, {6, 6}}}, + {"b*a*a", "bba", []Group{{0, 3}}}, + {"(ab)+", "abcabddd", []Group{{0, 2}, {3, 5}}}, + {"a(b(c|d)*)*", "abccbd", []Group{{0, 6}}}, + {"a(b|c)*d+", "abccdd", []Group{{0, 6}}}, + {"a*", "", []Group{{0, 0}}}, + {"a|b", "c", []Group{}}, + {"(a|b)*c", "aabbc", []Group{{0, 5}}}, + {"a(b|b)", "ab", []Group{{0, 2}}}, + {"a*", "aaaaaaaa", []Group{{0, 8}, {8, 8}}}, - {"ab?", "ab", []MatchIndex{{0, 2}}}, - {"a?b", "ab", []MatchIndex{{0, 2}}}, - {"a?", "", []MatchIndex{{0, 0}}}, - {"a?b?c", "a", []MatchIndex{}}, - {"a?b?c?", "ab", []MatchIndex{{0, 2}, {2, 2}}}, - {"a?b?c?", "ac", []MatchIndex{{0, 2}, {2, 2}}}, - {"a?b?c", "abc", []MatchIndex{{0, 3}}}, - {"a?b?c", "acb", []MatchIndex{{0, 2}}}, + {"ab?", "ab", []Group{{0, 2}}}, + {"a?b", "ab", []Group{{0, 2}}}, + {"a?", "", []Group{{0, 0}}}, + {"a?b?c", "a", []Group{}}, + {"a?b?c?", "ab", []Group{{0, 2}, {2, 2}}}, + {"a?b?c?", "ac", []Group{{0, 2}, {2, 2}}}, + {"a?b?c", "abc", []Group{{0, 3}}}, + {"a?b?c", "acb", []Group{{0, 2}}}, - {"[abc]", "defadefbdefce", []MatchIndex{{3, 4}, {7, 8}, {11, 12}}}, - {"[ab]c", "ab", []MatchIndex{}}, - {"g[ab]c", "gac", []MatchIndex{{0, 3}}}, - {"g[ab]c", "gbc", []MatchIndex{{0, 3}}}, - {"g[ab]c", "gc", []MatchIndex{}}, - {"g[ab]c", "gfc", []MatchIndex{}}, - {"[ab]*", "aabbbabaababab", []MatchIndex{{0, 14}, {14, 14}}}, - {"[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", "Fr|it", []MatchIndex{{0, 5}}}, - {"[Ff]r([Uu]|[pP])it", "Frpit", []MatchIndex{{0, 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}}}, + {"[abc]", "defadefbdefce", []Group{{3, 4}, {7, 8}, {11, 12}}}, + {"[ab]c", "ab", []Group{}}, + {"g[ab]c", "gac", []Group{{0, 3}}}, + {"g[ab]c", "gbc", []Group{{0, 3}}}, + {"g[ab]c", "gc", []Group{}}, + {"g[ab]c", "gfc", []Group{}}, + {"[ab]*", "aabbbabaababab", []Group{{0, 14}, {14, 14}}}, + {"[ab]+", "aabbbablaababab", []Group{{0, 7}, {8, 15}}}, + {"[Ff]r[Uu]it", "fruit", []Group{{0, 5}}}, + {"[Ff]r[Uu]it", "FrUit", []Group{{0, 5}}}, + {"[Ff]r[Uu|]it", "Fr|it", []Group{{0, 5}}}, + {"[Ff]r([Uu]|[pP])it", "Frpit", []Group{{0, 5}}}, + {"[Ff]r[Uu]|[pP]it", "Frpit", []Group{{2, 5}}}, + {"[a-zA-Z]+", "Hello, how is it going?", []Group{{0, 5}, {7, 10}, {11, 13}, {14, 16}, {17, 22}}}, - {".+", "Hello, how is it going?", []MatchIndex{{0, 23}}}, - {"a.", "a ", []MatchIndex{{0, 2}}}, - {"a.b", "a/b", []MatchIndex{{0, 3}}}, - {".", "a ", []MatchIndex{{0, 1}, {1, 2}}}, - {"a.", "a ", []MatchIndex{{0, 2}}}, - {".+b", "abc", []MatchIndex{{0, 2}}}, + {".+", "Hello, how is it going?", []Group{{0, 23}}}, + {"a.", "a ", []Group{{0, 2}}}, + {"a.b", "a/b", []Group{{0, 3}}}, + {".", "a ", []Group{{0, 1}, {1, 2}}}, + {"a.", "a ", []Group{{0, 2}}}, + {".+b", "abc", []Group{{0, 2}}}, - {`\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}}}, - {`\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}}}, - {`\s`, "a b c d", []MatchIndex{{1, 2}, {3, 4}, {5, 6}, {6, 7}}}, - {`\<`, "", []MatchIndex{{0, 1}, {6, 7}}}, - {`\(.+\)`, "Not (paranthesized), (so) is (this) not", []MatchIndex{{4, 35}}}, + {`\d`, "1a0a3s'''34343s", []Group{{0, 1}, {2, 3}, {4, 5}, {9, 10}, {10, 11}, {11, 12}, {12, 13}, {13, 14}}}, + {`\\`, `a\b\c\qwe\`, []Group{{1, 2}, {3, 4}, {5, 6}, {9, 10}}}, + {`\W`, `"Hello", he said. How are you doing?`, []Group{{0, 1}, {6, 7}, {7, 8}, {8, 9}, {11, 12}, {16, 17}, {17, 18}, {21, 22}, {25, 26}, {29, 30}, {35, 36}}}, + {`\w`, ";';';';';'qwe12", []Group{{10, 11}, {11, 12}, {12, 13}, {13, 14}, {14, 15}}}, + {`\s`, "a b c d", []Group{{1, 2}, {3, 4}, {5, 6}, {6, 7}}}, + {`\<`, "", []Group{{0, 1}, {6, 7}}}, + {`\(.+\)`, "Not (paranthesized), (so) is (this) not", []Group{{4, 35}}}, - {"[^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}}}, - {"[^0-9]+", "a1b2c3dd", []MatchIndex{{0, 1}, {2, 3}, {4, 5}, {6, 8}}}, - {"[^abc]+", "ababababbababaccacacacaca", []MatchIndex{}}, - {`\[`, "a[b[c[]]]", []MatchIndex{{1, 2}, {3, 4}, {5, 6}}}, - {`\([^)]+\)`, "Not (paranthesized), (so) is (this) not", []MatchIndex{{4, 19}, {21, 25}, {29, 35}}}, + {"[^abc]+", "qarbtopsaplpclkpasdmb prejip0r,p", []Group{{0, 1}, {2, 3}, {4, 8}, {9, 12}, {13, 16}, {17, 20}, {21, 32}}}, + {"[^a]+", "qqqaq", []Group{{0, 3}, {4, 5}}}, + {"[^0-9]+", "a1b2c3dd", []Group{{0, 1}, {2, 3}, {4, 5}, {6, 8}}}, + {"[^abc]+", "ababababbababaccacacacaca", []Group{}}, + {`\[`, "a[b[c[]]]", []Group{{1, 2}, {3, 4}, {5, 6}}}, + {`\([^)]+\)`, "Not (paranthesized), (so) is (this) not", []Group{{4, 19}, {21, 25}, {29, 35}}}, - {"^ab", "ab bab", []MatchIndex{{0, 2}}}, - {"^aaaa^", "aaaaaaaa", []MatchIndex{}}, - {"^([bB][Gg])", "bG", []MatchIndex{{0, 2}}}, - {"b$", "ba", []MatchIndex{}}, - {"(boy|girl)$", "girlf", []MatchIndex{}}, - {`\bint\b`, "print int integer", []MatchIndex{{6, 9}}}, - {`int\b`, "ints", []MatchIndex{}}, - {`int(\b|a)`, "inta", []MatchIndex{{0, 4}}}, - {`\b\d+\b`, "511 a3 43", []MatchIndex{{0, 3}, {7, 9}}}, - {`\Bint\B`, "prints int integer print", []MatchIndex{{2, 5}}}, - {`^`, "5^3^2", []MatchIndex{{0, 0}}}, - {`\^`, "5^3^2", []MatchIndex{{1, 2}, {3, 4}}}, - {`pool$`, "pool carpool", []MatchIndex{{8, 12}}}, - {`^int$`, "print int integer", []MatchIndex{}}, - {`^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}}}, + {"^ab", "ab bab", []Group{{0, 2}}}, + {"^aaaa^", "aaaaaaaa", []Group{}}, + {"^([bB][Gg])", "bG", []Group{{0, 2}}}, + {"b$", "ba", []Group{}}, + {"(boy|girl)$", "girlf", []Group{}}, + {`\bint\b`, "print int integer", []Group{{6, 9}}}, + {`int\b`, "ints", []Group{}}, + {`int(\b|a)`, "inta", []Group{{0, 4}}}, + {`\b\d+\b`, "511 a3 43", []Group{{0, 3}, {7, 9}}}, + {`\Bint\B`, "prints int integer print", []Group{{2, 5}}}, + {`^`, "5^3^2", []Group{{0, 0}}}, + {`\^`, "5^3^2", []Group{{1, 2}, {3, 4}}}, + {`pool$`, "pool carpool", []Group{{8, 12}}}, + {`^int$`, "print int integer", []Group{}}, + {`^int$`, "int", []Group{{0, 3}}}, + {`b*`, "aaaaaaaaaaqweqwe", []Group{{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{}}, - {"ab{5}", "abbbbbab", []MatchIndex{{0, 6}}}, - {"(a|b){3,4}", "aba", []MatchIndex{{0, 3}}}, - {"(a|b){3,4}", "ababaa", []MatchIndex{{0, 4}}}, - {"(bc){5,}", "bcbcbcbcbcbcbcbc", []MatchIndex{{0, 16}}}, - {`\d{3,4}`, "1209", []MatchIndex{{0, 4}}}, - {`\d{3,4}`, "109", []MatchIndex{{0, 3}}}, - {`\d{3,4}`, "5", []MatchIndex{}}, - {`\d{3,4}`, "123135", []MatchIndex{{0, 4}}}, - {`\d{3,4}`, "89a-0", []MatchIndex{}}, - {`\d{3,4}`, "ababab555", []MatchIndex{{6, 9}}}, - {`\bpaint\b`, "paints", []MatchIndex{}}, - {`\b\w{5}\b`, "paint", []MatchIndex{{0, 5}}}, + {"a{4}", "aabaaa", []Group{}}, + {"ab{5}", "abbbbbab", []Group{{0, 6}}}, + {"(a|b){3,4}", "aba", []Group{{0, 3}}}, + {"(a|b){3,4}", "ababaa", []Group{{0, 4}}}, + {"(bc){5,}", "bcbcbcbcbcbcbcbc", []Group{{0, 16}}}, + {`\d{3,4}`, "1209", []Group{{0, 4}}}, + {`\d{3,4}`, "109", []Group{{0, 3}}}, + {`\d{3,4}`, "5", []Group{}}, + {`\d{3,4}`, "123135", []Group{{0, 4}}}, + {`\d{3,4}`, "89a-0", []Group{}}, + {`\d{3,4}`, "ababab555", []Group{{6, 9}}}, + {`\bpaint\b`, "paints", []Group{}}, + {`\b\w{5}\b`, "paint", []Group{{0, 5}}}, // Unicode tests - {`.+`, "úïäö´«åæïëòöê»éãçâï«úïòíñ", []MatchIndex{{0, 25}}}, - {`a.b`, "a²b", []MatchIndex{{0, 3}}}, - {`[^a]+`, "úïäö´«åæïëòöê»éãçâï«úïòíñ", []MatchIndex{{0, 25}}}, + {`.+`, "úïäö´«åæïëòöê»éãçâï«úïòíñ", []Group{{0, 25}}}, + {`a.b`, "a²b", []Group{{0, 3}}}, + {`[^a]+`, "úïäö´«åæïëòöê»éãçâï«úïòíñ", []Group{{0, 25}}}, // Fun experiment - AI-generated tests - {"(abc|def|ghi)", "abcdefg", []MatchIndex{{0, 3}, {3, 6}}}, - {"a(b|c)d", "abcd", []MatchIndex{}}, - {"a(b|c)*d", "abcbcd", []MatchIndex{{0, 6}}}, - {"a(b|c)+d", "abcbcd", []MatchIndex{{0, 6}}}, - {"a(b|c)?d", "abd", []MatchIndex{{0, 3}}}, - {".+", "hello world", []MatchIndex{{0, 11}}}, - {"a.b", "aXb", []MatchIndex{{0, 3}}}, - {"a.*b", "aXb", []MatchIndex{{0, 3}}}, - {"a.{2,3}b", "aXXb", []MatchIndex{{0, 4}}}, - {"a.{2,}b", "aXXXb", []MatchIndex{{0, 5}}}, - {"a.{0,3}b", "ab", []MatchIndex{{0, 2}}}, - {"[abc]+", "abcabc", []MatchIndex{{0, 6}}}, - {"[a-zA-Z]+", "HelloWorld", []MatchIndex{{0, 10}}}, - {"[^abc]+", "defghi", []MatchIndex{{0, 6}}}, - {"^hello", "hello world", []MatchIndex{{0, 5}}}, - {"world$", "hello world", []MatchIndex{{6, 11}}}, - {`\bhello\b`, "hello world", []MatchIndex{{0, 5}}}, - {`\Bhello\B`, "hello world", []MatchIndex{}}, - {"(hello|world)", "hello world", []MatchIndex{{0, 5}, {6, 11}}}, - {"(hello|world)+", "hello world", []MatchIndex{{0, 5}, {6, 11}}}, - {"(hello|world)*", "hello world", []MatchIndex{{0, 5}, {5, 5}, {6, 11}, {11, 11}}}, - {"(hello|world)?", "hello world", []MatchIndex{{0, 5}, {5, 5}, {6, 11}, {11, 11}}}, - {"ú.+ï", "úïäö´«åæïëòöê»éãçâï«úïòíñ", []MatchIndex{{0, 22}}}, - {"(?=hello)", "hello world", []MatchIndex{{0, 0}}}, - {"(?!hello)", "hello world", []MatchIndex{{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}, {7, 7}, {8, 8}, {9, 9}, {10, 10}, {11, 11}}}, - {"(?<=hello)", "hello world", []MatchIndex{{5, 5}}}, - {"(?