From 02bc8f30a2ed79da3e11e55528f96efcaee25061 Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Fri, 31 Jan 2025 10:52:27 -0500 Subject: [PATCH] Added test for 'Find' --- regex/re_test.go | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/regex/re_test.go b/regex/re_test.go index 9012c9f..48be8a3 100644 --- a/regex/re_test.go +++ b/regex/re_test.go @@ -673,7 +673,33 @@ var groupTests = []struct { {`(<389-400>)`, nil, `391`, []Match{[]Group{{0, 3}, {0, 3}}}}, } -func TestFindAllMatches(t *testing.T) { +func TestFind(t *testing.T) { + for _, test := range reTests { + t.Run(test.re+" "+test.str, func(t *testing.T) { + regComp, err := Compile(test.re, test.flags...) + if err != nil { + if test.result != nil { + panic(fmt.Errorf("Test Error: %v", err)) + } + } else { + groupIndex, err := regComp.Find(test.str) + if err != nil { // No matches found + if len(test.result) == 0 { + return // Manually pass the test, because this is the expected behavior + } else { + t.Errorf("Wanted no match Got %v\n", groupIndex) + } + } else { + if groupIndex != test.result[0] { + t.Errorf("Wanted %v Got %v\n", test.result, groupIndex) + } + } + } + }) + } +} + +func TestFindAll(t *testing.T) { for _, test := range reTests { t.Run(test.re+" "+test.str, func(t *testing.T) { regComp, err := Compile(test.re, test.flags...) @@ -716,7 +742,7 @@ func TestFindString(t *testing.T) { } } -func TestFindAllStrings(t *testing.T) { +func TestFindAllString(t *testing.T) { for _, test := range reTests { t.Run(test.re+" "+test.str, func(t *testing.T) { regComp, err := Compile(test.re, test.flags...) @@ -741,7 +767,7 @@ func TestFindAllStrings(t *testing.T) { } } -func TestFindAllGroups(t *testing.T) { +func TestFindAllSubmatch(t *testing.T) { for _, test := range groupTests { t.Run(test.re+" "+test.str, func(t *testing.T) { regComp, err := Compile(test.re, test.flags...)