From 8feaefeeb8901adb6c73be185aeeef4a05ea9589 Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Sat, 25 Jan 2025 22:36:04 -0500 Subject: [PATCH] Added more tests --- re_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/re_test.go b/re_test.go index 6730a04..2583501 100644 --- a/re_test.go +++ b/re_test.go @@ -265,6 +265,21 @@ var reTests = []struct { {`\By\B`, nil, `xyz`, []Group{{1, 2}}}, {`ab|cd`, nil, `abc`, []Group{{0, 2}}}, {`ab|cd`, nil, `abcd`, []Group{{0, 2}, {2, 4}}}, + {`$b`, nil, `b`, []Group{}}, + {`a\(b`, nil, `a(b`, []Group{{0, 3}}}, + {`a\(*b`, nil, `ab`, []Group{{0, 2}}}, + {`a\(*b`, nil, `a((b`, []Group{{0, 4}}}, + {`a\\b`, nil, `a\b`, []Group{{0, 3}}}, + {`a+b+c`, nil, `aabbabc`, []Group{{4, 7}}}, + {`)(`, nil, `-`, nil}, + {`[^ab]*`, nil, `cde`, []Group{{0, 3}, {3, 3}}}, + {`abc`, nil, ``, []Group{}}, + {`a*`, nil, ``, []Group{{0, 0}}}, + {`a|b|c|d|e`, nil, `e`, []Group{{0, 1}}}, + {`abcd*efg`, nil, `abcdefg`, []Group{{0, 7}}}, + {`ab*`, nil, `xabyabbbz`, []Group{{1, 3}, {4, 8}}}, + {`ab*`, nil, `xayabbbz`, []Group{{1, 2}, {3, 7}}}, + {`[abhgefdc]ij`, nil, `hij`, []Group{{0, 3}}}, // Todo - add numeric range tests } @@ -294,10 +309,21 @@ var groupTests = []struct { {"(a?)a?", nil, "ab", []Match{[]Group{{0, 1}, {0, 1}}, []Group{{1, 1}, {1, 1}}, []Group{{2, 2}, {2, 2}}}}, {"(a?)a?", nil, "aa", []Match{[]Group{{0, 2}, {0, 1}}, []Group{{2, 2}, {2, 2}}}}, {"a((b.d){3})", nil, "abfdbhdbid", []Match{[]Group{{0, 10}, {1, 10}, {7, 10}}}}, + + // Test cases from Python's RE test suite {`(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)\071`, nil, `abcdefghijkl9`, []Match{[]Group{{0, 13}, {0, 1}, {1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6}, {6, 7}, {7, 8}, {8, 9}, {9, 10}, {10, 11}, {11, 12}}}}, {`()ef`, nil, `def`, []Match{[]Group{{1, 3}, {1, 1}}}}, {`(?:)ef`, nil, `def`, []Match{[]Group{{1, 3}}}}, {`(?:)`, nil, `def`, []Match{[]Group{{0, 0}}, []Group{{1, 1}}, []Group{{2, 2}}, []Group{{3, 3}}}}, + {`((a))`, nil, `abc`, []Match{[]Group{{0, 1}, {0, 1}, {0, 1}}}}, + {`(a)b(c)`, nil, `abc`, []Match{[]Group{{0, 3}, {0, 1}, {2, 3}}}}, + {`(a+|b)*`, nil, `ab`, []Match{[]Group{{0, 2}, {1, 2}}, []Group{{2, 2}}}}, + {`(a+|b)+`, nil, `ab`, []Match{[]Group{{0, 2}, {1, 2}}}}, + {`(a+|b)?`, nil, `ab`, []Match{[]Group{{0, 1}, {0, 1}}, []Group{{1, 2}, {1, 2}}, []Group{{2, 2}}}}, + {`(a|b|c|d|e)f`, nil, `ef`, []Match{[]Group{{0, 2}, {0, 1}}}}, + {`(ab|cd)e`, nil, `abcde`, []Match{[]Group{{2, 5}, {2, 4}}}}, + {`^(ab|cd)e`, nil, `abcde`, []Match{}}, + {`(abc|)ef`, nil, `abcdef`, []Match{[]Group{{4, 6}, {4, 4}}}}, } func TestFindAllMatches(t *testing.T) {