diff options
| author | Alex Flint <[email protected]> | 2021-04-19 13:21:04 -0700 |
|---|---|---|
| committer | Alex Flint <[email protected]> | 2021-04-19 13:21:04 -0700 |
| commit | 9949860eb3d60d374df3a47ebc0a22ca55bba399 (patch) | |
| tree | 7249f91dec445c4403c715eb4747754452d808bc /parse_test.go | |
| parent | 23b96d7aacf62828675decc309eae5b9dce5bd51 (diff) | |
change "kind" to "cardinality", add support for maps to parser
Diffstat (limited to 'parse_test.go')
| -rw-r--r-- | parse_test.go | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/parse_test.go b/parse_test.go index 0decfc1..6ee3541 100644 --- a/parse_test.go +++ b/parse_test.go @@ -220,6 +220,14 @@ func TestLongFlag(t *testing.T) { assert.Equal(t, "xyz", args.Foo) } +func TestSlice(t *testing.T) { + var args struct { + Strings []string + } + err := parse("--strings a b c", &args) + require.NoError(t, err) + assert.Equal(t, []string{"a", "b", "c"}, args.Strings) +} func TestSliceOfBools(t *testing.T) { var args struct { B []bool @@ -230,6 +238,18 @@ func TestSliceOfBools(t *testing.T) { assert.Equal(t, []bool{true, false, true}, args.B) } +func TestMap(t *testing.T) { + var args struct { + Values map[string]int + } + err := parse("--values a=1 b=2 c=3", &args) + require.NoError(t, err) + assert.Len(t, args.Values, 3) + assert.Equal(t, 1, args.Values["a"]) + assert.Equal(t, 2, args.Values["b"]) + assert.Equal(t, 3, args.Values["c"]) +} + func TestPlaceholder(t *testing.T) { var args struct { Input string `arg:"positional" placeholder:"SRC"` @@ -1233,7 +1253,7 @@ func TestDefaultValuesNotAllowedWithSlice(t *testing.T) { } err := parse("", &args) - assert.EqualError(t, err, ".A: default values are not supported for slice fields") + assert.EqualError(t, err, ".A: default values are not supported for slice or map fields") } func TestUnexportedFieldsSkipped(t *testing.T) { |
