mirror of
https://github.com/shopspring/decimal.git
synced 2024-11-22 12:30:49 +01:00
Add XML test.
This commit is contained in:
parent
a2664e0073
commit
c6c99f4daa
1 changed files with 26 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue