Skip to content

Commit

Permalink
Work on tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
01mf02 committed Jun 30, 2023
1 parent d9902a8 commit de77641
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
14 changes: 14 additions & 0 deletions jaq-core/tests/named.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@ fn limit() {
give(json!(null), "[limit(-1; 0, 1)]", json!([]));
}

yields!(min_empty, "[] | min_by(.)", json!(null));
// when output is equal, min_by selects the left element and max_by the right one
yields!(
min_max_eq,
"[{a: 1, b: 3}, {a: 1, b: 2}] | [(min_by(.a), max_by(.a)) | .b]",
[3, 2]
);
// multiple-output functions can be used to differentiate elements
yields!(
max_mult,
"[{a: 1, b: 3}, {a: 1, b: 2}] | max_by(.a, .b) | .b",
3
);

#[test]
fn range() {
let y = json!([-1, -1, 0, 1, 1]);
Expand Down
22 changes: 2 additions & 20 deletions jaq-std/tests/std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ yields!(

#[test]
fn min_max() {
give(json!([]), "min", json!(null));
give(json!([]), "max", json!(null));
give(json!([1, 4, 2]), "min", json!(1));
give(json!([1, 4, 2]), "max", json!(4));
// TODO: find examples where `min_by(f)` yields output different from `min`
// (and move it then to jaq-core/tests/named.rs)
give(
json!([{"a": {"b": {"c": 1}}}, {"a": {"b": {"c": 4}}}, {"a": {"b": {"c": 2}}}]),
"min_by(.a.b.c)",
Expand All @@ -130,24 +130,6 @@ fn min_max() {
"max_by(.a.b.c)",
json!({"a": {"b": {"c": 4}}}),
);
// min_by selects the left element when they're equal
give(
json!([{"a": 1, "b": 3}, {"a": 1, "b": 2}]),
"min_by(.a) | .b",
json!(3),
);
// max_by selects the right one
give(
json!([{"a": 1, "b": 3}, {"a": 1, "b": 2}]),
"max_by(.a) | .b",
json!(2),
);
// multiple-output functions can be used to differentiate elements
give(
json!([{"a": 1, "b": 3}, {"a": 1, "b": 2}]),
"max_by(.a, .b) | .b",
json!(3),
);
}

#[test]
Expand Down

0 comments on commit de77641

Please sign in to comment.