diff --git a/decimal_test.go b/decimal_test.go index c590d0d..f073031 100644 --- a/decimal_test.go +++ b/decimal_test.go @@ -2,6 +2,7 @@ package decimal import ( "encoding/json" + "encoding/xml" "math" "testing" ) @@ -172,6 +173,31 @@ func TestJSON(t *testing.T) { } } +func TestXML(t *testing.T) { + for _, s := range testTable { + var doc struct { + XMLName xml.Name `xml:"account"` + Amount Decimal `xml:"amount"` + } + docStr := `` + s + `` + err := xml.Unmarshal([]byte(docStr), &doc) + if err != nil { + t.Errorf("error unmarshaling %s: %v", docStr, err) + } else if doc.Amount.String() != s { + t.Errorf("expected %s, got %s (%s, %d)", + s, doc.Amount.String(), + doc.Amount.value.String(), doc.Amount.exp) + } + + out, err := xml.Marshal(&doc) + if err != nil { + t.Errorf("error marshaling %+v: %v", doc, err) + } else if string(out) != docStr { + t.Errorf("expected %s, got %s", docStr, string(out)) + } + } +} + func TestDecimal_rescale(t *testing.T) { type Inp struct { int int64