MCPcopy
hub / github.com/tinylib/msgp / TestJSONNumber

Function TestJSONNumber

_generated/def_test.go:79–181  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

77}
78
79func TestJSONNumber(t *testing.T) {
80 test := NumberJSONSample{
81 Single: "-42",
82 Array: []json.Number{"0", "-0", "1", "-1", "0.1", "-0.1", "1234", "-1234", "12.34", "-12.34", "12E0", "12E1", "12e34", "12E-0", "12e+1", "12e-34", "-12E0", "-12E1", "-12e34", "-12E-0", "-12e+1", "-12e-34", "1.2E0", "1.2E1", "1.2e34", "1.2E-0", "1.2e+1", "1.2e-34", "-1.2E0", "-1.2E1", "-1.2e34", "-1.2E-0", "-1.2e+1", "-1.2e-34", "0E0", "0E1", "0e34", "0E-0", "0e+1", "0e-34", "-0E0", "-0E1", "-0e34", "-0E-0", "-0e+1", "-0e-34"},
83 Map: map[string]json.Number{
84 "a": json.Number("50.2"),
85 },
86 }
87
88 // This is not guaranteed to be symmetric
89 encoded, err := test.MarshalMsg(nil)
90 if err != nil {
91 t.Errorf("%v", err)
92 }
93 var v NumberJSONSample
94 _, err = v.UnmarshalMsg(encoded)
95 if err != nil {
96 t.Errorf("%v", err)
97 }
98 // Test two values
99 if v.Single != "-42" {
100 t.Errorf("want %v, got %v", "-42", v.Single)
101 }
102 if v.Map["a"] != "50.2" {
103 t.Errorf("want %v, got %v", "50.2", v.Map["a"])
104 }
105
106 var jsBuf bytes.Buffer
107 remain, err := msgp.UnmarshalAsJSON(&jsBuf, encoded)
108 if err != nil {
109 t.Errorf("%v", err)
110 }
111 if len(remain) != 0 {
112 t.Errorf("remain should be empty")
113 }
114 wantjs := `{"Single":-42,"Array":[0,0,1,-1,0.1,-0.1,1234,-1234,12.34,-12.34,12,120,120000000000000000000000000000000000,12,120,0.0000000000000000000000000000000012,-12,-120,-120000000000000000000000000000000000,-12,-120,-0.0000000000000000000000000000000012,1.2,12,12000000000000000000000000000000000,1.2,12,0.00000000000000000000000000000000012,-1.2,-12,-12000000000000000000000000000000000,-1.2,-12,-0.00000000000000000000000000000000012,0,0,0,0,0,0,-0,-0,-0,-0,-0,-0],"Map":{"a":50.2}}`
115 if jsBuf.String() != wantjs {
116 t.Errorf("jsBuf.String() = \n%s, want \n%s", jsBuf.String(), wantjs)
117 }
118 // Test encoding
119 var buf bytes.Buffer
120 en := msgp.NewWriter(&buf)
121 err = test.EncodeMsg(en)
122 if err != nil {
123 t.Errorf("%v", err)
124 }
125 en.Flush()
126 encoded = buf.Bytes()
127
128 dc := msgp.NewReader(&buf)
129 err = v.DecodeMsg(dc)
130 if err != nil {
131 t.Errorf("%v", err)
132 }
133 // Test two values
134 if v.Single != "-42" {
135 t.Errorf("want %s, got %s", "-42", v.Single)
136 }

Callers

nothing calls this directly

Calls 11

FlushMethod · 0.95
UnmarshalAsJSONFunction · 0.92
NewWriterFunction · 0.92
NewReaderFunction · 0.92
AppendIntfFunction · 0.92
MarshalMsgMethod · 0.65
UnmarshalMsgMethod · 0.65
StringMethod · 0.65
EncodeMsgMethod · 0.65
DecodeMsgMethod · 0.65
ResetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…