@@ -315,6 +315,7 @@ void runNullSafeSharedTests(SetupCompilerOptions setup, TestDriver driver) {
315
315
'Symbol(C.field): 42, Symbol(_field): 0}' );
316
316
});
317
317
});
318
+
318
319
group ('Named arguments anywhere' , () {
319
320
var source = r'''
320
321
String topLevelMethod(int param1, String param2,
@@ -390,6 +391,155 @@ void runNullSafeSharedTests(SetupCompilerOptions setup, TestDriver driver) {
390
391
expectedResult: '1, two, 3, four' );
391
392
});
392
393
});
394
+
395
+ group ('Enums' , () {
396
+ var source = r'''
397
+ enum E {id1, id2, id3}
398
+
399
+ enum E2 {id1, id2, id3}
400
+
401
+ main() {
402
+ var e = E.id2;
403
+ // Breakpoint: bp
404
+ print('hello world');
405
+ }
406
+ ''' ;
407
+
408
+ setUpAll (() async {
409
+ await driver.initSource (setup, source);
410
+ });
411
+
412
+ tearDownAll (() async {
413
+ await driver.cleanupTest ();
414
+ });
415
+
416
+ test ('evaluate to the correct string' , () async {
417
+ await driver.check (
418
+ breakpointId: 'bp' ,
419
+ expression: 'E.id2.toString()' ,
420
+ expectedResult: 'E.id2' );
421
+ });
422
+ test ('evaluate to the correct index' , () async {
423
+ await driver.check (
424
+ breakpointId: 'bp' , expression: 'E.id3.index' , expectedResult: '2' );
425
+ });
426
+ test ('compare properly against themselves' , () async {
427
+ await driver.check (
428
+ breakpointId: 'bp' ,
429
+ expression: 'e == E.id2 && E.id2 == E.id2' ,
430
+ expectedResult: 'true' );
431
+ });
432
+ test ('compare properly against other enums' , () async {
433
+ await driver.check (
434
+ breakpointId: 'bp' ,
435
+ expression: 'e != E2.id2 && E.id2 != E2.id2' ,
436
+ expectedResult: 'true' );
437
+ });
438
+ });
439
+
440
+ group ('Enhanced enums' , () {
441
+ var source = r'''
442
+ enum E<T> with M {
443
+ id_int<int>(0),
444
+ id_bool<bool>(true),
445
+ id_string<String>('hello world', n: 13);
446
+
447
+ final T field;
448
+ final num n;
449
+ static const constStaticField = id_string;
450
+
451
+ const E(T arg0, {num? n}) : this.field = arg0, this.n = n ?? 42;
452
+
453
+ T get fieldGetter => field;
454
+ num instanceMethod() => n;
455
+ }
456
+
457
+ enum E2 with M {
458
+ v1, v2, id_string;
459
+ int get index => 10;
460
+ }
461
+
462
+ mixin M on Enum {
463
+ int mixinMethod() => index * 100;
464
+ }
465
+
466
+ main() {
467
+ var e = E.id_string;
468
+ // Breakpoint: bp
469
+ print('hello world');
470
+ }
471
+ ''' ;
472
+
473
+ setUpAll (() async {
474
+ await driver
475
+ .initSource (setup, source, experiments: {'enhanced-enums' : true });
476
+ });
477
+
478
+ tearDownAll (() async {
479
+ await driver.cleanupTest ();
480
+ });
481
+
482
+ test ('evaluate to the correct string' , () async {
483
+ await driver.check (
484
+ breakpointId: 'bp' ,
485
+ expression: 'E.id_string.toString()' ,
486
+ expectedResult: 'E.id_string' );
487
+ });
488
+ test ('evaluate to the correct index' , () async {
489
+ await driver.check (
490
+ breakpointId: 'bp' ,
491
+ expression: 'E.id_string.index' ,
492
+ expectedResult: '2' );
493
+ });
494
+ test ('compare properly against themselves' , () async {
495
+ await driver.check (
496
+ breakpointId: 'bp' ,
497
+ expression: 'e == E.id_string && E.id_string == E.id_string' ,
498
+ expectedResult: 'true' );
499
+ });
500
+ test ('compare properly against other enums' , () async {
501
+ await driver.check (
502
+ breakpointId: 'bp' ,
503
+ expression: 'e != E2.id_string && E.id_string != E2.id_string' ,
504
+ expectedResult: 'true' );
505
+ });
506
+ test ('with instance methods' , () async {
507
+ await driver.check (
508
+ breakpointId: 'bp' ,
509
+ expression: 'E.id_bool.instanceMethod()' ,
510
+ expectedResult: '42' );
511
+ });
512
+ test ('with instance methods from local instance' , () async {
513
+ await driver.check (
514
+ breakpointId: 'bp' ,
515
+ expression: 'e.instanceMethod()' ,
516
+ expectedResult: '13' );
517
+ });
518
+ test ('with getters' , () async {
519
+ await driver.check (
520
+ breakpointId: 'bp' ,
521
+ expression: 'E.id_int.fieldGetter' ,
522
+ expectedResult: '0' );
523
+ });
524
+ test ('with getters from local instance' , () async {
525
+ await driver.check (
526
+ breakpointId: 'bp' ,
527
+ expression: 'e.fieldGetter' ,
528
+ expectedResult: 'hello world' );
529
+ });
530
+ test ('with mixin calls' , () async {
531
+ await driver.check (
532
+ breakpointId: 'bp' ,
533
+ expression: 'E.id_string.mixinMethod()' ,
534
+ expectedResult: '200' );
535
+ });
536
+ test ('with mixin calls through overridden indices' , () async {
537
+ await driver.check (
538
+ breakpointId: 'bp' ,
539
+ expression: 'E2.v2.mixinMethod()' ,
540
+ expectedResult: '1000' );
541
+ });
542
+ });
393
543
}
394
544
395
545
/// Shared tests that are valid in legacy (before 2.12) and are agnostic to
0 commit comments