mirror of https://github.com/goccy/go-json.git
Merge pull request #90 from goccy/feature/coverage
Add test cases for unsigned integer types
This commit is contained in:
commit
8578b68bf3
|
@ -1,5 +1,10 @@
|
||||||
package json_test
|
package json_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
stdjson "encoding/json"
|
||||||
|
)
|
||||||
|
|
||||||
func intptr(v int) *int { return &v }
|
func intptr(v int) *int { return &v }
|
||||||
func int8ptr(v int8) *int8 { return &v }
|
func int8ptr(v int8) *int8 { return &v }
|
||||||
func int16ptr(v int16) *int16 { 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 float32ptr(v float32) *float32 { return &v }
|
||||||
func float64ptr(v float64) *float64 { return &v }
|
func float64ptr(v float64) *float64 { return &v }
|
||||||
func stringptr(v string) *string { 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 {
|
if err := enc.Encode(test.data); err != nil {
|
||||||
t.Fatalf("%s(htmlEscape:%T): %s: %s", test.name, htmlEscape, test.expected, err)
|
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 {
|
if indent {
|
||||||
got := "\n" + buf.String()
|
got := "\n" + buf.String()
|
||||||
if got != test.indentExpected {
|
if got != test.indentExpected {
|
||||||
|
|
|
@ -2922,6 +2922,10 @@ null
|
||||||
if err := enc.Encode(test.data); err != nil {
|
if err := enc.Encode(test.data); err != nil {
|
||||||
t.Fatalf("%s(htmlEscape:%T): %s: %s", test.name, htmlEscape, test.expected, err)
|
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 {
|
if indent {
|
||||||
got := "\n" + buf.String()
|
got := "\n" + buf.String()
|
||||||
if got != test.indentExpected {
|
if got != test.indentExpected {
|
||||||
|
|
|
@ -2922,6 +2922,10 @@ null
|
||||||
if err := enc.Encode(test.data); err != nil {
|
if err := enc.Encode(test.data); err != nil {
|
||||||
t.Fatalf("%s(htmlEscape:%T): %s: %s", test.name, htmlEscape, test.expected, err)
|
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 {
|
if indent {
|
||||||
got := "\n" + buf.String()
|
got := "\n" + buf.String()
|
||||||
if got != test.indentExpected {
|
if got != test.indentExpected {
|
||||||
|
|
|
@ -2922,6 +2922,10 @@ null
|
||||||
if err := enc.Encode(test.data); err != nil {
|
if err := enc.Encode(test.data); err != nil {
|
||||||
t.Fatalf("%s(htmlEscape:%T): %s: %s", test.name, htmlEscape, test.expected, err)
|
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 {
|
if indent {
|
||||||
got := "\n" + buf.String()
|
got := "\n" + buf.String()
|
||||||
if got != test.indentExpected {
|
if got != test.indentExpected {
|
||||||
|
|
|
@ -2922,6 +2922,10 @@ null
|
||||||
if err := enc.Encode(test.data); err != nil {
|
if err := enc.Encode(test.data); err != nil {
|
||||||
t.Fatalf("%s(htmlEscape:%T): %s: %s", test.name, htmlEscape, test.expected, err)
|
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 {
|
if indent {
|
||||||
got := "\n" + buf.String()
|
got := "\n" + buf.String()
|
||||||
if got != test.indentExpected {
|
if got != test.indentExpected {
|
||||||
|
|
1952
cover_uint16_test.go
1952
cover_uint16_test.go
File diff suppressed because it is too large
Load Diff
1952
cover_uint32_test.go
1952
cover_uint32_test.go
File diff suppressed because it is too large
Load Diff
1952
cover_uint64_test.go
1952
cover_uint64_test.go
File diff suppressed because it is too large
Load Diff
1952
cover_uint8_test.go
1952
cover_uint8_test.go
File diff suppressed because it is too large
Load Diff
1952
cover_uint_test.go
1952
cover_uint_test.go
File diff suppressed because it is too large
Load Diff
2159
encode_vm.go
2159
encode_vm.go
File diff suppressed because it is too large
Load Diff
2156
encode_vm_escaped.go
2156
encode_vm_escaped.go
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
2076
encode_vm_indent.go
2076
encode_vm_indent.go
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue