diff --git a/ast/visitor.go b/ast/visitor.go index f25407b99..dc0478513 100644 --- a/ast/visitor.go +++ b/ast/visitor.go @@ -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() } @@ -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("") diff --git a/ast/visitor_test.go b/ast/visitor_test.go index c576bdd9d..2618c5460 100644 --- a/ast/visitor_test.go +++ b/ast/visitor_test.go @@ -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 @@ -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 { @@ -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 {