LEFT | RIGHT |
1 // Copyright 2010 The Go Authors. All rights reserved. | 1 // Copyright 2010 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package json | 5 package json |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "fmt" | 9 "fmt" |
10 "image" | 10 "image" |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 type S13 struct { | 168 type S13 struct { |
169 S8 | 169 S8 |
170 } | 170 } |
171 | 171 |
172 type unmarshalTest struct { | 172 type unmarshalTest struct { |
173 in string | 173 in string |
174 ptr interface{} | 174 ptr interface{} |
175 out interface{} | 175 out interface{} |
176 err error | 176 err error |
177 useNumber bool | 177 useNumber bool |
| 178 } |
| 179 |
| 180 type Ambig struct { |
| 181 // Given "hello", the first match should win. |
| 182 First int `json:"HELLO"` |
| 183 Second int `json:"Hello"` |
178 } | 184 } |
179 | 185 |
180 var unmarshalTests = []unmarshalTest{ | 186 var unmarshalTests = []unmarshalTest{ |
181 // basic types | 187 // basic types |
182 {in: `true`, ptr: new(bool), out: true}, | 188 {in: `true`, ptr: new(bool), out: true}, |
183 {in: `1`, ptr: new(int), out: 1}, | 189 {in: `1`, ptr: new(int), out: 1}, |
184 {in: `1.2`, ptr: new(float64), out: 1.2}, | 190 {in: `1.2`, ptr: new(float64), out: 1.2}, |
185 {in: `-5`, ptr: new(int16), out: int16(-5)}, | 191 {in: `-5`, ptr: new(int16), out: int16(-5)}, |
186 {in: `2`, ptr: new(Number), out: Number("2"), useNumber: true}, | 192 {in: `2`, ptr: new(Number), out: Number("2"), useNumber: true}, |
187 {in: `2`, ptr: new(Number), out: Number("2")}, | 193 {in: `2`, ptr: new(Number), out: Number("2")}, |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 Loop2: 14, | 283 Loop2: 14, |
278 }, | 284 }, |
279 Embed0p: Embed0p{ | 285 Embed0p: Embed0p{ |
280 Point: image.Point{X: 15, Y: 16}, | 286 Point: image.Point{X: 15, Y: 16}, |
281 }, | 287 }, |
282 Embed0q: Embed0q{ | 288 Embed0q: Embed0q{ |
283 Point: Point{Z: 17}, | 289 Point: Point{Z: 17}, |
284 }, | 290 }, |
285 }, | 291 }, |
286 }, | 292 }, |
| 293 { |
| 294 in: `{"hello": 1}`, |
| 295 ptr: new(Ambig), |
| 296 out: Ambig{First: 1}, |
| 297 }, |
287 | 298 |
288 { | 299 { |
289 in: `{"X": 1,"Y":2}`, | 300 in: `{"X": 1,"Y":2}`, |
290 ptr: new(S5), | 301 ptr: new(S5), |
291 out: S5{S8: S8{S9: S9{Y: 2}}}, | 302 out: S5{S8: S8{S9: S9{Y: 2}}}, |
292 }, | 303 }, |
293 { | 304 { |
294 in: `{"X": 1,"Y":2}`, | 305 in: `{"X": 1,"Y":2}`, |
295 ptr: new(S10), | 306 ptr: new(S10), |
296 out: S10{S13: S13{S8: S8{S9: S9{Y: 2}}}}, | 307 out: S10{S13: S13{S8: S8{S9: S9{Y: 2}}}}, |
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
935 blob := `{"X":` + tt.json + `}` | 946 blob := `{"X":` + tt.json + `}` |
936 if err := Unmarshal([]byte(blob), &b); err != nil { | 947 if err := Unmarshal([]byte(blob), &b); err != nil { |
937 t.Errorf("Unmarshal %#q: %v", blob, err) | 948 t.Errorf("Unmarshal %#q: %v", blob, err) |
938 continue | 949 continue |
939 } | 950 } |
940 if !reflect.DeepEqual(b.X, tt.post) { | 951 if !reflect.DeepEqual(b.X, tt.post) { |
941 t.Errorf("Unmarshal %#q into %#v: X=%#v, want %#v", blob
, tt.pre, b.X, tt.post) | 952 t.Errorf("Unmarshal %#q into %#v: X=%#v, want %#v", blob
, tt.pre, b.X, tt.post) |
942 } | 953 } |
943 } | 954 } |
944 } | 955 } |
LEFT | RIGHT |