forked from mirror/go-json
Add compatible test
This commit is contained in:
parent
e6e5fe665c
commit
30ab976eb4
|
@ -1,5 +1,10 @@
|
|||
package json_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
stdjson "encoding/json"
|
||||
)
|
||||
|
||||
func intptr(v int) *int { return &v }
|
||||
func int8ptr(v int8) *int8 { return &v }
|
||||
func int16ptr(v int16) *int16 { return &v }
|
||||
|
@ -13,3 +18,14 @@ func uint64ptr(v uint64) *uint64 { return &v }
|
|||
func float32ptr(v float32) *float32 { return &v }
|
||||
func float64ptr(v float64) *float64 { return &v }
|
||||
func stringptr(v string) *string { return &v }
|
||||
|
||||
func encodeByEncodingJSON(data interface{}, indent, escape bool) string {
|
||||
var buf bytes.Buffer
|
||||
enc := stdjson.NewEncoder(&buf)
|
||||
enc.SetEscapeHTML(escape)
|
||||
if indent {
|
||||
enc.SetIndent("", " ")
|
||||
}
|
||||
enc.Encode(data)
|
||||
return buf.String()
|
||||
}
|
||||
|
|
|
@ -2922,6 +2922,10 @@ null
|
|||
if err := enc.Encode(test.data); err != nil {
|
||||
t.Fatalf("%s(htmlEscape:%T): %s: %s", test.name, htmlEscape, test.expected, err)
|
||||
}
|
||||
stdresult := encodeByEncodingJSON(test.data, indent, htmlEscape)
|
||||
if buf.String() != stdresult {
|
||||
t.Errorf("%s(htmlEscape:%T): doesn't compatible with encoding/json. expected %q but got %q", test.name, htmlEscape, stdresult, buf.String())
|
||||
}
|
||||
if indent {
|
||||
got := "\n" + buf.String()
|
||||
if got != test.indentExpected {
|
||||
|
|
|
@ -2922,6 +2922,10 @@ null
|
|||
if err := enc.Encode(test.data); err != nil {
|
||||
t.Fatalf("%s(htmlEscape:%T): %s: %s", test.name, htmlEscape, test.expected, err)
|
||||
}
|
||||
stdresult := encodeByEncodingJSON(test.data, indent, htmlEscape)
|
||||
if buf.String() != stdresult {
|
||||
t.Errorf("%s(htmlEscape:%T): doesn't compatible with encoding/json. expected %q but got %q", test.name, htmlEscape, stdresult, buf.String())
|
||||
}
|
||||
if indent {
|
||||
got := "\n" + buf.String()
|
||||
if got != test.indentExpected {
|
||||
|
|
|
@ -2922,6 +2922,10 @@ null
|
|||
if err := enc.Encode(test.data); err != nil {
|
||||
t.Fatalf("%s(htmlEscape:%T): %s: %s", test.name, htmlEscape, test.expected, err)
|
||||
}
|
||||
stdresult := encodeByEncodingJSON(test.data, indent, htmlEscape)
|
||||
if buf.String() != stdresult {
|
||||
t.Errorf("%s(htmlEscape:%T): doesn't compatible with encoding/json. expected %q but got %q", test.name, htmlEscape, stdresult, buf.String())
|
||||
}
|
||||
if indent {
|
||||
got := "\n" + buf.String()
|
||||
if got != test.indentExpected {
|
||||
|
|
|
@ -2922,6 +2922,10 @@ null
|
|||
if err := enc.Encode(test.data); err != nil {
|
||||
t.Fatalf("%s(htmlEscape:%T): %s: %s", test.name, htmlEscape, test.expected, err)
|
||||
}
|
||||
stdresult := encodeByEncodingJSON(test.data, indent, htmlEscape)
|
||||
if buf.String() != stdresult {
|
||||
t.Errorf("%s(htmlEscape:%T): doesn't compatible with encoding/json. expected %q but got %q", test.name, htmlEscape, stdresult, buf.String())
|
||||
}
|
||||
if indent {
|
||||
got := "\n" + buf.String()
|
||||
if got != test.indentExpected {
|
||||
|
|
|
@ -2922,6 +2922,10 @@ null
|
|||
if err := enc.Encode(test.data); err != nil {
|
||||
t.Fatalf("%s(htmlEscape:%T): %s: %s", test.name, htmlEscape, test.expected, err)
|
||||
}
|
||||
stdresult := encodeByEncodingJSON(test.data, indent, htmlEscape)
|
||||
if buf.String() != stdresult {
|
||||
t.Errorf("%s(htmlEscape:%T): doesn't compatible with encoding/json. expected %q but got %q", test.name, htmlEscape, stdresult, buf.String())
|
||||
}
|
||||
if indent {
|
||||
got := "\n" + buf.String()
|
||||
if got != test.indentExpected {
|
||||
|
|
Loading…
Reference in New Issue