Add XML test.

This commit is contained in:
Casey Marshall 2015-03-23 17:14:19 -05:00
parent a2664e0073
commit c6c99f4daa

View file

@ -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 := `<account><amount>` + s + `</amount></account>`
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