Browse Source

Fixed bug with single '=' sign.

pull/6/head
Kalle Stenflo 13 years ago
parent
commit
cb122f7f31
  1. 6
      json-path/src/main/java/com/jayway/jsonpath/reader/filter/eval/ExpressionEvaluator.java
  2. 46
      json-path/src/test/java/com/jayway/jsonpath/ComplianceTests.java

6
json-path/src/main/java/com/jayway/jsonpath/reader/filter/eval/ExpressionEvaluator.java

@ -17,7 +17,7 @@ public class ExpressionEvaluator {
Long a = (Long) actual;
Long e = Long.parseLong(expected.trim());
if ("=".equals(comparator)) {
if ("=".equals(comparator) || "==".equals(comparator)) {
return a.longValue() == e.longValue();
} else if ("!=".equals(comparator) || "<>".equals(comparator)) {
return a.longValue() != e.longValue();
@ -52,7 +52,7 @@ public class ExpressionEvaluator {
Double a = (Double) actual;
Double e = Double.parseDouble(expected.trim());
if ("=".equals(comparator)) {
if ("=".equals(comparator) || "==".equals(comparator)) {
return a.doubleValue() == e.doubleValue();
} else if ("!=".equals(comparator) || "<>".equals(comparator)) {
return a.doubleValue() != e.doubleValue();
@ -76,7 +76,7 @@ public class ExpressionEvaluator {
expected = expected.substring(0, expected.length()-1);
}
if ("=".equals(comparator)) {
if ("=".equals(comparator) || "==".equals(comparator)) {
return a.equals(expected);
} else if ("!=".equals(comparator) || "<>".equals(comparator)) {
return !a.equals(expected);

46
json-path/src/test/java/com/jayway/jsonpath/ComplianceTests.java

@ -40,7 +40,12 @@ public class ComplianceTests {
assertThat(JsonPath.<Integer>read(json, "$[0]"), is(equalTo(1)));
assertThat(JsonPath.<Integer>read(json, "$[4]"), is(equalTo(null)));
assertThat(JsonPath.<List<Comparable>>read(json, "$[*]"), hasItems((Comparable)new Integer(1), (Comparable)new String("2"), (Comparable)new Double(3.14), (Comparable)new Boolean(true), null));
assertThat(JsonPath.<List<Comparable>>read(json, "$[*]"), hasItems(
(Comparable)new Integer(1),
(Comparable)new String("2"),
(Comparable)new Double(3.14),
(Comparable)new Boolean(true),
null));
assertThat(JsonPath.<Boolean>read(json, "$[-1:]"), is(equalTo(null)));
}
@ -65,7 +70,7 @@ public class ComplianceTests {
assertThat(JsonPath.<Integer>read(json, "$.points[4].x"), equalTo(0));
assertThat(JsonPath.<List<Integer>>read(json, "$.points[?(@.id = 'i4')].x"), hasItem(-6));
assertThat(JsonPath.<List<Integer>>read(json, "$.points[?(@.id == 'i4')].x"), hasItem(-6));
assertThat(JsonPath.<List<Integer>>read(json, "$.points[*].x"), hasItems(4, -2, 8, -6, 0, 1));
@ -78,7 +83,44 @@ public class ComplianceTests {
@Test
public void test_four() throws Exception {
String json = "{ \"menu\": {\n" +
" \"header\": \"SVG Viewer\",\n" +
" \"items\": [\n" +
" {\"id\": \"Open\"},\n" +
" {\"id\": \"OpenNew\", \"label\": \"Open New\"},\n" +
" null,\n" +
" {\"id\": \"ZoomIn\", \"label\": \"Zoom In\"},\n" +
" {\"id\": \"ZoomOut\", \"label\": \"Zoom Out\"},\n" +
" {\"id\": \"OriginalView\", \"label\": \"Original View\"},\n" +
" null,\n" +
" {\"id\": \"Quality\"},\n" +
" {\"id\": \"Pause\"},\n" +
" {\"id\": \"Mute\"},\n" +
" null,\n" +
" {\"id\": \"Find\", \"label\": \"Find...\"},\n" +
" {\"id\": \"FindAgain\", \"label\": \"Find Again\"},\n" +
" {\"id\": \"Copy\"},\n" +
" {\"id\": \"CopyAgain\", \"label\": \"Copy Again\"},\n" +
" {\"id\": \"CopySVG\", \"label\": \"Copy SVG\"},\n" +
" {\"id\": \"ViewSVG\", \"label\": \"View SVG\"},\n" +
" {\"id\": \"ViewSource\", \"label\": \"View Source\"},\n" +
" {\"id\": \"SaveAs\", \"label\": \"Save As\"},\n" +
" null,\n" +
" {\"id\": \"Help\"},\n" +
" {\"id\": \"About\", \"label\": \"About Adobe CVG Viewer...\"}\n" +
" ]\n" +
" }\n" +
" }";
/*
"$.menu.items[?(@ && @.id && !@.label)].id",
"$.menu.items[?(@ && @.label && /SVG/.test(@.label))].id",
"$.menu.items[?(!@)]",
"$..[0]"
*/
}

Loading…
Cancel
Save