Skip to content

Commit

Permalink
Merge branch 'main' into fix/datarace
Browse files Browse the repository at this point in the history
  • Loading branch information
liuq19 authored Jun 20, 2024
2 parents 5eac274 + 09461c3 commit 6a8437d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
3 changes: 2 additions & 1 deletion ast/visitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ func (self *traverser) decodeObject() error {

/* check for empty object */
if self.parser.s[self.parser.p] == '}' {
self.parser.p++
return self.visitor.OnObjectEnd()
}

Expand Down Expand Up @@ -326,6 +327,6 @@ func (self *traverser) decodeString(iv int64, ep int) error {
return self.visitor.OnString(out)
}

// If visitor return this error on `OnObjectBegin()` or `OnArrayBegin()`,
// If visitor return this error on `OnObjectBegin()` or `OnArrayBegin()`,
// the transverer will skip entiry object or array
var VisitOPSkip = errors.New("")
31 changes: 19 additions & 12 deletions ast/visitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ import (
`github.com/stretchr/testify/require`
)

var visitorTestCases = []struct {
name string
jsonStr string
} {
{"default", _TwitterJson},
{"issue_case01", "[1193.6419677734375]"},
{"issue653", `{"v0": 0, "m0": {}, "v1": 1, "a0": [], "v2": 2}`},
}

type visitorNodeDiffTest struct {
t *testing.T
str string
Expand Down Expand Up @@ -328,12 +337,11 @@ func TestVisitor_NodeDiff(t *testing.T) {
return writer
}

t.Run("default", func(t *testing.T) {
suite.Run(t, _TwitterJson, newTracer(t))
})
t.Run("issue_case01", func(t *testing.T) {
suite.Run(t, `[1193.6419677734375]`, newTracer(t))
})
for _, c := range visitorTestCases {
t.Run(c.name, func(t *testing.T) {
suite.Run(t, c.jsonStr, newTracer(t))
})
}
}

type visitorUserNode interface {
Expand Down Expand Up @@ -640,12 +648,11 @@ func TestVisitor_UserNodeDiff(t *testing.T) {
var d1 visitorUserNodeASTDecoder
var d2 visitorUserNodeVisitorDecoder

t.Run("default", func(t *testing.T) {
testUserNodeDiff(t, &d1, &d2, _TwitterJson)
})
t.Run("issue_case01", func(t *testing.T) {
testUserNodeDiff(t, &d1, &d2, `[1193.6419677734375]`)
})
for _, c := range visitorTestCases {
t.Run(c.name, func(t *testing.T) {
testUserNodeDiff(t, &d1, &d2, c.jsonStr)
})
}
}

type skipVisitor struct {
Expand Down

0 comments on commit 6a8437d

Please sign in to comment.