From 2a9ae0b68aa8b387b188c5be5c99c5bd0c893989 Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Sat, 1 Feb 2025 11:09:05 -0500 Subject: [PATCH] Wrote test for 'FindSubmatch' --- regex/re_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/regex/re_test.go b/regex/re_test.go index ce2ed69..1ce9136 100644 --- a/regex/re_test.go +++ b/regex/re_test.go @@ -767,6 +767,26 @@ func TestFindAllString(t *testing.T) { } } +func TestFindSubmatch(t *testing.T) { + for _, test := range groupTests { + 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(err) + } + } + match, err := regComp.FindSubmatch(test.str) + for i := range match { + if match[i].IsValid() { + if test.result[0][i] != match[i] { + t.Errorf("Wanted %v Got %v\n", test.result[0], match) + } + } + } + }) + } +} func TestFindAllSubmatch(t *testing.T) { for _, test := range groupTests { t.Run(test.re+" "+test.str, func(t *testing.T) {