MCPcopy Create free account
hub / github.com/cockroachdb/apd / TestJSONEncoding

Function TestJSONEncoding

decimal_test.go:928–966  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

926}
927
928func TestJSONEncoding(t *testing.T) {
929 var encodingTests = []string{
930 "0",
931 "1",
932 "2",
933 "10",
934 "1000",
935 "1234567890",
936 "298472983472983471903246121093472394872319615612417471234712061",
937 "0.0",
938 "NaN",
939 "Inf",
940 "123.456",
941 "1E1",
942 "1E-1",
943 "1.2E3",
944 }
945
946 for _, test := range encodingTests {
947 for _, sign := range []string{"", "+", "-"} {
948 x := sign + test
949 var tx Decimal
950 tx.SetString(x)
951 b, err := json.Marshal(&tx)
952 if err != nil {
953 t.Errorf("marshaling of %s failed: %s", &tx, err)
954 continue
955 }
956 var rx Decimal
957 if err := json.Unmarshal(b, &rx); err != nil {
958 t.Errorf("unmarshaling of %s failed: %s", &tx, err)
959 continue
960 }
961 if rx.CmpTotal(&tx) != 0 {
962 t.Errorf("JSON encoding of %s failed: got %s want %s", &tx, &rx, &tx)
963 }
964 }
965 }
966}
967
968// TestNewFromStringInvalid tests that NewFromString produces
969// an error when parsing an invalid decimal.

Callers

nothing calls this directly

Calls 2

SetStringMethod · 0.95
CmpTotalMethod · 0.95

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…