Skip to content

Commit

Permalink
[*] fix: Issue #30
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew-M-C committed May 7, 2024
1 parent 0b6bd70 commit 78c1871
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/go_1.16_before.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

env:
CODECOV_TOKEN: '2fc0d617-8e9a-47d7-ab58-52fa92b23741'
MAIN_GO_VER: '1.16'
MAIN_GO_VER: '1.13'
MAIN_HOST_OS: 'ubuntu-latest'

jobs:
Expand All @@ -18,7 +18,7 @@ jobs:
max-parallel: 6
matrix:
GO_VER: ['1.13', '1.14', '1.15']
HOST_OS: ['ubuntu-latest', 'macos-latest']
HOST_OS: ['ubuntu-latest']

runs-on: ${{ matrix.HOST_OS }}

Expand Down
2 changes: 2 additions & 0 deletions jsonvalue.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,8 @@ func (v *V) deepCopy() *V {
res := new(globalPool{}, Array)
res.children = v.children.deepCopy()
return res
case Boolean:
return NewBool(v.Bool())
case Null:
return NewNull()
}
Expand Down
55 changes: 55 additions & 0 deletions marshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func testMarshal(t *testing.T) {
cv("indent", func() { testMarshalIndent(t) })
cv("ASCII control characters", func() { testMarshalControlCharacters(t) })
cv("test JSONP and control ASCII for UTF-8", func() { testMarshalJSONPAndControlAsciiForUTF8(t) })
cv("Issue #30", func() { testIssue30(t) })
}

func testMarshalFloat64NaN(*testing.T) {
Expand Down Expand Up @@ -605,3 +606,57 @@ func testMarshalJSONPAndControlAsciiForUTF8(t *testing.T) {
so(err, isNil)
so(v.String(), eq, string(unshownableControlCharsAndJSONPSpecial))
}

func testIssue30(t *testing.T) {
cv("Issue #30", func() {
responseData, err := MustUnmarshalString(issue30Raw).Get("data")
so(err, isNil)

var candidateInfoArr []*V
candidateInfoArr = append(candidateInfoArr, responseData.ForRangeArr()...)
data := candidateInfoArr

v := NewObject()
v.MustSet(data).At("data")

b := v.MustMarshal(OptSetSequence())
t.Log(v)
t.Log(string(b))

var m json.RawMessage
err = json.Unmarshal(b, &m)
so(err, isNil)
})

cv("stripped Issue #30", func() {
list := []*V{
NewObject(map[string]any{"archived": false}),
NewObject(map[string]any{"archived": false}),
}

v, err := Import(list)
so(err, isNil)
so(v.IsArray(), isTrue)

t.Log(v)
})
}

const issue30Raw = `{
"data": [
{
"basicInfo": {
"num": 0,
"str": "",
"archived": true
}
},
{
"basicInfo": {
"num": 1,
"str": "",
"archived": false
}
}
]
}`

0 comments on commit 78c1871

Please sign in to comment.