Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(500)

Side by Side Diff: src/pkg/json/decode_test.go

Issue 4301043: update tree for reflect changes (Closed)
Patch Set: diff -r f692a5e90f6f https://go.googlecode.com/hg/ Created 13 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pkg/json/decode.go ('k') | src/pkg/json/encode.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "os" 9 "os"
10 "reflect" 10 "reflect"
11 "strings" 11 "strings"
12 "testing" 12 "testing"
13 ) 13 )
14 14
15 type T struct { 15 type T struct {
16 X string 16 X string
17 Y int 17 Y int
18 } 18 }
19 19
20 type tx struct { 20 type tx struct {
21 x int 21 x int
22 } 22 }
23 23
24 var txType = reflect.Typeof((*tx)(nil)).(*reflect.PtrType).Elem().(*reflect.Stru ctType) 24 var txType = reflect.Typeof((*tx)(nil)).Elem()
25 25
26 // A type that can unmarshal itself. 26 // A type that can unmarshal itself.
27 27
28 type unmarshaler struct { 28 type unmarshaler struct {
29 T bool 29 T bool
30 } 30 }
31 31
32 func (u *unmarshaler) UnmarshalJSON(b []byte) os.Error { 32 func (u *unmarshaler) UnmarshalJSON(b []byte) os.Error {
33 *u = unmarshaler{true} // All we need to see that UnmarshalJson is calle d. 33 *u = unmarshaler{true} // All we need to see that UnmarshalJson is calle d.
34 return nil 34 return nil
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 if !reflect.DeepEqual(err, tt.err) { 132 if !reflect.DeepEqual(err, tt.err) {
133 t.Errorf("#%d: checkValid: %v", i, err) 133 t.Errorf("#%d: checkValid: %v", i, err)
134 continue 134 continue
135 } 135 }
136 } 136 }
137 if tt.ptr == nil { 137 if tt.ptr == nil {
138 continue 138 continue
139 } 139 }
140 // v = new(right-type) 140 // v = new(right-type)
141 v := reflect.NewValue(tt.ptr).(*reflect.PtrValue) 141 v := reflect.NewValue(tt.ptr).(*reflect.PtrValue)
142 » » v.PointTo(reflect.MakeZero(v.Type().(*reflect.PtrType).Elem())) 142 » » v.PointTo(reflect.MakeZero(v.Type().Elem()))
143 if err := Unmarshal([]byte(in), v.Interface()); !reflect.DeepEqu al(err, tt.err) { 143 if err := Unmarshal([]byte(in), v.Interface()); !reflect.DeepEqu al(err, tt.err) {
144 t.Errorf("#%d: %v want %v", i, err, tt.err) 144 t.Errorf("#%d: %v want %v", i, err, tt.err)
145 continue 145 continue
146 } 146 }
147 if !reflect.DeepEqual(v.Elem().Interface(), tt.out) { 147 if !reflect.DeepEqual(v.Elem().Interface(), tt.out) {
148 t.Errorf("#%d: mismatch\nhave: %#+v\nwant: %#+v", i, v.E lem().Interface(), tt.out) 148 t.Errorf("#%d: mismatch\nhave: %#+v\nwant: %#+v", i, v.E lem().Interface(), tt.out)
149 data, _ := Marshal(v.Elem().Interface()) 149 data, _ := Marshal(v.Elem().Interface())
150 println(string(data)) 150 println(string(data))
151 data, _ = Marshal(tt.out) 151 data, _ = Marshal(tt.out)
152 println(string(data)) 152 println(string(data))
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 }, 531 },
532 "PSmall": null, 532 "PSmall": null,
533 "PPSmall": { 533 "PPSmall": {
534 "Tag": "tag31" 534 "Tag": "tag31"
535 }, 535 },
536 "Interface": null, 536 "Interface": null,
537 "PInterface": 5.2 537 "PInterface": 5.2
538 }` 538 }`
539 539
540 var pallValueCompact = strings.Map(noSpace, pallValueIndent) 540 var pallValueCompact = strings.Map(noSpace, pallValueIndent)
OLDNEW
« no previous file with comments | « src/pkg/json/decode.go ('k') | src/pkg/json/encode.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b