Skip to content

Commit 60fffdc

Browse files
committed
test(jq): cover multiple --arg flags together
Signed-off-by: Lars Trieloff <lars@trieloff.net>
1 parent 4251d5d commit 60fffdc

3 files changed

Lines changed: 56 additions & 0 deletions

File tree

packages/just-bash/src/commands/jq/jq.arg.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,28 @@ describe("jq named-argument flags", () => {
2222
});
2323
});
2424

25+
describe("multiple --arg", () => {
26+
it("populates $ARGS.named in order", async () => {
27+
const env = new Bash();
28+
const result = await env.exec(
29+
"jq -cn --arg a foo --arg b bar --arg c baz '$ARGS.named'",
30+
);
31+
expect(result.stdout).toBe('{"a":"foo","b":"bar","c":"baz"}\n');
32+
expect(result.stderr).toBe("");
33+
expect(result.exitCode).toBe(0);
34+
});
35+
36+
it("binds each $NAME for use in a filter", async () => {
37+
const env = new Bash();
38+
const result = await env.exec(
39+
"jq -n --arg first Ada --arg last Lovelace '$first + \" \" + $last'",
40+
);
41+
expect(result.stdout).toBe('"Ada Lovelace"\n');
42+
expect(result.stderr).toBe("");
43+
expect(result.exitCode).toBe(0);
44+
});
45+
});
46+
2547
describe("--argjson", () => {
2648
it("binds $NAME to a JSON number", async () => {
2749
const env = new Bash();

packages/just-bash/src/comparison-tests/fixtures/jq-arg.comparison.fixtures.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
{
2+
"182a418ef9169fee": {
3+
"command": "jq -cn --arg a foo --arg b bar --arg c baz '$ARGS.named'",
4+
"files": {},
5+
"stdout": "{\"a\":\"foo\",\"b\":\"bar\",\"c\":\"baz\"}\n",
6+
"stderr": "",
7+
"exitCode": 0
8+
},
29
"29c465e8ba4443cf": {
310
"command": "echo '{}' | jq --arg name World '{greeting: (\"Hello \" + $name)}'",
411
"files": {},
@@ -27,6 +34,13 @@
2734
"stderr": "",
2835
"exitCode": 0
2936
},
37+
"663f71c927f1e87a": {
38+
"command": "jq -n --arg first Ada --arg last Lovelace '$first + \" \" + $last'",
39+
"files": {},
40+
"stdout": "\"Ada Lovelace\"\n",
41+
"stderr": "",
42+
"exitCode": 0
43+
},
3044
"78da9edc39aeb8cb": {
3145
"command": "jq -n --argjson x notjson '$x'",
3246
"files": {},

packages/just-bash/src/comparison-tests/jq-arg.comparison.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,26 @@ describe("jq named-argument flags - Real Bash Comparison", () => {
3333
});
3434
});
3535

36+
describe("multiple --arg", () => {
37+
it("populates $ARGS.named in order", async () => {
38+
const env = await setupFiles(testDir, {});
39+
await compareOutputs(
40+
env,
41+
testDir,
42+
"jq -cn --arg a foo --arg b bar --arg c baz '$ARGS.named'",
43+
);
44+
});
45+
46+
it("binds each $name for use in a filter", async () => {
47+
const env = await setupFiles(testDir, {});
48+
await compareOutputs(
49+
env,
50+
testDir,
51+
"jq -n --arg first Ada --arg last Lovelace '$first + \" \" + $last'",
52+
);
53+
});
54+
});
55+
3656
describe("--argjson", () => {
3757
it("binds a JSON number", async () => {
3858
const env = await setupFiles(testDir, {});

0 commit comments

Comments
 (0)