From 0367c0d61453de472b9aafafff6b5b9f1b345b88 Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Sun, 26 Jan 2025 10:24:29 -0500 Subject: [PATCH] Added more tests --- re_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/re_test.go b/re_test.go index 1b39d89..f012f5d 100644 --- a/re_test.go +++ b/re_test.go @@ -280,6 +280,13 @@ var reTests = []struct { {`ab*`, nil, `xabyabbbz`, []Group{{1, 3}, {4, 8}}}, {`ab*`, nil, `xayabbbz`, []Group{{1, 2}, {3, 7}}}, {`[abhgefdc]ij`, nil, `hij`, []Group{{0, 3}}}, + {`a[bcd]*dcdcde`, nil, `adcdcde`, []Group{{0, 7}}}, + {`a[bcd]+dcdcde`, nil, `adcdcde`, []Group{}}, + {`[a-zA-Z_][a-zA-Z0-9_]*`, nil, `alpha`, []Group{{0, 5}}}, + {`multiple words of text`, nil, `uh-uh`, []Group{}}, + {`multiple words`, nil, `multiple words, yeah`, []Group{{0, 14}}}, + {`[k]`, nil, `ab`, []Group{}}, + {`a[-]?c`, nil, `ac`, []Group{{0, 2}}}, // Todo - add numeric range tests } @@ -326,6 +333,21 @@ var groupTests = []struct { {`(abc|)ef`, nil, `abcdef`, []Match{[]Group{{4, 6}, {4, 4}}}}, {`(a|b)c*d`, nil, `abcd`, []Match{[]Group{{1, 4}, {1, 2}}}}, {`(ab|ab*)bc`, nil, `abc`, []Match{[]Group{{0, 3}, {0, 1}}}}, + {`a([bc]*)c*`, nil, `abc`, []Match{[]Group{{0, 3}, {1, 3}}}}, + {`a([bc]*)(c*d)`, nil, `abcd`, []Match{[]Group{{0, 4}, {1, 3}, {3, 4}}}}, + {`a([bc]+)(c*d)`, nil, `abcd`, []Match{[]Group{{0, 4}, {1, 3}, {3, 4}}}}, + {`a([bc]*)(c+d)`, nil, `abcd`, []Match{[]Group{{0, 4}, {1, 2}, {2, 4}}}}, + {`(ab|a)b*c`, nil, `abc`, []Match{[]Group{{0, 3}, {0, 2}}}}, + {`((a)(b)c)(d)`, nil, `abcd`, []Match{[]Group{{0, 4}, {0, 3}, {0, 1}, {1, 2}, {3, 4}}}}, + {`^a(bc+|b[eh])g|.h$`, nil, `abh`, []Match{[]Group{{1, 3}}}}, + {`(bc+d$|ef*g.|h?i(j|k))`, nil, `effgz`, []Match{[]Group{{0, 5}, {0, 5}}}}, + {`(bc+d$|ef*g.|h?i(j|k))`, nil, `ij`, []Match{[]Group{{0, 2}, {0, 2}, {1, 2}}}}, + {`(bc+d$|ef*g.|h?i(j|k))`, nil, `effg`, []Match{}}, + {`(bc+d$|ef*g.|h?i(j|k))`, nil, `bcdd`, []Match{}}, + {`(bc+d$|ef*g.|h?i(j|k))`, nil, `reffgz`, []Match{[]Group{{1, 6}, {1, 6}}}}, + {`(((((((((a)))))))))`, nil, `a`, []Match{[]Group{{0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}}}}, + {`(.*)c(.*)`, nil, `abcde`, []Match{[]Group{{0, 5}, {0, 2}, {3, 5}}}}, + {`\((.*), (.*)\)`, nil, `(a, b)`, []Match{[]Group{{0, 6}, {1, 2}, {4, 5}}}}, } func TestFindAllMatches(t *testing.T) {