@@ -64,6 +64,46 @@ main() {
64
64
// TODO(nshahan) Merge with [runAgnosticSharedTests] after we no longer need to
65
65
// test support for evaluation in legacy (pre-null safety) code.
66
66
void runNullSafeSharedTests (SetupCompilerOptions setup, TestDriver driver) {
67
+ group ('Exceptions' , () {
68
+ const exceptionSource = r'''
69
+ void main() {
70
+ try {
71
+ throw Exception('meow!');
72
+ } catch (e, s) {
73
+ // Breakpoint: bp
74
+ print('Cat says: \$e:\$s');
75
+ }
76
+ }
77
+ ''' ;
78
+
79
+ setUpAll (() async {
80
+ await driver.initSource (setup, exceptionSource);
81
+ });
82
+
83
+ tearDownAll (() async {
84
+ await driver.cleanupTest ();
85
+ });
86
+
87
+ test ('error' , () async {
88
+ await driver.check (
89
+ breakpointId: 'bp' ,
90
+ expression: 'e.toString()' ,
91
+ expectedResult: 'meow!' );
92
+ });
93
+
94
+ test ('stack trace' , () async {
95
+ await driver.check (
96
+ breakpointId: 'bp' , expression: 's.toString()' , expectedResult: '' );
97
+ });
98
+
99
+ test ('scope' , () async {
100
+ await driver.checkScope (breakpointId: 'bp' , expectedScope: {
101
+ 'e' : 'e' ,
102
+ 's' : 's' ,
103
+ });
104
+ });
105
+ });
106
+
67
107
group ('Records' , () {
68
108
const recordsSource = '''
69
109
void main() {
@@ -77,8 +117,7 @@ void runNullSafeSharedTests(SetupCompilerOptions setup, TestDriver driver) {
77
117
''' ;
78
118
79
119
setUpAll (() async {
80
- await driver
81
- .initSource (setup, recordsSource, experiments: {'records' : true });
120
+ await driver.initSource (setup, recordsSource);
82
121
});
83
122
84
123
tearDownAll (() async {
@@ -170,6 +209,121 @@ void runNullSafeSharedTests(SetupCompilerOptions setup, TestDriver driver) {
170
209
});
171
210
});
172
211
212
+ group ('Patterns' , () {
213
+ const patternsSource = r'''
214
+ void main() {
215
+ int foo(Object? obj) {
216
+ switch (obj) {
217
+ case [int a, double b] || [double b, int a]:
218
+ // Breakpoint: bp1
219
+ return a;
220
+ case [int a, String b] || [String a, int b]:
221
+ // Breakpoint: bp2
222
+ return a;
223
+ default:
224
+ // Breakpoint: bp3
225
+ return 0;
226
+ }
227
+ }
228
+
229
+ final one = foo([1,2]);
230
+ final ten = foo([10,'20']);
231
+ final zero = foo(0);
232
+
233
+ // Breakpoint: bp4
234
+ print('$one, $ten, $zero');
235
+ }
236
+ ''' ;
237
+
238
+ setUpAll (() async {
239
+ await driver.initSource (setup, patternsSource);
240
+ });
241
+
242
+ tearDownAll (() async {
243
+ await driver.cleanupTest ();
244
+ });
245
+
246
+ test ('first case match' , () async {
247
+ await driver.check (
248
+ breakpointId: 'bp1' , expression: 'a.toString()' , expectedResult: '1' );
249
+ });
250
+
251
+ test ('second case match' , () async {
252
+ await driver.check (
253
+ breakpointId: 'bp2' ,
254
+ expression: 'a.toString()' ,
255
+ expectedResult: '10' );
256
+ });
257
+
258
+ test ('default case match' , () async {
259
+ await driver.check (
260
+ breakpointId: 'bp3' ,
261
+ expression: 'obj.toString()' ,
262
+ expectedResult: '0' );
263
+ });
264
+
265
+ test ('first case match result' , () async {
266
+ await driver.check (
267
+ breakpointId: 'bp4' ,
268
+ expression: 'one.toString()' ,
269
+ expectedResult: '1' );
270
+ });
271
+
272
+ test ('second case match result' , () async {
273
+ await driver.check (
274
+ breakpointId: 'bp4' ,
275
+ expression: 'ten.toString()' ,
276
+ expectedResult: '10' );
277
+ });
278
+
279
+ test ('default match result' , () async {
280
+ await driver.check (
281
+ breakpointId: 'bp4' ,
282
+ expression: 'zero.toString()' ,
283
+ expectedResult: '0' );
284
+ });
285
+
286
+ // TODO(annagrin): Remove renamed variables here and below after
287
+ // const evaluator stops renaming variables used in cases.
288
+ //
289
+ // Issue: https://github.com/dart-lang/sdk/issues/51554
290
+ test ('first case scope' , () async {
291
+ await driver.checkScope (breakpointId: 'bp1' , expectedScope: {
292
+ 'a' : '1' ,
293
+ 'b' : '2' ,
294
+ r'a$351' : r'a$351' ,
295
+ r'b$351' : r'b$351' ,
296
+ 'obj' : 'obj'
297
+ });
298
+ });
299
+
300
+ test ('second case scope' , () async {
301
+ await driver.checkScope (breakpointId: 'bp2' , expectedScope: {
302
+ 'a' : '10' ,
303
+ 'b' : '10' ,
304
+ r'a$351' : '10' ,
305
+ r'b$351' : '\' 20\' ' ,
306
+ 'obj' : 'obj'
307
+ });
308
+ });
309
+
310
+ test ('default case scope' , () async {
311
+ await driver.checkScope (breakpointId: 'bp3' , expectedScope: {
312
+ 'a' : 'a' ,
313
+ 'b' : 'b' ,
314
+ r'a$351' : r'a$351' ,
315
+ r'b$351' : r'b$351' ,
316
+ 'obj' : '0'
317
+ });
318
+ });
319
+
320
+ test ('result scope' , () async {
321
+ await driver.checkScope (
322
+ breakpointId: 'bp4' ,
323
+ expectedScope: {'foo' : 'foo' , 'one' : '1' , 'ten' : '10' , 'zero' : '0' });
324
+ });
325
+ });
326
+
173
327
group ('Correct null safety mode used' , () {
174
328
var source = '''
175
329
const soundNullSafety = !(<Null>[] is List<int>);
@@ -461,6 +615,11 @@ void runNullSafeSharedTests(SetupCompilerOptions setup, TestDriver driver) {
461
615
expression: 'e != E2.id2 && E.id2 != E2.id2' ,
462
616
expectedResult: 'true' );
463
617
});
618
+ test ('scope' , () async {
619
+ await driver.checkScope (breakpointId: 'bp' , expectedScope: {
620
+ 'e' : 'e' ,
621
+ });
622
+ });
464
623
});
465
624
466
625
group ('Automatically inserted argument null checks' , () {
@@ -699,6 +858,13 @@ void runAgnosticSharedTests(SetupCompilerOptions setup, TestDriver driver) {
699
858
expression: 'this' ,
700
859
expectedError: "Error: Expected identifier, but got 'this'" );
701
860
});
861
+
862
+ test ('scope' , () async {
863
+ await driver.checkScope (breakpointId: 'bp' , expectedScope: {
864
+ r'$this' : '\' 1234\' ' ,
865
+ 'ret' : '1234' ,
866
+ });
867
+ });
702
868
});
703
869
704
870
group ('Expression compiler tests in static function:' , () {
0 commit comments