Skip to content

Commit 7a6fa59

Browse files
committed
Add tests for subsetof
1 parent c9527bf commit 7a6fa59

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.jayway.jsonpath;
22

3+
import java.util.Collections;
34
import org.assertj.core.api.Assertions;
45
import org.junit.Test;
56

@@ -142,6 +143,15 @@ public void a_size_filter_can_be_serialized() {
142143
assertThat(filter).isEqualTo(parsed);
143144
}
144145

146+
@Test
147+
public void a_subsetof_filter_can_be_serialized() {
148+
149+
String filter = filter(where("a").subsetof(Collections.emptyList())).toString();
150+
String parsed = parse("[?(@['a'] SUBSETOF [])]").toString();
151+
152+
assertThat(filter).isEqualTo(parsed);
153+
}
154+
145155
@Test
146156
public void a_exists_filter_can_be_serialized() {
147157

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.jayway.jsonpath;
22

3+
import java.util.ArrayList;
4+
import org.assertj.core.util.Lists;
35
import org.junit.Test;
46

57
import java.util.HashMap;
@@ -358,6 +360,24 @@ public void null_size_evals() {
358360
assertThat(filter(where("null-key").size(6)).apply(createPredicateContext(json))).isEqualTo(false);
359361
}
360362

363+
//----------------------------------------------------------------------------
364+
//
365+
// SUBSETOF
366+
//
367+
//----------------------------------------------------------------------------
368+
@Test
369+
public void array_subsetof_evals() {
370+
// list is a superset
371+
List<String> list = Lists.newArrayList("a", "b", "c", "d", "e", "f", "g");
372+
assertThat(filter(where("string-arr").subsetof(list)).apply(createPredicateContext(json))).isEqualTo(true);
373+
// list is exactly the same set (but in a different order)
374+
list = Lists.newArrayList("e", "d", "b", "c", "a");
375+
assertThat(filter(where("string-arr").subsetof(list)).apply(createPredicateContext(json))).isEqualTo(true);
376+
// list is missing one element
377+
list = Lists.newArrayList("a", "b", "c", "d");
378+
assertThat(filter(where("string-arr").subsetof(list)).apply(createPredicateContext(json))).isEqualTo(false);
379+
}
380+
361381
//----------------------------------------------------------------------------
362382
//
363383
// EXISTS

0 commit comments

Comments
 (0)