aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/encoding/json/stream_test.go
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2019-09-12 23:22:53 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2019-09-12 23:22:53 +0000
commit656297e1fec9a127ff742df16958ee279ccacec5 (patch)
tree24347a35dacea36ce742c32c17420f3e31f17e3d /libgo/go/encoding/json/stream_test.go
parentd6ecb707cc5a58816d27908a7aa324c4b0bc67bb (diff)
downloadgcc-656297e1fec9a127ff742df16958ee279ccacec5.zip
gcc-656297e1fec9a127ff742df16958ee279ccacec5.tar.gz
gcc-656297e1fec9a127ff742df16958ee279ccacec5.tar.bz2
libgo: update to Go1.13
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/194698 From-SVN: r275691
Diffstat (limited to 'libgo/go/encoding/json/stream_test.go')
-rw-r--r--libgo/go/encoding/json/stream_test.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/libgo/go/encoding/json/stream_test.go b/libgo/go/encoding/json/stream_test.go
index 1d1999d..e3317dd 100644
--- a/libgo/go/encoding/json/stream_test.go
+++ b/libgo/go/encoding/json/stream_test.go
@@ -90,6 +90,18 @@ func TestEncoderIndent(t *testing.T) {
}
}
+type strMarshaler string
+
+func (s strMarshaler) MarshalJSON() ([]byte, error) {
+ return []byte(s), nil
+}
+
+type strPtrMarshaler string
+
+func (s *strPtrMarshaler) MarshalJSON() ([]byte, error) {
+ return []byte(*s), nil
+}
+
func TestEncoderSetEscapeHTML(t *testing.T) {
var c C
var ct CText
@@ -97,6 +109,15 @@ func TestEncoderSetEscapeHTML(t *testing.T) {
Valid int `json:"<>&#! "`
Invalid int `json:"\\"`
}
+
+ // This case is particularly interesting, as we force the encoder to
+ // take the address of the Ptr field to use its MarshalJSON method. This
+ // is why the '&' is important.
+ marshalerStruct := &struct {
+ NonPtr strMarshaler
+ Ptr strPtrMarshaler
+ }{`"<str>"`, `"<str>"`}
+
for _, tt := range []struct {
name string
v interface{}
@@ -111,6 +132,11 @@ func TestEncoderSetEscapeHTML(t *testing.T) {
`{"\u003c\u003e\u0026#! ":0,"Invalid":0}`,
`{"<>&#! ":0,"Invalid":0}`,
},
+ {
+ `"<str>"`, marshalerStruct,
+ `{"NonPtr":"\u003cstr\u003e","Ptr":"\u003cstr\u003e"}`,
+ `{"NonPtr":"<str>","Ptr":"<str>"}`,
+ },
} {
var buf bytes.Buffer
enc := NewEncoder(&buf)