From fb46ed62d968fbc1d9b030c3526aa095cfa801ba Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Sun, 19 Jan 2025 22:56:47 -0500 Subject: [PATCH] Added tests for FindString --- re_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/re_test.go b/re_test.go index 7881925..afebc2f 100644 --- a/re_test.go +++ b/re_test.go @@ -204,6 +204,28 @@ func TestFindAllMatches(t *testing.T) { } } +func TestFindString(t *testing.T) { + for _, test := range reTests { + t.Run(test.re+" "+test.str, func(t *testing.T) { + regComp, err := Compile(test.re) + if err != nil { + panic(err) + } + foundString := FindString(regComp, test.str) + if len(test.result) == 0 { + if foundString != "" { + t.Errorf("Expected no match got %v\n", foundString) + } + } else { + expectedString := test.str[test.result[0].startIdx:test.result[0].endIdx] + if foundString != foundString { + t.Errorf("Wanted %v Got %v\n", expectedString, foundString) + } + } + }) + } +} + func TestFindAllGroups(t *testing.T) { for _, test := range groupTests { t.Run(test.re+" "+test.str, func(t *testing.T) {