MCPcopy Create free account
hub / github.com/aws/smithy-go / TestDocumentNumberEncodesAsNumber

Function TestDocumentNumberEncodesAsNumber

document/json/encoder_test.go:96–132  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

94}
95
96func TestDocumentNumberEncodesAsNumber(t *testing.T) {
97 encoder := json.NewEncoder()
98
99 cases := map[string]struct {
100 input interface{}
101 expected string
102 }{
103 "integer": {
104 input: map[string]interface{}{"x": document.Number("42")},
105 expected: `{"x":42}`,
106 },
107 "float": {
108 input: map[string]interface{}{"x": document.Number("42.0")},
109 expected: `{"x":42.0}`,
110 },
111 "negative zero": {
112 input: map[string]interface{}{"x": document.Number("-0.0")},
113 expected: `{"x":-0.0}`,
114 },
115 "scientific notation": {
116 input: map[string]interface{}{"x": document.Number("1.5e+10")},
117 expected: `{"x":1.5e+10}`,
118 },
119 }
120
121 for name, tc := range cases {
122 t.Run(name, func(t *testing.T) {
123 b, err := encoder.Encode(tc.input)
124 if err != nil {
125 t.Fatalf("Encode() error: %v", err)
126 }
127 if string(b) != tc.expected {
128 t.Errorf("Encode() = %s, want %s", b, tc.expected)
129 }
130 })
131 }
132}
133
134func testEncode(t *testing.T, tt testCase) {
135 t.Helper()

Callers

nothing calls this directly

Calls 4

EncodeMethod · 0.95
NewEncoderFunction · 0.92
NumberTypeAlias · 0.92
ErrorfMethod · 0.80

Tested by

no test coverage detected