(t *testing.T)
| 643 | } |
| 644 | |
| 645 | func TestJSON(t *testing.T) { |
| 646 | for _, x := range testTable { |
| 647 | s := x.short |
| 648 | var doc struct { |
| 649 | Amount Decimal `json:"amount"` |
| 650 | } |
| 651 | docStr := `{"amount":"` + s + `"}` |
| 652 | docStrNumber := `{"amount":` + s + `}` |
| 653 | err := json.Unmarshal([]byte(docStr), &doc) |
| 654 | if err != nil { |
| 655 | t.Errorf("error unmarshaling %s: %v", docStr, err) |
| 656 | } else if doc.Amount.String() != s { |
| 657 | t.Errorf("expected %s, got %s (%s, %d)", |
| 658 | s, doc.Amount.String(), |
| 659 | doc.Amount.value.String(), doc.Amount.exp) |
| 660 | } |
| 661 | |
| 662 | out, err := json.Marshal(&doc) |
| 663 | if err != nil { |
| 664 | t.Errorf("error marshaling %+v: %v", doc, err) |
| 665 | } else if string(out) != docStr { |
| 666 | t.Errorf("expected %s, got %s", docStr, string(out)) |
| 667 | } |
| 668 | |
| 669 | // make sure unquoted marshalling works too |
| 670 | MarshalJSONWithoutQuotes = true |
| 671 | out, err = json.Marshal(&doc) |
| 672 | if err != nil { |
| 673 | t.Errorf("error marshaling %+v: %v", doc, err) |
| 674 | } else if string(out) != docStrNumber { |
| 675 | t.Errorf("expected %s, got %s", docStrNumber, string(out)) |
| 676 | } |
| 677 | MarshalJSONWithoutQuotes = false |
| 678 | } |
| 679 | } |
| 680 | |
| 681 | func TestUnmarshalJSONNull(t *testing.T) { |
| 682 | var doc struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…