Merge pull request #157 from goccy/feature/add-number-test

Add test case of encoder for json.Number type
This commit is contained in:
Masaaki Goshima 2021-03-20 19:30:51 +09:00 committed by GitHub
commit 015b9c40be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 1818 additions and 1 deletions

View File

@ -14,7 +14,7 @@ jobs:
strategy: strategy:
matrix: matrix:
os: [ "ubuntu-latest", "macos-latest", "windows-latest" ] os: [ "ubuntu-latest", "macos-latest", "windows-latest" ]
go-version: [ "1.13", "1.14", "1.15", "1.16" ] go-version: [ "1.14", "1.15", "1.16" ]
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
- name: setup Go ${{ matrix.go-version }} - name: setup Go ${{ matrix.go-version }}

View File

@ -3,6 +3,8 @@ package json_test
import ( import (
"bytes" "bytes"
stdjson "encoding/json" stdjson "encoding/json"
"github.com/goccy/go-json"
) )
func intptr(v int) *int { return &v } 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 boolptr3(v bool) ***bool { vv := &v; vvv := &vv; return &vvv }
func bytesptr(v []byte) *[]byte { return &v } func bytesptr(v []byte) *[]byte { return &v }
func bytesptr3(v []byte) ***[]byte { vv := &v; vvv := &vv; return &vvv } 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 sliceptr(v []int) *[]int { return &v }
func arrayptr(v [2]int) *[2]int { return &v } func arrayptr(v [2]int) *[2]int { return &v }
func mapptr(v map[string]int) *map[string]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 return OpBoolPtr
case OpBytes: case OpBytes:
return OpBytesPtr return OpBytesPtr
case OpNumber:
return OpNumberPtr
case OpArray: case OpArray:
return OpArrayPtr return OpArrayPtr
case OpSlice: 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) p = ptrToNPtr(p+code.Offset, code.PtrNum)
} }
if p != 0 { if p != 0 {
b = appendIndent(ctx, b, code.Indent+1)
b = append(b, code.EscapedKey...) b = append(b, code.EscapedKey...)
b = append(b, ' ')
bb, err := appendNumber(b, ptrToNumber(p)) bb, err := appendNumber(b, ptrToNumber(p))
if err != nil { if err != nil {
return nil, err 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) p = ptrToNPtr(p+code.Offset, code.PtrNum)
} }
if p != 0 { if p != 0 {
b = appendIndent(ctx, b, code.Indent+1)
b = append(b, code.Key...) b = append(b, code.Key...)
b = append(b, ' ')
bb, err := appendNumber(b, ptrToNumber(p)) bb, err := appendNumber(b, ptrToNumber(p))
if err != nil { if err != nil {
return nil, err return nil, err