summaryrefslogtreecommitdiff
path: root/decode_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'decode_test.go')
-rw-r--r--decode_test.go22
1 files changed, 20 insertions, 2 deletions
diff --git a/decode_test.go b/decode_test.go
index c224f3a..6d27347 100644
--- a/decode_test.go
+++ b/decode_test.go
@@ -82,16 +82,34 @@ func (o *testObj) DecodeJSON(r io.RuneScanner) error {
)
}
+type testStr string
+
+func (s *testStr) DecodeJSON(r io.RuneScanner) error {
+ var buf strings.Builder
+ if err := DecodeString(r, &buf); err != nil {
+ return err
+ }
+ *s = testStr(buf.String())
+ return nil
+}
+
+var (
+ _ Decodable = (*testAry)(nil)
+ _ Decodable = (*testObj)(nil)
+ _ Decodable = (*testStr)(nil)
+)
+
func TestDecodeTypeError(t *testing.T) {
t.Parallel()
type outType struct {
First int
Second testAry
Third testObj
+ Fourth testStr
}
var out outType
- err := NewDecoder(strings.NewReader(`{"First": 1.2, "Second": [3], "Third": {"a":4}}`)).Decode(&out)
+ err := NewDecoder(strings.NewReader(`{"First": 1.2, "Second": [3], "Third": {"a":4}, "Fourth": "foo\u000Abar"}`)).Decode(&out)
assert.EqualError(t, err,
`json: v["First"]: cannot decode JSON number 1.2 at input byte 9 into Go int: strconv.ParseInt: parsing "1.2": invalid syntax`)
- assert.Equal(t, outType{First: 0, Second: testAry{3}, Third: testObj{"a": 4}}, out)
+ assert.Equal(t, outType{First: 0, Second: testAry{3}, Third: testObj{"a": 4}, Fourth: "foo\nbar"}, out)
}