Skip to content

Commit cab639a

Browse files
committed
chore: add test for decoding
1 parent 7747b41 commit cab639a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

mapper_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,3 +756,31 @@ func TestValuesThatLookLikeFlags(t *testing.T) {
756756
assert.NoError(t, err)
757757
assert.Equal(t, map[string]string{"-foo": "-bar"}, cli.Map)
758758
}
759+
760+
type DecodeCLI struct {
761+
Foo DecodeFoo `env:"FOO"`
762+
}
763+
764+
type DecodeFoo struct {
765+
Bar string
766+
}
767+
768+
func (f DecodeFoo) Decode(ctx *kong.DecodeContext) error {
769+
ctx.Value.Target.Set(reflect.ValueOf(struct {
770+
Bar string
771+
}{"baz"}))
772+
return nil
773+
}
774+
775+
func TestDecode(t *testing.T) {
776+
c := &DecodeCLI{}
777+
parser, err := kong.New(c)
778+
assert.NoError(t, err)
779+
780+
t.Setenv("FOO", "foo")
781+
782+
_, err = parser.Parse([]string{})
783+
assert.NoError(t, err)
784+
785+
assert.Equal(t, c.Foo.Bar, "baz")
786+
}

0 commit comments

Comments
 (0)