This commit is contained in:
Kevin Wan
2023-08-14 22:22:22 +08:00
committed by GitHub
parent 45fbd7dc35
commit cb3ffc76a3
4 changed files with 75 additions and 8 deletions

View File

@@ -5092,6 +5092,21 @@ func TestUnmarshalFromStringSliceForTypeMismatch(t *testing.T) {
}, &v))
}
func TestUnmarshalWithOpaqueKeys(t *testing.T) {
var v struct {
Opaque string `key:"opaque.key"`
Value string `key:"value"`
}
unmarshaler := NewUnmarshaler("key", WithOpaqueKeys())
if assert.NoError(t, unmarshaler.Unmarshal(map[string]any{
"opaque.key": "foo",
"value": "bar",
}, &v)) {
assert.Equal(t, "foo", v.Opaque)
assert.Equal(t, "bar", v.Value)
}
}
func BenchmarkDefaultValue(b *testing.B) {
for i := 0; i < b.N; i++ {
var a struct {