1 load("./driver/driver.js");
8 if (x < 10) { foo(); } else if (x < 20) { bar(); } else { baz() }
11 // Note, the check will be against the basic block that contains the first matched character.
12 // So in this following case, the block that contains the '{'.
13 checkBasicBlock(testIf, "{ foo", ShouldHaveExecuted);
14 // In this case, it will test the basic block that contains the ' ' character.
15 checkBasicBlock(testIf, " foo", ShouldHaveExecuted);
16 checkBasicBlock(testIf, "} else if", ShouldHaveExecuted);
17 checkBasicBlock(testIf, "else if", ShouldNotHaveExecuted);
18 checkBasicBlock(testIf, "{ bar", ShouldNotHaveExecuted);
19 checkBasicBlock(testIf, " bar", ShouldNotHaveExecuted);
20 checkBasicBlock(testIf, "else {", ShouldNotHaveExecuted);
21 checkBasicBlock(testIf, "{ baz", ShouldNotHaveExecuted);
22 checkBasicBlock(testIf, " baz", ShouldNotHaveExecuted);
24 checkBasicBlock(testIf, "else if (x < 20)", ShouldHaveExecuted);
25 checkBasicBlock(testIf, "{ bar", ShouldNotHaveExecuted);
26 checkBasicBlock(testIf, " bar", ShouldNotHaveExecuted);
27 checkBasicBlock(testIf, "else {", ShouldHaveExecuted);
28 checkBasicBlock(testIf, "{ baz", ShouldHaveExecuted);
29 checkBasicBlock(testIf, " baz", ShouldHaveExecuted);
31 checkBasicBlock(testIf, "{ bar", ShouldHaveExecuted);
32 checkBasicBlock(testIf, " bar", ShouldHaveExecuted);
34 function testForRegular(x) {
35 for (var i = 0; i < x; i++) { foo(); } bar();
38 checkBasicBlock(testForRegular, "{ foo", ShouldNotHaveExecuted);
39 checkBasicBlock(testForRegular, "} bar", ShouldNotHaveExecuted);
40 checkBasicBlock(testForRegular, " bar", ShouldHaveExecuted);
42 checkBasicBlock(testForRegular, "{ foo", ShouldHaveExecuted);
43 checkBasicBlock(testForRegular, "} bar", ShouldHaveExecuted);
45 function testForIn(x) {
46 for (var i in x) { foo(); } bar();
49 checkBasicBlock(testForIn, "{ foo", ShouldNotHaveExecuted);
50 checkBasicBlock(testForIn, "} bar", ShouldNotHaveExecuted);
51 checkBasicBlock(testForIn, " bar", ShouldHaveExecuted);
53 checkBasicBlock(testForIn, "{ foo", ShouldHaveExecuted);
54 checkBasicBlock(testForIn, "} bar", ShouldHaveExecuted);
56 function testForOf(x) {
57 for (var i of x) { foo(); } bar();
60 checkBasicBlock(testForOf, "{ foo", ShouldNotHaveExecuted);
61 checkBasicBlock(testForOf, " foo", ShouldNotHaveExecuted);
62 checkBasicBlock(testForOf, "} bar", ShouldNotHaveExecuted);
63 checkBasicBlock(testForOf, " bar", ShouldHaveExecuted);
65 checkBasicBlock(testForOf, "{ foo", ShouldHaveExecuted);
66 checkBasicBlock(testForOf, "} bar", ShouldHaveExecuted);
68 function testWhile(x) {
69 var i = 0; while (i++ < x) { foo(); } bar();
72 checkBasicBlock(testWhile, "{ foo", ShouldNotHaveExecuted);
73 checkBasicBlock(testWhile, " foo", ShouldNotHaveExecuted);
74 checkBasicBlock(testWhile, "} bar", ShouldNotHaveExecuted);
75 checkBasicBlock(testWhile, " bar", ShouldHaveExecuted);
77 checkBasicBlock(testWhile, "{ foo", ShouldHaveExecuted);
78 checkBasicBlock(testWhile, "} bar", ShouldHaveExecuted);
83 function testIfNoBraces(x) {
84 if (x < 10) foo(); else if (x < 20) bar(); else baz();
87 checkBasicBlock(testIfNoBraces, "foo", ShouldHaveExecuted);
88 checkBasicBlock(testIfNoBraces, " foo", ShouldHaveExecuted);
89 checkBasicBlock(testIfNoBraces, "; else if", ShouldHaveExecuted);
90 checkBasicBlock(testIfNoBraces, " else if", ShouldNotHaveExecuted);
91 checkBasicBlock(testIfNoBraces, " bar", ShouldNotHaveExecuted);
92 checkBasicBlock(testIfNoBraces, "bar", ShouldNotHaveExecuted);
93 checkBasicBlock(testIfNoBraces, "else baz", ShouldNotHaveExecuted);
94 checkBasicBlock(testIfNoBraces, "baz", ShouldNotHaveExecuted);
96 checkBasicBlock(testIfNoBraces, "else baz", ShouldHaveExecuted);
97 checkBasicBlock(testIfNoBraces, "baz", ShouldHaveExecuted);
98 checkBasicBlock(testIfNoBraces, "; else baz", ShouldNotHaveExecuted);
99 checkBasicBlock(testIfNoBraces, "else if (x < 20)", ShouldHaveExecuted);
100 // Note that the whitespace preceding bar is part of the previous basic block.
101 // An if statement's if-true basic block text offset begins at the start offset
102 // of the if-true block, in this case, just the expression "bar()".
103 checkBasicBlock(testIfNoBraces, " bar", ShouldHaveExecuted);
104 checkBasicBlock(testIfNoBraces, "bar", ShouldNotHaveExecuted);
106 checkBasicBlock(testIfNoBraces, " bar", ShouldHaveExecuted);
107 checkBasicBlock(testIfNoBraces, "bar", ShouldHaveExecuted);
109 function testForRegularNoBraces(x) {
110 for (var i = 0; i < x; i++) foo(); bar();
112 testForRegularNoBraces(0);
113 checkBasicBlock(testForRegularNoBraces, " foo", ShouldHaveExecuted);
114 checkBasicBlock(testForRegularNoBraces, "foo", ShouldNotHaveExecuted);
115 checkBasicBlock(testForRegularNoBraces, "; bar", ShouldNotHaveExecuted);
116 checkBasicBlock(testForRegularNoBraces, " bar", ShouldHaveExecuted);
117 testForRegularNoBraces(1);
118 checkBasicBlock(testForRegularNoBraces, " foo", ShouldHaveExecuted);
119 checkBasicBlock(testForRegularNoBraces, "foo", ShouldHaveExecuted);
120 checkBasicBlock(testForRegularNoBraces, " bar", ShouldHaveExecuted);
122 function testForInNoBraces(x) {
123 for (var i in x) foo(); bar();
125 testForInNoBraces({});
126 checkBasicBlock(testForInNoBraces, " foo", ShouldHaveExecuted);
127 checkBasicBlock(testForInNoBraces, "foo", ShouldNotHaveExecuted);
128 checkBasicBlock(testForInNoBraces, "; bar", ShouldNotHaveExecuted);
129 checkBasicBlock(testForInNoBraces, " bar", ShouldHaveExecuted);
130 testForInNoBraces({foo: 20});
131 checkBasicBlock(testForInNoBraces, " foo", ShouldHaveExecuted);
132 checkBasicBlock(testForInNoBraces, "foo", ShouldHaveExecuted);
133 checkBasicBlock(testForInNoBraces, "; bar", ShouldHaveExecuted);
135 function testForOfNoBraces(x) {
136 for (var i of x) foo(); bar();
138 testForOfNoBraces([]);
139 checkBasicBlock(testForOfNoBraces, " foo", ShouldHaveExecuted);
140 checkBasicBlock(testForOfNoBraces, "foo", ShouldNotHaveExecuted);
141 checkBasicBlock(testForOfNoBraces, "; bar", ShouldNotHaveExecuted);
142 checkBasicBlock(testForOfNoBraces, " bar", ShouldHaveExecuted);
143 testForOfNoBraces([20]);
144 checkBasicBlock(testForOfNoBraces, " foo", ShouldHaveExecuted);
145 checkBasicBlock(testForOfNoBraces, "foo", ShouldHaveExecuted);
146 checkBasicBlock(testForOfNoBraces, "; bar", ShouldHaveExecuted);
148 function testWhileNoBraces(x) {
149 var i = 0; while (i++ < x) foo(); bar();
151 testWhileNoBraces(0);
152 checkBasicBlock(testWhileNoBraces, " foo", ShouldHaveExecuted);
153 checkBasicBlock(testWhileNoBraces, "foo", ShouldNotHaveExecuted);
154 checkBasicBlock(testWhileNoBraces, "; bar", ShouldNotHaveExecuted);
155 checkBasicBlock(testWhileNoBraces, " bar", ShouldHaveExecuted);
156 testWhileNoBraces(1);
157 checkBasicBlock(testWhileNoBraces, " foo", ShouldHaveExecuted);
158 checkBasicBlock(testWhileNoBraces, "foo", ShouldHaveExecuted);
159 checkBasicBlock(testWhileNoBraces, "; bar", ShouldHaveExecuted);