|
31 | 31 | /**
|
32 | 32 | * Tests for {@link MustBeReachingVariableDef}.
|
33 | 33 | *
|
| 34 | + * <p>Tests in this class look for the labels 'D:' and 'U:' in the input code and check whether the |
| 35 | + * definition of a var `x` at label `D:` is the must-reaching definition for its use at label `U:`. |
34 | 36 | */
|
35 | 37 | @RunWith(JUnit4.class)
|
36 | 38 | public final class MustBeReachingVariableDefTest {
|
@@ -76,14 +78,31 @@ public void testLoops() {
|
76 | 78 | public void testConditional() {
|
77 | 79 | assertMatch("var x=0,y; D:(x=1)&&y; U:x");
|
78 | 80 | assertNotMatch("var x=0,y; D:y&&(x=1); U:x");
|
| 81 | + assertNotMatch("D:var x=0; var y; y&&(x=1); U:x"); |
79 | 82 | }
|
80 | 83 |
|
81 | 84 | @Test
|
82 | 85 | public void nullishCoalesce() {
|
83 |
| - // LHS is always executed so the definition of x = 1 must be reached |
| 86 | + // LHS is always executed so the definition of x = 1 must be reached |
84 | 87 | assertMatch("var x=0,y; D:(x=1)??y; U:x");
|
85 | 88 | // definitions in RHS are not always executed
|
86 |
| - assertNotMatch("var x=0,y; D:y??(x=1); U:x"); |
| 89 | + assertNotMatch("var x=0; var y; D:y??(x=1); U:x"); |
| 90 | + assertNotMatch("D:var x=0; var y; y??(x=1); U:x"); |
| 91 | + } |
| 92 | + |
| 93 | + @Test |
| 94 | + public void optionalChaining() { |
| 95 | + // LHS is always executed so the definition of x = 1 must be reached |
| 96 | + assertMatch("var x=0,y; D:(x=1)?.y; U:x"); |
| 97 | + assertMatch("var x=0,y; D:(x=1)?.[y]; U:x"); |
| 98 | + assertMatch("var x=0,y; D:(x=1)?.(y); U:x"); |
| 99 | + assertMatch("var x=0,y,z; D:z(x=1)?.y; U:x"); |
| 100 | + assertMatch("var x=0,y,z; D:z[x=1]?.y; U:x"); |
| 101 | + |
| 102 | + // definitions in RHS are not always executed |
| 103 | + assertNotMatch("var x = 0,y; D:y?.(x=1); U:x"); |
| 104 | + assertNotMatch("D:var x = 0; var y; y?.(x=1); U:x"); |
| 105 | + assertNotMatch("var x=0,y; D:y?.[x=1]; U:x"); |
87 | 106 | }
|
88 | 107 |
|
89 | 108 | @Test
|
|
0 commit comments