File tree 1 file changed +24
-0
lines changed 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -16,4 +16,28 @@ describe("shell-quote parse with pipes", () => {
16
16
17
17
expect ( hasOpToken ) . toBe ( true ) ;
18
18
} ) ;
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
+ } ) ;
19
43
} ) ;
You can’t perform that action at this time.
0 commit comments