From ff250338b49460be03ba1268da0515f8d965fa73 Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Sun, 26 Jan 2025 22:18:34 -0500 Subject: [PATCH] Added more tests; added backreference comment --- re_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/re_test.go b/re_test.go index f012f5d..d77265a 100644 --- a/re_test.go +++ b/re_test.go @@ -287,6 +287,11 @@ var reTests = []struct { {`multiple words`, nil, `multiple words, yeah`, []Group{{0, 14}}}, {`[k]`, nil, `ab`, []Group{}}, {`a[-]?c`, nil, `ac`, []Group{{0, 2}}}, + {`^(.+)?B`, nil, `AB`, []Group{{0, 2}}}, + + // At this point, the python test suite has a bunch + // of backreference tests. Since my engine doesn't + // implement backreferences, I've skipped those tests. // Todo - add numeric range tests } @@ -348,6 +353,22 @@ var groupTests = []struct { {`(((((((((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}}}}, + + // At this point, the python test suite has a bunch + // of backreference tests. Since my engine doesn't + // implement backreferences, I've skipped those tests. + + {`(a)(b)c|ab`, nil, `ab`, []Match{[]Group{{0, 2}}}}, + {`(a)+x`, nil, `aaax`, []Match{[]Group{{0, 4}, {2, 3}}}}, + {`([ac])+x`, nil, `aacx`, []Match{[]Group{{0, 4}, {2, 3}}}}, + {`([^/]*/)*sub1/`, nil, `d:msgs/tdir/sub1/trial/away.cpp`, []Match{[]Group{{0, 17}, {7, 12}}}}, + {`([^.]*)\.([^:]*):[T ]+(.*)`, nil, `track1.title:TBlah blah blah`, []Match{[]Group{{0, 28}, {0, 6}, {7, 12}, {14, 28}}}}, + {`([^N]*N)+`, nil, `abNNxyzN`, []Match{[]Group{{0, 8}, {4, 8}}}}, + {`([^N]*N)+`, nil, `abNNxyz`, []Match{[]Group{{0, 4}, {3, 4}}}}, + {`([abc]*)x`, nil, `abcx`, []Match{[]Group{{0, 4}, {0, 3}}}}, + {`([abc]*)x`, nil, `abc`, []Match{}}, + {`([xyz]*)x`, nil, `abcx`, []Match{[]Group{{3, 4}, {3, 3}}}}, + {`(a)+b|aac`, nil, `aac`, []Match{[]Group{{0, 3}}}}, } func TestFindAllMatches(t *testing.T) {