-
Notifications
You must be signed in to change notification settings - Fork 471
Expand file tree
/
Copy pathtaskManager.test.ts
More file actions
124 lines (104 loc) · 3.3 KB
/
taskManager.test.ts
File metadata and controls
124 lines (104 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import { tokenize } from "./taskManager";
describe(tokenize, () => {
it("parses environment variables", () => {
const input = tokenize("FOO=1 tsc -p");
const output = [
{ type: "EnvVar", value: { FOO: "1" } },
{ type: "Command", value: "tsc" },
{ type: "Argument", value: "-p" },
];
expect(input).toEqual(output);
});
it("parses multiples envs environment variables", () => {
const input = tokenize("FOO=1 BAZ=bla tsc -p");
const output = [
{ type: "EnvVar", value: { FOO: "1", BAZ: "bla" } },
{ type: "Command", value: "tsc" },
{ type: "Argument", value: "-p" },
];
expect(input).toEqual(output);
});
it("parses command and argument", () => {
const input = tokenize("tsc -p");
const output = [
{ type: "Command", value: "tsc" },
{ type: "Argument", value: "-p" },
];
expect(input).toEqual(output);
});
it("parses two commands", () => {
const input = tokenize("tsc && node");
const output = [
{ type: "Command", value: "tsc" },
{ type: "AND" },
{ type: "Command", value: "node" },
];
expect(input).toEqual(output);
});
it("parses two commands", () => {
const input = tokenize("tsc -p . && node index.js");
const output = [
{ type: "Command", value: "tsc" },
{ type: "Argument", value: "-p" },
{ type: "Command", value: "." },
{ type: "AND" },
{ type: "Command", value: "node" },
{ type: "Command", value: "index.js" },
];
expect(input).toEqual(output);
});
it("parses multiple arguments", () => {
const input = tokenize("tsc --foo -- --foo");
const output = [
{ type: "Command", value: "tsc" },
{ type: "Argument", value: "--foo" },
{ type: "Argument", value: "--" },
{ type: "Argument", value: "--foo" },
];
expect(input).toEqual(output);
});
it("parses pipe and string commands", () => {
const input = tokenize(`echo "Hello World" | wc -w`);
const output = [
{ type: "Command", value: "echo" },
{ type: "String", value: '"Hello World"' },
{ type: "PIPE" },
{ type: "Command", value: "wc" },
{ type: "Argument", value: "-w" },
];
expect(input).toEqual(output);
});
it("parses escaped characters", () => {
const input = tokenize(`echo "Hello | World" | wc -w`);
const output = [
{ type: "Command", value: "echo" },
{ type: "String", value: '"Hello | World"' },
{ type: "PIPE" },
{ type: "Command", value: "wc" },
{ type: "Argument", value: "-w" },
];
expect(input).toEqual(output);
});
it("parses escaped characters", () => {
const input = tokenize(`echo "Hello | World" | wc -w`);
const output = [
{ type: "Command", value: "echo" },
{ type: "String", value: '"Hello | World"' },
{ type: "PIPE" },
{ type: "Command", value: "wc" },
{ type: "Argument", value: "-w" },
];
expect(input).toEqual(output);
});
it("parses or", () => {
const input = tokenize(`echo "Hello | World" || wc -w`);
const output = [
{ type: "Command", value: "echo" },
{ type: "String", value: '"Hello | World"' },
{ type: "OR" },
{ type: "Command", value: "wc" },
{ type: "Argument", value: "-w" },
];
expect(input).toEqual(output);
});
});