diff --git a/decimal_test.go b/decimal_test.go index a34c7db..7d9bbae 100644 --- a/decimal_test.go +++ b/decimal_test.go @@ -173,6 +173,23 @@ func TestJSON(t *testing.T) { } } +func TestBadJSON(t *testing.T) { + for _, testCase := range []string{ + "]o_o[", "{", `{"amount":""`, + `{"amount":""}`, + `{"amount":"nope"}`, + `0.333`, + } { + var doc struct { + Amount Decimal `json:"amount"` + } + err := json.Unmarshal([]byte(testCase), &doc) + if err == nil { + t.Errorf("expected error, got %+v", doc) + } + } +} + func TestXML(t *testing.T) { for _, s := range testTable { var doc struct { @@ -198,6 +215,25 @@ func TestXML(t *testing.T) { } } +func TestBadXML(t *testing.T) { + for _, testCase := range []string{ + "o_o", "7", + ``, + ``, + `nope`, + `0.333`, + } { + var doc struct { + XMLName xml.Name `xml:"account"` + Amount Decimal `xml:"amount"` + } + err := xml.Unmarshal([]byte(testCase), &doc) + if err == nil { + t.Errorf("expected error, got %+v", doc) + } + } +} + func TestDecimal_rescale(t *testing.T) { type Inp struct { int int64