Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
tidwall committed Nov 22, 2022
1 parent f37cc44 commit e14b8d3
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions gjson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2573,3 +2573,21 @@ func TestDeepModifierWithOptions(t *testing.T) {
actual + "\n\t<<< MISMATCH >>>")
}
}

func TestIssue301(t *testing.T) {
json := `{
"children": ["Sara","Alex","Jack"],
"fav.movie": ["Deer Hunter"]
}`

assert(t, Get(json, `children.0`).String() == "Sara")
assert(t, Get(json, `children.[0]`).String() == `["Sara"]`)
assert(t, Get(json, `children.1`).String() == "Alex")
assert(t, Get(json, `children.[1]`).String() == `["Alex"]`)
assert(t, Get(json, `children.[10]`).String() == `[]`)
assert(t, Get(json, `fav\.movie.0`).String() == "Deer Hunter")
assert(t, Get(json, `fav\.movie.[0]`).String() == `["Deer Hunter"]`)
assert(t, Get(json, `fav\.movie.1`).String() == "")
assert(t, Get(json, `fav\.movie.[1]`).String() == "[]")

}

0 comments on commit e14b8d3

Please sign in to comment.