Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
AsterDY committed Jan 22, 2024
1 parent b8b3e27 commit 5282d44
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ast/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -1804,4 +1804,4 @@ func switchRawType(c byte) types.ValueType {
func backward(src string, i int) int {
for ; i>=0 && isSpace(src[i]); i-- {}
return i
}
}
42 changes: 41 additions & 1 deletion ast/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ func TestExportErrNotExist(t *testing.T) {
if err != test.err || node.Exists(){
t.Fatal(err)
}
p.parser.p = 0
val, err := p.GetValueByPath(test.path...)
if err != test.err || val.Exists(){
t.Fatal(err)
}
}
t.Run(test.data, f)
}
Expand Down Expand Up @@ -234,10 +239,15 @@ func TestSearcher_GetByPathSingle(t *testing.T) {
s := NewSearcher(test.json)
node, err1 := s.GetByPath(test.path...)
assert.Equal(t, test.ok, err1 == nil)

value, err2 := node.Interface()
assert.Equal(t, test.value, value)
assert.Equal(t, test.ok, err2 == nil)

val, err1 := s.GetValueByPath(test.path...)
assert.Equal(t, test.ok, err1 == nil)
value, err2 = val.Interface()
assert.Equal(t, test.value, value)
assert.Equal(t, test.ok, err2 == nil)
})
}
}
Expand Down Expand Up @@ -273,6 +283,36 @@ func TestSearcher_GetByPathErr(t *testing.T) {
if e == nil {
t.Fatalf("node: %v, err: %v", node, e)
}

val, e := s.GetByPath("zz")
if e == nil {
t.Fatalf("val: %v, err: %v", val, e)
}
s.parser.p = 0
val, e = s.GetByPath("xx", 4)
if e == nil {
t.Fatalf("val: %v, err: %v", val, e)
}
s.parser.p = 0
val, e = s.GetByPath("yy", "a")
if e == nil {
t.Fatalf("val: %v, err: %v", val, e)
}
s.parser.p = 0
val, e = s.GetByPath("test", 2, "x")
if e == nil {
t.Fatalf("val: %v, err: %v", val, e)
}
s.parser.p = 0
val, e = s.GetByPath("err1", 0)
if e == nil {
t.Fatalf("val: %v, err: %v", val, e)
}
s.parser.p = 0
val, e = s.GetByPath("err2", "x")
if e == nil {
t.Fatalf("val: %v, err: %v", val, e)
}
}

func TestLoadIndex(t *testing.T) {
Expand Down

0 comments on commit 5282d44

Please sign in to comment.