added != comparison operator

This commit is contained in:
Josh Baker 2016-11-30 14:38:08 -07:00
parent 90669a0cbe
commit 7afd24f7a2
2 changed files with 22 additions and 4 deletions

View File

@ -645,8 +645,11 @@ func parseArrayPath(path string) (r arrayPathResult) {
} }
s := i s := i
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] == '%' ||
path[i] == ']' { path[i] == ']' {
break break
@ -661,7 +664,11 @@ func parseArrayPath(path string) (r arrayPathResult) {
} }
if i < len(path) { if i < len(path) {
s = i s = i
if path[i] == '<' || path[i] == '>' { if path[i] == '!' {
if i < len(path)-1 && path[i+1] == '=' {
i++
}
} else if path[i] == '<' || path[i] == '>' {
if i < len(path)-1 && path[i+1] == '=' { if i < len(path)-1 && path[i+1] == '=' {
i++ i++
} }
@ -990,6 +997,8 @@ func queryMatches(rp *arrayPathResult, value Result) bool {
switch rp.query.op { switch rp.query.op {
case "=": case "=":
return value.Str == rpv return value.Str == rpv
case "!=":
return value.Str != rpv
case "<": case "<":
return value.Str < rpv return value.Str < rpv
case "<=": case "<=":
@ -1006,6 +1015,8 @@ func queryMatches(rp *arrayPathResult, value Result) bool {
switch rp.query.op { switch rp.query.op {
case "=": case "=":
return value.Num == rpvn return value.Num == rpvn
case "!=":
return value.Num == rpvn
case "<": case "<":
return value.Num < rpvn return value.Num < rpvn
case "<=": case "<=":
@ -1019,6 +1030,8 @@ func queryMatches(rp *arrayPathResult, value Result) bool {
switch rp.query.op { switch rp.query.op {
case "=": case "=":
return rpv == "true" return rpv == "true"
case "!=":
return rpv != "true"
case ">": case ">":
return rpv == "false" return rpv == "false"
case ">=": case ">=":
@ -1028,6 +1041,8 @@ func queryMatches(rp *arrayPathResult, value Result) bool {
switch rp.query.op { switch rp.query.op {
case "=": case "=":
return rpv == "false" return rpv == "false"
case "!=":
return rpv != "false"
case "<": case "<":
return rpv == "true" return rpv == "true"
case "<=": case "<=":

View File

@ -204,7 +204,10 @@ func TestBasic(t *testing.T) {
if mtok.String() != "1002.3" { if mtok.String() != "1002.3" {
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 != "Brett"].firstName`)
if mtok.String() != "Jason" {
t.Fatalf("expected %v, got %v", "Jason", mtok.String())
}
mtok = get(basicJSON, `loggy.programmers.#[firstName % "Bre*"].email`) mtok = get(basicJSON, `loggy.programmers.#[firstName % "Bre*"].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())