-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathconditional-loop.js
54 lines (48 loc) · 1.02 KB
/
conditional-loop.js
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
var test = require('tape')
var parse = require('../parser')
test('conditional loop', function (t) {
t.plan(3)
var statement = parse('while true; do echo 1; done')[0]
t.deepEqual(statement, {
type: "whileLoop",
test: [{
type: "command",
command: {
type: "literal",
value: "true"
},
args: [],
redirects: [],
env: {},
control: ";",
next: null
}],
body: [{
type: "command",
command: {
type: "literal",
value: "echo"
},
args: [
{
type: "literal",
value: "1"
}],
redirects: [],
env: {},
control: ";",
next: null
}],
next: null,
control: ';'
}, "can parse a while loop")
var ast = parse('while true && false; do blah; done')
t.ok(ast[0].test[0].next, "Can use chaining in test-commands")
try {
var input = "while echo 1 && do blah; done";
parse(input)
} catch (err) {
t.pass('make sure this is a syntax error')
}
t.end()
})