Test unhappy JSON and XML paths.

This commit is contained in:
Casey Marshall 2015-03-23 19:39:37 -05:00
parent 78186b90c0
commit 0fb3379e01

View file

@ -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", "<abc", "<account><amount>7",
`<html><body></body></html>`,
`<account><amount></amount></account>`,
`<account><amount>nope</amount></account>`,
`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