saambarati1@gmail.com | 1595250 | 2015-02-23 22:10:51 +0000 | [diff] [blame] | 1 | load("./driver/driver.js"); |
| 2 | |
| 3 | function foo(){ } |
| 4 | function bar(){ } |
| 5 | function baz(){ } |
| 6 | |
| 7 | function testConditionalBasic(x) { |
| 8 | return x ? 10 : 20; |
| 9 | } |
| 10 | |
| 11 | |
| 12 | testConditionalBasic(false); |
| 13 | checkBasicBlock(testConditionalBasic, "x", ShouldHaveExecuted); |
| 14 | checkBasicBlock(testConditionalBasic, "20", ShouldHaveExecuted); |
| 15 | checkBasicBlock(testConditionalBasic, "10", ShouldNotHaveExecuted); |
| 16 | |
| 17 | testConditionalBasic(true); |
| 18 | checkBasicBlock(testConditionalBasic, "10", ShouldHaveExecuted); |
| 19 | |
| 20 | |
| 21 | function testConditionalFunctionCall(x, y) { |
| 22 | x ? y ? foo() |
| 23 | : baz() |
| 24 | : bar() |
| 25 | } |
| 26 | testConditionalFunctionCall(false, false); |
saambarati1@gmail.com | c497d15 | 2015-07-17 18:48:30 +0000 | [diff] [blame] | 27 | checkBasicBlock(testConditionalFunctionCall, "x ?", ShouldHaveExecuted); |
saambarati1@gmail.com | 1595250 | 2015-02-23 22:10:51 +0000 | [diff] [blame] | 28 | checkBasicBlock(testConditionalFunctionCall, "? y", ShouldHaveExecuted); |
| 29 | checkBasicBlock(testConditionalFunctionCall, "bar", ShouldHaveExecuted); |
| 30 | checkBasicBlock(testConditionalFunctionCall, ": bar", ShouldHaveExecuted); |
saambarati1@gmail.com | c497d15 | 2015-07-17 18:48:30 +0000 | [diff] [blame] | 31 | checkBasicBlock(testConditionalFunctionCall, "y ?", ShouldNotHaveExecuted); |
saambarati1@gmail.com | 1595250 | 2015-02-23 22:10:51 +0000 | [diff] [blame] | 32 | checkBasicBlock(testConditionalFunctionCall, "? foo", ShouldNotHaveExecuted); |
| 33 | checkBasicBlock(testConditionalFunctionCall, "foo", ShouldNotHaveExecuted); |
| 34 | checkBasicBlock(testConditionalFunctionCall, "baz", ShouldNotHaveExecuted); |
| 35 | |
| 36 | testConditionalFunctionCall(true, false); |
saambarati1@gmail.com | c497d15 | 2015-07-17 18:48:30 +0000 | [diff] [blame] | 37 | checkBasicBlock(testConditionalFunctionCall, "y ?", ShouldHaveExecuted); |
saambarati1@gmail.com | 1595250 | 2015-02-23 22:10:51 +0000 | [diff] [blame] | 38 | checkBasicBlock(testConditionalFunctionCall, "? foo", ShouldHaveExecuted); |
| 39 | checkBasicBlock(testConditionalFunctionCall, ": baz", ShouldHaveExecuted); |
| 40 | checkBasicBlock(testConditionalFunctionCall, "baz", ShouldHaveExecuted); |
| 41 | checkBasicBlock(testConditionalFunctionCall, "foo", ShouldNotHaveExecuted); |
| 42 | |
| 43 | testConditionalFunctionCall(true, true); |
| 44 | checkBasicBlock(testConditionalFunctionCall, "foo", ShouldHaveExecuted); |