Skip to content

Commit

Permalink
test: add test for #67
Browse files Browse the repository at this point in the history
  • Loading branch information
eiiches committed Nov 23, 2020
1 parent f93d865 commit 2a4ab7b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ This table illustrates which features (picked from jq-1.5 manual) are supported
|     • [`unique`, `unique_by(path_exp)`](https://stedolan.github.io/jq/manual/v1.5/#unique,unique_by(path_exp)) ||
|     • [`reverse`](https://stedolan.github.io/jq/manual/v1.5/#reverse) ||
|     • [`contains(element)`](https://stedolan.github.io/jq/manual/v1.5/#contains(element)) ||
|     • [`indices(s)`](https://stedolan.github.io/jq/manual/v1.5/#indices(s)) | |
| &nbsp;&nbsp;&nbsp;&nbsp;&bull; [`indices(s)`](https://stedolan.github.io/jq/manual/v1.5/#indices&#40;s&#41;) |<sup>*9</sup> |
| &nbsp;&nbsp;&nbsp;&nbsp;&bull; [`index(s)`, `rindex(s)`](https://stedolan.github.io/jq/manual/v1.5/#index&#40;s&#41;&#44;rindex&#40;s&#41;) ||
| &nbsp;&nbsp;&nbsp;&nbsp;&bull; [`inside`](https://stedolan.github.io/jq/manual/v1.5/#inside) ||
| &nbsp;&nbsp;&nbsp;&nbsp;&bull; [`startswith(str)`](https://stedolan.github.io/jq/manual/v1.5/#startswith&#40;str&#41;) ||
Expand Down Expand Up @@ -224,6 +224,8 @@ This table illustrates which features (picked from jq-1.5 manual) are supported

*8) `.foo |= empty` always throws an error in jackson-jq instead of producing an unexpected result. jq-1.5 and jq-1.6 respectively produces a different and incorrect result for `[1,2,3] | ((.[] | select(. > 1)) |= empty)`. [jq#897](https://github.com/stedolan/jq/issues/897) says "empty in the RHS is undefined". You can still use `_modify/2` directly if you really want to emulate the exact jq-1.5 or jq-1.6 behavior.

*9) `"x" | indices("")` always returns an empty array in jackson-jq. The behavior is in line with jq after [2660b04](https://github.com/stedolan/jq/commit/2660b04a731568c54eb4b91fe811d81cbbf3470b) commit, but differs from how jq-1.5 and jq-1.6 behave.

Using jackson-jq-extra module
-----------------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public static class TestCase {
@JsonProperty("should_compile")
public boolean shouldCompile = true;

@JsonProperty("ignore_true_jq_behavior")
public boolean ignoreTrueJqBehavior = false;

@JsonInclude(Include.NON_NULL)
@JsonProperty("v")
@JsonDeserialize(using = VersionRangeDeserializer.class)
Expand Down Expand Up @@ -156,7 +159,7 @@ private void test(final TestCase tc, final Version version) throws Throwable {
return;
}

if (hasJqCache.computeIfAbsent(version, v -> TrueJqEvaluator.hasJq(v))) {
if (!tc.ignoreTrueJqBehavior && hasJqCache.computeIfAbsent(version, v -> TrueJqEvaluator.hasJq(v))) {
final Result result = cachedJqEvaluator.evaluate(tc.q, tc.in, version, 2000L);
assumeThat(result.error).as("%s", command).isNull();
assumeThat(wrap(tc.out)).as("%s", command).isEqualTo(wrap(result.values));
Expand Down
1 change: 1 addition & 0 deletions jackson-jq/src/test/resources/tests/functions/indices.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- {"v":"[1.5,1.5]","q":"indices(-1.0)","in":null,"out":[null]}
- {"v":"[1.5,1.6]","q":"indices(\"\")","in":"x","out":[[]],"ignore_true_jq_behavior":true}

0 comments on commit 2a4ab7b

Please sign in to comment.