(t *testing.T)
| 94 | } |
| 95 | |
| 96 | func 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 | |
| 134 | func testEncode(t *testing.T, tt testCase) { |
| 135 | t.Helper() |
nothing calls this directly
no test coverage detected