query matching with %

This commit is contained in:
Josh Baker 2016-11-30 14:32:17 -07:00
parent 6fd75099ef
commit 90669a0cbe
2 changed files with 7 additions and 0 deletions

View File

@ -647,6 +647,7 @@ func parseArrayPath(path string) (r arrayPathResult) {
for ; i < len(path); i++ { for ; i < len(path); i++ {
if path[i] <= ' ' || path[i] == '=' || if path[i] <= ' ' || path[i] == '=' ||
path[i] == '<' || path[i] == '>' || path[i] == '<' || path[i] == '>' ||
path[i] == '%' ||
path[i] == ']' { path[i] == ']' {
break break
} }
@ -997,6 +998,8 @@ func queryMatches(rp *arrayPathResult, value Result) bool {
return value.Str > rpv return value.Str > rpv
case ">=": case ">=":
return value.Str >= rpv return value.Str >= rpv
case "%":
return match.Match(value.Str, rpv)
} }
case Number: case Number:
rpvn, _ := strconv.ParseFloat(rpv, 64) rpvn, _ := strconv.ParseFloat(rpv, 64)

View File

@ -205,6 +205,10 @@ func TestBasic(t *testing.T) {
t.Fatalf("expected %v, got %v", "1002.3", mtok.String()) t.Fatalf("expected %v, got %v", "1002.3", mtok.String())
} }
mtok = get(basicJSON, `loggy.programmers.#[firstName % "Bre*"].email`)
if mtok.String() != "aaaa" {
t.Fatalf("expected %v, got %v", "aaaa", mtok.String())
}
mtok = get(basicJSON, `loggy.programmers.#[firstName == "Brett"].email`) mtok = get(basicJSON, `loggy.programmers.#[firstName == "Brett"].email`)
if mtok.String() != "aaaa" { if mtok.String() != "aaaa" {
t.Fatalf("expected %v, got %v", "aaaa", mtok.String()) t.Fatalf("expected %v, got %v", "aaaa", mtok.String())