Add test case of encoder for json.Number type

This commit is contained in:
Masaaki Goshima 2021-03-20 19:01:04 +09:00
parent 16f6c377b4
commit d0d58b9026
5 changed files with 1817 additions and 0 deletions

View File

@ -3,6 +3,8 @@ package json_test
import (
"bytes"
stdjson "encoding/json"
"github.com/goccy/go-json"
)
func intptr(v int) *int { return &v }
@ -35,6 +37,8 @@ func boolptr(v bool) *bool { return &v }
func boolptr3(v bool) ***bool { vv := &v; vvv := &vv; return &vvv }
func bytesptr(v []byte) *[]byte { return &v }
func bytesptr3(v []byte) ***[]byte { vv := &v; vvv := &vv; return &vvv }
func numberptr(v json.Number) *json.Number { return &v }
func numberptr3(v json.Number) ***json.Number { vv := &v; vvv := &vv; return &vvv }
func sliceptr(v []int) *[]int { return &v }
func arrayptr(v [2]int) *[2]int { return &v }
func mapptr(v map[string]int) *map[string]int { return &v }

1807
cover_number_test.go Normal file

File diff suppressed because it is too large Load Diff

View File

@ -429,6 +429,8 @@ func convertPtrOp(code *Opcode) OpType {
return OpBoolPtr
case OpBytes:
return OpBytesPtr
case OpNumber:
return OpNumberPtr
case OpArray:
return OpArrayPtr
case OpSlice:

View File

@ -2420,7 +2420,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
p = ptrToNPtr(p+code.Offset, code.PtrNum)
}
if p != 0 {
b = appendIndent(ctx, b, code.Indent+1)
b = append(b, code.EscapedKey...)
b = append(b, ' ')
bb, err := appendNumber(b, ptrToNumber(p))
if err != nil {
return nil, err

View File

@ -2426,7 +2426,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
p = ptrToNPtr(p+code.Offset, code.PtrNum)
}
if p != 0 {
b = appendIndent(ctx, b, code.Indent+1)
b = append(b, code.Key...)
b = append(b, ' ')
bb, err := appendNumber(b, ptrToNumber(p))
if err != nil {
return nil, err