Browse Source

Add tests for subsetof

pull/365/head
Daniel Halperin 8 years ago
parent
commit
7a6fa59a85
  1. 10
      json-path/src/test/java/com/jayway/jsonpath/FilterParseTest.java
  2. 20
      json-path/src/test/java/com/jayway/jsonpath/FilterTest.java

10
json-path/src/test/java/com/jayway/jsonpath/FilterParseTest.java

@ -1,5 +1,6 @@
package com.jayway.jsonpath;
import java.util.Collections;
import org.assertj.core.api.Assertions;
import org.junit.Test;
@ -142,6 +143,15 @@ public class FilterParseTest {
assertThat(filter).isEqualTo(parsed);
}
@Test
public void a_subsetof_filter_can_be_serialized() {
String filter = filter(where("a").subsetof(Collections.emptyList())).toString();
String parsed = parse("[?(@['a'] SUBSETOF [])]").toString();
assertThat(filter).isEqualTo(parsed);
}
@Test
public void a_exists_filter_can_be_serialized() {

20
json-path/src/test/java/com/jayway/jsonpath/FilterTest.java

@ -1,5 +1,7 @@
package com.jayway.jsonpath;
import java.util.ArrayList;
import org.assertj.core.util.Lists;
import org.junit.Test;
import java.util.HashMap;
@ -358,6 +360,24 @@ public class FilterTest extends BaseTest {
assertThat(filter(where("null-key").size(6)).apply(createPredicateContext(json))).isEqualTo(false);
}
//----------------------------------------------------------------------------
//
// SUBSETOF
//
//----------------------------------------------------------------------------
@Test
public void array_subsetof_evals() {
// list is a superset
List<String> list = Lists.newArrayList("a", "b", "c", "d", "e", "f", "g");
assertThat(filter(where("string-arr").subsetof(list)).apply(createPredicateContext(json))).isEqualTo(true);
// list is exactly the same set (but in a different order)
list = Lists.newArrayList("e", "d", "b", "c", "a");
assertThat(filter(where("string-arr").subsetof(list)).apply(createPredicateContext(json))).isEqualTo(true);
// list is missing one element
list = Lists.newArrayList("a", "b", "c", "d");
assertThat(filter(where("string-arr").subsetof(list)).apply(createPredicateContext(json))).isEqualTo(false);
}
//----------------------------------------------------------------------------
//
// EXISTS

Loading…
Cancel
Save