aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/json/decode_test.go
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2011-09-16 15:47:21 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2011-09-16 15:47:21 +0000
commitadb0401dac41c81571722312d4586b2693f95aa6 (patch)
treeea2b52e3c258d6b6d9356977c683c7f72a4a5fd5 /libgo/go/json/decode_test.go
parent5548ca3540bccbc908a45942896d635ea5f1c23f (diff)
downloadgcc-adb0401dac41c81571722312d4586b2693f95aa6.zip
gcc-adb0401dac41c81571722312d4586b2693f95aa6.tar.gz
gcc-adb0401dac41c81571722312d4586b2693f95aa6.tar.bz2
Update Go library to r60.
From-SVN: r178910
Diffstat (limited to 'libgo/go/json/decode_test.go')
-rw-r--r--libgo/go/json/decode_test.go34
1 files changed, 23 insertions, 11 deletions
diff --git a/libgo/go/json/decode_test.go b/libgo/go/json/decode_test.go
index bf8bf10..a855d60 100644
--- a/libgo/go/json/decode_test.go
+++ b/libgo/go/json/decode_test.go
@@ -34,18 +34,19 @@ func (u *unmarshaler) UnmarshalJSON(b []byte) os.Error {
return nil
}
+type ustruct struct {
+ M unmarshaler
+}
+
var (
um0, um1 unmarshaler // target2 of unmarshaling
ump = &um1
umtrue = unmarshaler{true}
+ umslice = []unmarshaler{unmarshaler{true}}
+ umslicep = new([]unmarshaler)
+ umstruct = ustruct{unmarshaler{true}}
)
-type badTag struct {
- X string
- Y string "y"
- Z string "@#*%(#@"
-}
-
type unmarshalTest struct {
in string
ptr interface{}
@@ -67,9 +68,6 @@ var unmarshalTests = []unmarshalTest{
{`{"X": [1,2,3], "Y": 4}`, new(T), T{Y: 4}, &UnmarshalTypeError{"array", reflect.TypeOf("")}},
{`{"x": 1}`, new(tx), tx{}, &UnmarshalFieldError{"x", txType, txType.Field(0)}},
- // skip invalid tags
- {`{"X":"a", "y":"b", "Z":"c"}`, new(badTag), badTag{"a", "b", "c"}, nil},
-
// syntax errors
{`{"X": "foo", "Y"}`, nil, nil, &SyntaxError{"invalid character '}' after object key", 17}},
@@ -86,6 +84,9 @@ var unmarshalTests = []unmarshalTest{
// unmarshal interface test
{`{"T":false}`, &um0, umtrue, nil}, // use "false" so test will fail if custom unmarshaler is not called
{`{"T":false}`, &ump, &umtrue, nil},
+ {`[{"T":false}]`, &umslice, umslice, nil},
+ {`[{"T":false}]`, &umslicep, &umslice, nil},
+ {`{"M":{"T":false}}`, &umstruct, umstruct, nil},
}
func TestMarshal(t *testing.T) {
@@ -149,7 +150,6 @@ func TestUnmarshal(t *testing.T) {
println(string(data))
data, _ = Marshal(tt.out)
println(string(data))
- return
continue
}
}
@@ -217,6 +217,18 @@ func TestUnmarshalPtrPtr(t *testing.T) {
}
}
+func TestEscape(t *testing.T) {
+ const input = `"foobar"<html>`
+ const expected = `"\"foobar\"\u003chtml\u003e"`
+ b, err := Marshal(input)
+ if err != nil {
+ t.Fatalf("Marshal error: %v", err)
+ }
+ if s := string(b); s != expected {
+ t.Errorf("Encoding of [%s] was [%s], want [%s]", input, s, expected)
+ }
+}
+
func TestHTMLEscape(t *testing.T) {
b, err := MarshalForHTML("foobarbaz<>&quux")
if err != nil {
@@ -250,7 +262,7 @@ type All struct {
Float32 float32
Float64 float64
- Foo string "bar"
+ Foo string `json:"bar"`
PBool *bool
PInt *int