| OLD | NEW |
| (Empty) | |
| 1 import 'package:test/test.dart'; |
| 2 |
| 3 import 'helper.dart' show check; |
| 4 |
| 5 main() { |
| 6 test('simple switch statement', () { |
| 7 String code = ''' |
| 8 main() { |
| 9 int x = 2; |
| 10 switch(x) { |
| 11 case 1: |
| 12 print('spider'); |
| 13 break; |
| 14 case 2: |
| 15 print('grasshopper'); |
| 16 break; |
| 17 } |
| 18 }'''; |
| 19 return check(code); |
| 20 }); |
| 21 |
| 22 test('switch with default', () { |
| 23 String code = ''' |
| 24 main() { |
| 25 int x = 5; |
| 26 switch(x) { |
| 27 case 1: |
| 28 print('spider'); |
| 29 break; |
| 30 case 2: |
| 31 print('grasshopper'); |
| 32 break; |
| 33 default: |
| 34 print('ladybug'); |
| 35 |
| 36 } |
| 37 }'''; |
| 38 return check(code); |
| 39 }); |
| 40 |
| 41 /* |
| 42 // TODO(efortuna): Uncomment. Because of patch file weirdness, the original |
| 43 // SSA vs the Kernel version is instantiating a subclass of the |
| 44 // FallThroughError, so it produces slightly different code. Fix that. |
| 45 test('switch with fall through error', () { |
| 46 String code = ''' |
| 47 main() { |
| 48 int x = 2; |
| 49 switch(x) { |
| 50 case 1: |
| 51 print('spider'); |
| 52 break; |
| 53 case 2: |
| 54 print('grasshopper'); |
| 55 case 3: |
| 56 print('ant'); |
| 57 break; |
| 58 default: |
| 59 print('ladybug'); |
| 60 } |
| 61 }'''; |
| 62 return check(code); |
| 63 }); |
| 64 */ |
| 65 test('switch with multi-case branch', () { |
| 66 String code = ''' |
| 67 main() { |
| 68 int x = 3; |
| 69 switch(x) { |
| 70 case 1: |
| 71 print('spider'); |
| 72 break; |
| 73 case 2: |
| 74 case 3: |
| 75 case 4: |
| 76 print('grasshopper'); |
| 77 print('ant'); |
| 78 break; |
| 79 } |
| 80 }'''; |
| 81 return check(code); |
| 82 }); |
| 83 |
| 84 test('switch with weird fall-through end case', () { |
| 85 String code = ''' |
| 86 main() { |
| 87 int x = 6; |
| 88 switch(x) { |
| 89 case 1: |
| 90 print('spider'); |
| 91 break; |
| 92 case 5: |
| 93 print('beetle'); |
| 94 break; |
| 95 case 6: |
| 96 } |
| 97 }'''; |
| 98 return check(code); |
| 99 }); |
| 100 |
| 101 test('switch with labeled continue', () { |
| 102 String code = ''' |
| 103 main() { |
| 104 int x = 1; |
| 105 switch(x) { |
| 106 case 1: |
| 107 print('spider'); |
| 108 continue world; |
| 109 case 5: |
| 110 print('beetle'); |
| 111 break; |
| 112 world: |
| 113 case 6: |
| 114 print('cricket'); |
| 115 break; |
| 116 default: |
| 117 print('bat'); |
| 118 } |
| 119 }'''; |
| 120 return check(code); |
| 121 }); |
| 122 |
| 123 test('switch with continue to fall through', () { |
| 124 String code = ''' |
| 125 main() { |
| 126 int x = 1; |
| 127 switch(x) { |
| 128 case 1: |
| 129 print('spider'); |
| 130 continue world; |
| 131 world: |
| 132 case 5: |
| 133 print('beetle'); |
| 134 break; |
| 135 case 6: |
| 136 print('cricket'); |
| 137 break; |
| 138 default: |
| 139 print('bat'); |
| 140 } |
| 141 }'''; |
| 142 return check(code); |
| 143 }); |
| 144 |
| 145 test('switch with continue without default case', () { |
| 146 String code = ''' |
| 147 main() { |
| 148 int x = 1; |
| 149 switch(x) { |
| 150 case 1: |
| 151 print('spider'); |
| 152 continue world; |
| 153 world: |
| 154 case 5: |
| 155 print('beetle'); |
| 156 break; |
| 157 case 6: |
| 158 print('cricket'); |
| 159 break; |
| 160 } |
| 161 }'''; |
| 162 return check(code); |
| 163 }); |
| 164 |
| 165 test('switch with continue without default case', () { |
| 166 String code = ''' |
| 167 main() { |
| 168 int x = 8; |
| 169 switch(x) { |
| 170 case 1: |
| 171 print('spider'); |
| 172 continue world; |
| 173 world: |
| 174 case 5: |
| 175 print('beetle'); |
| 176 break; |
| 177 case 6: |
| 178 print('cricket'); |
| 179 break; |
| 180 } |
| 181 }'''; |
| 182 return check(code); |
| 183 }); |
| 184 } |
| OLD | NEW |