mirror of
https://github.com/shopspring/decimal.git
synced 2024-11-22 20:40:48 +01:00
Test unhappy JSON and XML paths.
This commit is contained in:
parent
78186b90c0
commit
0fb3379e01
1 changed files with 36 additions and 0 deletions
|
@ -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) {
|
func TestXML(t *testing.T) {
|
||||||
for _, s := range testTable {
|
for _, s := range testTable {
|
||||||
var doc struct {
|
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) {
|
func TestDecimal_rescale(t *testing.T) {
|
||||||
type Inp struct {
|
type Inp struct {
|
||||||
int int64
|
int int64
|
||||||
|
|
Loading…
Reference in a new issue