aboutsummaryrefslogtreecommitdiff
path: root/flag_test.go
diff options
context:
space:
mode:
authorGrégoire Duchêne <gduchene@awhk.org>2023-02-26 13:12:55 +0000
committerGrégoire Duchêne <gduchene@awhk.org>2023-02-26 13:12:55 +0000
commit1ccf64c35e6cd5b335f8b230844712b6fb026dca (patch)
treef01e7d0885ea21a7cdca0714cd863bfde60e5064 /flag_test.go
parent7819ffd61f780eded638be342b469a57596a15fe (diff)
Parameterize UnknownEnumValueError
Also, do not sort the expected values in UnknownEnumValueError.Error.
Diffstat (limited to 'flag_test.go')
-rw-r--r--flag_test.go13
1 files changed, 6 insertions, 7 deletions
diff --git a/flag_test.go b/flag_test.go
index 5b0df0e..3273775 100644
--- a/flag_test.go
+++ b/flag_test.go
@@ -5,10 +5,11 @@ package core_test
import (
"flag"
- "sort"
"strconv"
"testing"
+ "github.com/google/go-cmp/cmp"
+
"go.awhk.org/core"
)
@@ -144,7 +145,7 @@ func TestInitFlagSet(s *testing.T) {
}
func TestParseProtobufEnum(s *testing.T) {
- t := &core.T{T: s}
+ t := &core.T{T: s, Options: cmp.Options{sortStrings}}
// That type and map emulate code generated by protoc.
type fakeEnum int32
@@ -169,10 +170,9 @@ func TestParseProtobufEnum(s *testing.T) {
t.Run("UnknownValue", func(t *core.T) {
val, err := parse("BAZ")
- var exp core.UnknownEnumValueError
+ var exp core.UnknownEnumValueError[string]
if t.AssertErrorAs(&exp, err) {
t.AssertEqual("BAZ", exp.Actual)
- sort.Strings(exp.Expected)
t.AssertEqual([]string{"BAR", "FAKE_UNKNOWN", "FOO"}, exp.Expected)
}
t.AssertEqual(fakeEnum(0), val)
@@ -195,11 +195,10 @@ func TestParseStringEnum(s *testing.T) {
t.Run("UnknownValue", func(t *core.T) {
val, err := parse("baz")
- var exp core.UnknownEnumValueError
+ var exp core.UnknownEnumValueError[string]
if t.AssertErrorAs(&exp, err) {
t.AssertEqual("baz", exp.Actual)
- sort.Strings(exp.Expected)
- t.AssertEqual([]string{"bar", "foo"}, exp.Expected)
+ t.AssertEqual([]string{"foo", "bar"}, exp.Expected)
}
t.AssertEqual("", val)
})