|
5 | 5 |
|
6 | 6 | (unfinished)
|
7 | 7 |
|
| 8 | +(def keys-of-many-types |
| 9 | + [{:key 1} |
| 10 | + {:key 3} |
| 11 | + {:key "nice"} |
| 12 | + {:key true} |
| 13 | + {:key nil} |
| 14 | + {:key false} |
| 15 | + {:key {}} |
| 16 | + {:key []} |
| 17 | + {:key -1} |
| 18 | + {:key 0} |
| 19 | + {:key ""}]) |
| 20 | + |
8 | 21 | (facts
|
9 | 22 | (at-path "$" ...json...) => ...json...
|
10 | 23 | (at-path "$.hello" {:hello "world"}) => "world"
|
|
28 | 41 | {:id 45, :text "hello"}]}) => ["hello"]
|
29 | 42 | (at-path "$.foo[*].bar[*].baz"
|
30 | 43 | {:foo [{:bar [{:baz "hello"}]}]}) => ["hello"]
|
| 44 | + ;; Filter expression with boolean and operator |
31 | 45 | (at-path "$[?(@.key>42 && @.key<44)]"
|
32 | 46 | [{:key 42}, {:key 43}, {:key 44}]) => [{:key 43}]
|
| 47 | + ;; Filter expression with boolean and operator and value false |
| 48 | + (at-path "$[?(@.key>0 && false)]" |
| 49 | + keys-of-many-types) => [] |
| 50 | + ;; Filter expression with boolean and operator and value true |
| 51 | + (at-path "$[?(@.key>0 && true)]" |
| 52 | + keys-of-many-types) => [{:key 1}, {:key 3}] |
| 53 | + ;; Filter expression with boolean or operator |
33 | 54 | (at-path "$[?(@.key>43 || @.key<43)]"
|
34 |
| - [{:key 42}, {:key 43}, {:key 44}]) => [{:key 42}, {:key 44}]) |
35 |
| - |
36 |
| - ;; TODO: add this case, comparator is blowing up comparing against different types |
37 |
| - ;; "Filter expression with boolean or operator and value false" |
38 |
| - ; (at-path "$[?(@.key>0 && false)]" |
39 |
| - ; [{:key 1} |
40 |
| - ; {:key 3} |
41 |
| - ; {:key "nice"} |
42 |
| - ; {:key true} |
43 |
| - ; {:key nil} |
44 |
| - ; {:key false} |
45 |
| - ; {:key {}} |
46 |
| - ; {:key []} |
47 |
| - ; {:key -1} |
48 |
| - ; {:key 0} |
49 |
| - ; {:key ""}]) => [] |
| 55 | + [{:key 42}, {:key 43}, {:key 44}]) => [{:key 42}, {:key 44}] |
| 56 | + ;; Filter expression with boolean or operator and value false |
| 57 | + (at-path "$[?(@.key>0 || false)]" |
| 58 | + keys-of-many-types) => [{:key 1}, {:key 3}] |
| 59 | + ;; Filter expression with boolean or operator and value true |
| 60 | + (at-path "$[?(@.key>0 || true)]" |
| 61 | + keys-of-many-types) => keys-of-many-types) |
| 62 | + ;; TODO: Filter expression with different grouped operators |
| 63 | + ;; NOTE: the parser will need to be updated in order to get this test to work |
| 64 | + ; (at-path "$[?(@.a && (@.b || @.c))]" |
| 65 | + ; [{:a true} |
| 66 | + ; {:a true, :b true} |
| 67 | + ; {:a true, :b true, :c true} |
| 68 | + ; {:b true, :c true} |
| 69 | + ; {:a true, :c true} |
| 70 | + ; {:c true} |
| 71 | + ; {:b true}]) |
| 72 | + ; => [{:a true, :b true} |
| 73 | + ; {:a true, :b true, :c true} |
| 74 | + ; {:a true, :c true}]) |
50 | 75 |
|
51 | 76 | (facts
|
52 | 77 | (-> (query "$.hello"
|
|
0 commit comments