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

View File

@ -204,7 +204,10 @@ func TestBasic(t *testing.T) {
if mtok.String() != "1002.3" {
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`)
if mtok.String() != "aaaa" {
t.Fatalf("expected %v, got %v", "aaaa", mtok.String())