Skip to content

Commit cc7ea56

Browse files
jerry861200jjlai5
authored andcommitted
test: pipe-command
1 parent 44022db commit cc7ea56

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

codex-cli/tests/pipe-command.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,28 @@ describe("shell-quote parse with pipes", () => {
1616

1717
expect(hasOpToken).toBe(true);
1818
});
19+
20+
it("should parse multiple pipes in a command", () => {
21+
const cmd = "cat a.txt | grep foo | sort | uniq";
22+
const tokens = parse(cmd);
23+
const opTokens = tokens.filter((t) => typeof t === "object" && "op" in t);
24+
expect(opTokens.length).toBe(3);
25+
expect(opTokens.every((t) => t.op === "|")).toBe(true);
26+
});
27+
28+
it("should parse pipes with or without spaces", () => {
29+
const cmd = "echo foo|grep foo";
30+
const tokens = parse(cmd);
31+
const opToken = tokens.find((t) => typeof t === "object" && "op" in t);
32+
expect(opToken && opToken.op).toBe("|");
33+
});
34+
35+
it("should parse pipe and other operators together", () => {
36+
const cmd = "echo foo && cat bar | grep baz || echo done";
37+
const tokens = parse(cmd);
38+
const ops = tokens
39+
.filter((t) => typeof t === "object" && "op" in t)
40+
.map((t) => t.op);
41+
expect(ops).toEqual(["&&", "|", "||"]);
42+
});
1943
});

0 commit comments

Comments
 (0)