reset count on append, fixes #3

This commit is contained in:
Josh Baker 2016-08-15 04:56:55 -07:00
parent e865d89fc7
commit 8be3ed7605
2 changed files with 14 additions and 1 deletions

View File

@ -436,6 +436,7 @@ proc_val:
// return Result{} // return Result{}
} else { } else {
f.stype = vc f.stype = vc
f.count = 0
stack = append(stack, f) stack = append(stack, f)
depth++ depth++
goto read_key goto read_key

View File

@ -97,12 +97,24 @@ func TestEscapePath(t *testing.T) {
var basicJSON = `{"age":100, "name":{"here":"B\\\"R"}, var basicJSON = `{"age":100, "name":{"here":"B\\\"R"},
"noop":{"what is a wren?":"a bird"}, "noop":{"what is a wren?":"a bird"},
"happy":true,"immortal":false, "happy":true,"immortal":false,
"items":[1,2,3,{"tags":[1,2,3],"points":[[1,2],[3,4]]},4,5,6,7],
"arr":["1",2,"3",{"hello":"world"},"4",5], "arr":["1",2,"3",{"hello":"world"},"4",5],
"vals":[1,2,3,{"sadf":sdf"asdf"}],"name":{"first":"tom","last":null}}` "vals":[1,2,3,{"sadf":sdf"asdf"}],"name":{"first":"tom","last":null}}`
func TestBasic(t *testing.T) { func TestBasic(t *testing.T) {
var token Result var token Result
if Get(basicJSON, "items.3.tags.#").Num != 3 {
t.Fatalf("expected 3, got %v", Get(basicJSON, "items.3.tags.#").Num)
}
if Get(basicJSON, "items.3.points.1.#").Num != 2 {
t.Fatalf("expected 2, got %v", Get(basicJSON, "items.3.points.1.#").Num)
}
if Get(basicJSON, "items.#").Num != 8 {
t.Fatalf("expected 6, got %v", Get(basicJSON, "items.#").Num)
}
if Get(basicJSON, "vals.#").Num != 4 {
t.Fatalf("expected 4, got %v", Get(basicJSON, "vals.#").Num)
}
if !Get(basicJSON, "name.last").Exists() { if !Get(basicJSON, "name.last").Exists() {
t.Fatal("expected true, got false") t.Fatal("expected true, got false")
} }