diff options
Diffstat (limited to 'flag_test.go')
| -rw-r--r-- | flag_test.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/flag_test.go b/flag_test.go index 411174a..e5469d7 100644 --- a/flag_test.go +++ b/flag_test.go @@ -5,6 +5,7 @@ package core_test import ( "flag" + "regexp" "strconv" "testing" @@ -204,6 +205,27 @@ func TestParseStringEnum(s *testing.T) { }) } +func TestParseStringRegexp(s *testing.T) { + t := &core.T{T: s} + parse := core.ParseStringRegexp(regexp.MustCompile("Hello( World!)?")) + + t.Run("Match", func(t *core.T) { + val, err := parse("Hello") + t.AssertErrorIs(nil, err) + t.AssertEqual("Hello", val) + + val, err = parse("Hello World!") + t.AssertErrorIs(nil, err) + t.AssertEqual("Hello World!", val) + }) + + t.Run("NoMatch", func(t *core.T) { + val, err := parse("something else") + t.AssertErrorIs(core.ErrStringRegexpNoMatch, err) + t.AssertEqual("", val) + }) +} + func TestParseStringerEnum(s *testing.T) { t := &core.T{T: s, Options: cmp.Options{fakeEnumComparer}} parser := core.ParseStringerEnum(fakeEnumFoo, fakeEnumBar) |
