Skip to content

Commit 730ac5a

Browse files
ngdinhtoanToanAtLZD
authored andcommitted
Add test for parse JSON tag.
1 parent db95112 commit 730ac5a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

decoder_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,3 +1451,25 @@ func TestDecoderExplicit(t *testing.T) {
14511451
Equal(t, test.Name, "Joeybloggs")
14521452
Equal(t, test.Age, 0)
14531453
}
1454+
1455+
func TestDecoderStructWithJSONTag(t *testing.T) {
1456+
type Test struct {
1457+
Name string `json:"name,omitempty"`
1458+
Age int `json:",omitempty"`
1459+
}
1460+
1461+
values := map[string][]string{
1462+
"name": {"Joeybloggs"},
1463+
"Age": {"3"},
1464+
}
1465+
1466+
var test Test
1467+
1468+
d := NewDecoder()
1469+
d.SetTagName("json")
1470+
1471+
err := d.Decode(&test, values)
1472+
Equal(t, err, nil)
1473+
Equal(t, test.Name, "Joeybloggs")
1474+
Equal(t, test.Age, int(3))
1475+
}

0 commit comments

Comments
 (0)