[tests] Typedef, part of, and mixin 'on' language tests for sealed classes.

Change-Id: Idc72291668d72def5ec4c93ecb77eeea554628b9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/271502
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
diff --git a/tests/language/sealed_class/sealed_class_as_mixin_error_test.dart b/tests/language/sealed_class/sealed_class_as_mixin_error_test.dart
index 856fe4c..afe07f2 100644
--- a/tests/language/sealed_class/sealed_class_as_mixin_error_test.dart
+++ b/tests/language/sealed_class/sealed_class_as_mixin_error_test.dart
@@ -6,7 +6,7 @@
 
 // Error when attempting to mix in a sealed class outside of library.
 
-import 'sealed_class_as_mixin_lib.dart';
+import 'sealed_class_as_mixin_in_lib_error_test.dart';
 
 abstract class OutsideA with SealedClass {}
 //             ^
diff --git a/tests/language/sealed_class/sealed_class_as_mixin_lib.dart b/tests/language/sealed_class/sealed_class_as_mixin_in_lib_error_test.dart
similarity index 73%
rename from tests/language/sealed_class/sealed_class_as_mixin_lib.dart
rename to tests/language/sealed_class/sealed_class_as_mixin_in_lib_error_test.dart
index f2f63a3..ec6ac46 100644
--- a/tests/language/sealed_class/sealed_class_as_mixin_lib.dart
+++ b/tests/language/sealed_class/sealed_class_as_mixin_in_lib_error_test.dart
@@ -4,6 +4,8 @@
 
 // SharedOptions=--enable-experiment=sealed-class
 
+// Error when attempting to mix in a sealed class inside of library.
+
 sealed class SealedClass {
   int nonAbstractFoo = 0;
   abstract int foo;
@@ -12,16 +14,14 @@
 }
 
 abstract class A with SealedClass {}
-
-class AImpl extends A {
-  @override
-  int foo = 1;
-
-  @override
-  int bar(int value) => value + 1;
-}
+// ^
+// [analyzer] unspecified
+// [cfe] unspecified
 
 class B with SealedClass {
+// ^
+// [analyzer] unspecified
+// [cfe] unspecified
   @override
   int nonAbstractFoo = 100;
 
@@ -33,11 +33,6 @@
 }
 
 abstract class C = Object with SealedClass;
-
-class CImpl extends C {
-  @override
-  int foo = 3;
-
-  @override
-  int bar(int value) => value - 1;
-}
+// ^
+// [analyzer] unspecified
+// [cfe] unspecified
diff --git a/tests/language/sealed_class/sealed_class_as_mixin_test.dart b/tests/language/sealed_class/sealed_class_as_mixin_test.dart
deleted file mode 100644
index 46b49b2..0000000
--- a/tests/language/sealed_class/sealed_class_as_mixin_test.dart
+++ /dev/null
@@ -1,65 +0,0 @@
-// Copyright (c) 2022, the Dart project authors.  Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-// SharedOptions=--enable-experiment=sealed-class
-
-// Allow sealed classes to be mixed in by multiple classes in the same library.
-// Additionally, allow their subclasses/subtypes to be used freely.
-
-import "package:expect/expect.dart";
-import 'sealed_class_as_mixin_lib.dart';
-
-class AExtends extends A {
-  @override
-  int foo = 0;
-
-  @override
-  int bar(int value) => value;
-}
-
-class AImplements implements A {
-  @override
-  int nonAbstractFoo = 0;
-
-  @override
-  int foo = 0;
-
-  @override
-  int bar(int value) => value;
-
-  @override
-  int nonAbstractBar(int value) => value;
-}
-
-main() {
-  A a = AImpl();
-  Expect.equals(0, a.nonAbstractFoo);
-  Expect.equals(1, a.foo);
-  Expect.equals(3, a.bar(2));
-  Expect.equals(100, a.nonAbstractBar(0));
-
-  var b = B();
-  Expect.equals(100, b.nonAbstractFoo);
-  Expect.equals(2, b.foo);
-  Expect.equals(2, b.bar(2));
-  Expect.equals(100, b.nonAbstractBar(0));
-
-  C c = CImpl();
-  Expect.equals(0, c.nonAbstractFoo);
-  Expect.equals(3, c.foo);
-  Expect.equals(1, c.bar(2));
-  Expect.equals(100, c.nonAbstractBar(0));
-
-  var aExtends = AExtends();
-  Expect.equals(0, aExtends.nonAbstractFoo);
-  Expect.equals(0, aExtends.foo);
-  Expect.equals(0, aExtends.bar(0));
-  Expect.equals(100, aExtends.nonAbstractBar(0));
-
-  var aImplements = AImplements();
-  Expect.equals(0, aImplements.nonAbstractFoo);
-  Expect.equals(0, aImplements.foo);
-  Expect.equals(0, aImplements.bar(0));
-  Expect.equals(0, aImplements.nonAbstractBar(0));
-}
diff --git a/tests/language/sealed_class/sealed_class_mixin_on_lib.dart b/tests/language/sealed_class/sealed_class_mixin_on_lib.dart
new file mode 100644
index 0000000..647703f
--- /dev/null
+++ b/tests/language/sealed_class/sealed_class_mixin_on_lib.dart
@@ -0,0 +1,11 @@
+// Copyright (c) 2022, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// SharedOptions=--enable-experiment=sealed-class
+
+sealed class SealedClass {}
+
+abstract class A extends SealedClass {}
+
+class B extends SealedClass {}
\ No newline at end of file
diff --git a/tests/language/sealed_class/sealed_class_mixin_on_test.dart b/tests/language/sealed_class/sealed_class_mixin_on_test.dart
new file mode 100644
index 0000000..c3c13a1
--- /dev/null
+++ b/tests/language/sealed_class/sealed_class_mixin_on_test.dart
@@ -0,0 +1,23 @@
+// Copyright (c) 2022, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// SharedOptions=--enable-experiment=sealed-class
+
+// Allow a sealed type to appear in the "on" clause of a mixin declaration in
+// another library.
+
+import "package:expect/expect.dart";
+import 'sealed_class_mixin_on_lib.dart';
+
+mixin MA on SealedClass {}
+mixin MB on SealedClass {}
+
+class C extends A with MA, MB {
+  int foo = 0;
+}
+
+main() {
+  var c = C();
+  Expect.equals(0, c.foo);
+}
diff --git a/tests/language/sealed_class/sealed_class_part_lib.dart b/tests/language/sealed_class/sealed_class_part_lib.dart
new file mode 100644
index 0000000..361deef
--- /dev/null
+++ b/tests/language/sealed_class/sealed_class_part_lib.dart
@@ -0,0 +1,14 @@
+// Copyright (c) 2022, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// SharedOptions=--enable-experiment=sealed-class
+
+part of 'sealed_class_part_test.dart';
+
+class A extends SealedClass {}
+
+class B implements SealedClass {
+  @override
+  int foo = 1;
+}
diff --git a/tests/language/sealed_class/sealed_class_part_test.dart b/tests/language/sealed_class/sealed_class_part_test.dart
new file mode 100644
index 0000000..ce62ada
--- /dev/null
+++ b/tests/language/sealed_class/sealed_class_part_test.dart
@@ -0,0 +1,23 @@
+// Copyright (c) 2022, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// SharedOptions=--enable-experiment=sealed-class
+
+// Allow extending and implementing sealed classes in a part file of
+// the same library
+
+import "package:expect/expect.dart";
+part 'sealed_class_part_lib.dart';
+
+sealed class SealedClass {
+  int foo = 0;
+}
+
+main() {
+  var a = A();
+  Expect.equals(0, a.foo);
+
+  var b = B();
+  Expect.equals(1, b.foo);
+}
diff --git a/tests/language/sealed_class/sealed_class_sealed_subtype_test.dart b/tests/language/sealed_class/sealed_class_sealed_subtype_test.dart
new file mode 100644
index 0000000..0df4ff3
--- /dev/null
+++ b/tests/language/sealed_class/sealed_class_sealed_subtype_test.dart
@@ -0,0 +1,43 @@
+// Copyright (c) 2022, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// SharedOptions=--enable-experiment=sealed-class
+
+// Allow subtypes of a sealed class or mixin to be sealed as well.
+import "package:expect/expect.dart";
+
+sealed class SealedClass {
+  int foo = 0;
+}
+sealed class A extends SealedClass {}
+sealed class B implements SealedClass {
+  @override
+  int foo = 1;
+}
+
+sealed mixin SealedMixin {
+  int foo = 0;
+}
+sealed class AMixin with SealedMixin {}
+sealed class BMixin = Object with SealedMixin;
+
+// Used for trivial runtime tests of the sealed subtypes.
+class AConcrete extends A {}
+class BConcrete extends B {}
+class AMixinConcrete extends AMixin {}
+class BMixinConcrete extends BMixin {}
+
+main() {
+  var a = AConcrete();
+  Expect.equals(0, a.foo);
+
+  var b = BConcrete();
+  Expect.equals(1, b.foo);
+
+  var amixin = AMixinConcrete();
+  Expect.equals(0, amixin.foo);
+
+  var bmixin = BMixinConcrete();
+  Expect.equals(0, bmixin.foo);
+}
\ No newline at end of file
diff --git a/tests/language/sealed_class/sealed_class_typedef_error_test.dart b/tests/language/sealed_class/sealed_class_typedef_error_test.dart
new file mode 100644
index 0000000..4a6414a
--- /dev/null
+++ b/tests/language/sealed_class/sealed_class_typedef_error_test.dart
@@ -0,0 +1,23 @@
+// Copyright (c) 2022, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// SharedOptions=--enable-experiment=sealed-class
+
+// Error when attempting to extend or implement typedef sealed class
+// outside of its library.
+
+import 'sealed_class_typedef_lib.dart';
+
+class ATypeDef extends SealedClassTypeDef {}
+//    ^
+// [analyzer] unspecified
+// [cfe] Sealed class 'SealedClass' can't be extended, implemented, or mixed in outside of its library.
+
+class BTypeDef implements SealedClassTypeDef {
+//    ^
+// [analyzer] unspecified
+// [cfe] Sealed class 'SealedClass' can't be extended, implemented, or mixed in outside of its library.
+  @override
+  int foo = 1;
+}
diff --git a/tests/language/sealed_class/sealed_class_typedef_lib.dart b/tests/language/sealed_class/sealed_class_typedef_lib.dart
new file mode 100644
index 0000000..4ec6181
--- /dev/null
+++ b/tests/language/sealed_class/sealed_class_typedef_lib.dart
@@ -0,0 +1,18 @@
+// Copyright (c) 2022, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// SharedOptions=--enable-experiment=sealed-class
+
+sealed class SealedClass {
+  int foo = 0;
+}
+
+typedef SealedClassTypeDef = SealedClass;
+
+class A extends SealedClassTypeDef {}
+
+class B implements SealedClassTypeDef {
+  @override
+  int foo = 1;
+}
diff --git a/tests/language/sealed_class/sealed_class_typedef_outside_of_library_lib.dart b/tests/language/sealed_class/sealed_class_typedef_outside_of_library_lib.dart
new file mode 100644
index 0000000..4a8ccb5
--- /dev/null
+++ b/tests/language/sealed_class/sealed_class_typedef_outside_of_library_lib.dart
@@ -0,0 +1,17 @@
+// Copyright (c) 2022, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// SharedOptions=--enable-experiment=sealed-class
+
+import 'sealed_class_typedef_outside_of_library_lib2.dart';
+
+sealed class SealedClass {
+  int foo = 0;
+}
+
+class A extends ATypeDef {}
+
+class B implements ATypeDef {
+  int foo = 1;
+}
diff --git a/tests/language/sealed_class/sealed_class_typedef_outside_of_library_lib2.dart b/tests/language/sealed_class/sealed_class_typedef_outside_of_library_lib2.dart
new file mode 100644
index 0000000..07695bb
--- /dev/null
+++ b/tests/language/sealed_class/sealed_class_typedef_outside_of_library_lib2.dart
@@ -0,0 +1,9 @@
+// Copyright (c) 2022, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// SharedOptions=--enable-experiment=sealed-class
+
+import "sealed_class_typedef_outside_of_library_lib.dart";
+
+typedef ATypeDef = SealedClass;
diff --git a/tests/language/sealed_class/sealed_class_typedef_outside_of_library_test.dart b/tests/language/sealed_class/sealed_class_typedef_outside_of_library_test.dart
new file mode 100644
index 0000000..5873d13
--- /dev/null
+++ b/tests/language/sealed_class/sealed_class_typedef_outside_of_library_test.dart
@@ -0,0 +1,18 @@
+// Copyright (c) 2022, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// SharedOptions=--enable-experiment=sealed-class
+
+// Allow typedef in different library, used by class in library.
+
+import "package:expect/expect.dart";
+import 'sealed_class_typedef_outside_of_library_lib.dart';
+
+main() {
+  var a = A();
+  Expect.equals(0, a.foo);
+
+  var b = B();
+  Expect.equals(1, b.foo);
+}
diff --git a/tests/language/sealed_class/sealed_class_typedef_test.dart b/tests/language/sealed_class/sealed_class_typedef_test.dart
new file mode 100644
index 0000000..deaf885
--- /dev/null
+++ b/tests/language/sealed_class/sealed_class_typedef_test.dart
@@ -0,0 +1,19 @@
+// Copyright (c) 2022, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// SharedOptions=--enable-experiment=sealed-class
+
+// Allow typedef sealed classes to be extended, implemented, mixed in by
+// multiple classes in the same library.
+
+import "package:expect/expect.dart";
+import 'sealed_class_typedef_lib.dart';
+
+main() {
+  var a = A();
+  Expect.equals(0, a.foo);
+
+  var b = B();
+  Expect.equals(1, b.foo);
+}
diff --git a/tests/language/sealed_class/sealed_class_typedef_used_outside_error_test.dart b/tests/language/sealed_class/sealed_class_typedef_used_outside_error_test.dart
new file mode 100644
index 0000000..bb84809
--- /dev/null
+++ b/tests/language/sealed_class/sealed_class_typedef_used_outside_error_test.dart
@@ -0,0 +1,25 @@
+// Copyright (c) 2022, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// SharedOptions=--enable-experiment=sealed-class
+
+// Error when trying to extend or implement a typedef sealed class outside of
+// the sealed class' library when the typedef is also outside the sealed class
+// library.
+
+import 'sealed_class_typedef_used_outside_lib.dart';
+
+typedef ATypeDef = SealedClass;
+
+class A extends ATypeDef {}
+//    ^
+// [analyzer] unspecified
+// [cfe] Sealed class 'SealedClass' can't be extended, implemented, or mixed in outside of its library.
+
+class B implements ATypeDef {
+//    ^
+// [analyzer] unspecified
+// [cfe] Sealed class 'SealedClass' can't be extended, implemented, or mixed in outside of its library.
+  int foo = 1;
+}
diff --git a/tests/language/sealed_class/sealed_class_typedef_used_outside_lib.dart b/tests/language/sealed_class/sealed_class_typedef_used_outside_lib.dart
new file mode 100644
index 0000000..535cc5b
--- /dev/null
+++ b/tests/language/sealed_class/sealed_class_typedef_used_outside_lib.dart
@@ -0,0 +1,9 @@
+// Copyright (c) 2022, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// SharedOptions=--enable-experiment=sealed-class
+
+sealed class SealedClass {
+  int foo = 0;
+}
diff --git a/tests/language/sealed_class/sealed_mixin_typedef_error_test.dart b/tests/language/sealed_class/sealed_mixin_typedef_error_test.dart
new file mode 100644
index 0000000..c7663ce
--- /dev/null
+++ b/tests/language/sealed_class/sealed_mixin_typedef_error_test.dart
@@ -0,0 +1,14 @@
+// Copyright (c) 2022, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// SharedOptions=--enable-experiment=sealed-class
+
+// Error when attempting to mix in a typedef sealed mixin outside of its library
+
+import 'sealed_mixin_typedef_lib.dart';
+
+class ATypeDef with SealedMixinTypeDef {}
+//    ^
+// [analyzer] unspecified
+// [cfe] Sealed mixin 'SealedMixin' can't be mixed in outside of its library.
diff --git a/tests/language/sealed_class/sealed_mixin_typedef_lib.dart b/tests/language/sealed_class/sealed_mixin_typedef_lib.dart
new file mode 100644
index 0000000..5047f41
--- /dev/null
+++ b/tests/language/sealed_class/sealed_mixin_typedef_lib.dart
@@ -0,0 +1,13 @@
+// Copyright (c) 2022, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// SharedOptions=--enable-experiment=sealed-class
+
+sealed mixin SealedMixin {
+  int foo = 0;
+}
+
+typedef SealedMixinTypeDef = SealedMixin;
+
+class A with SealedMixinTypeDef {}
diff --git a/tests/language/sealed_class/sealed_mixin_typedef_test.dart b/tests/language/sealed_class/sealed_mixin_typedef_test.dart
new file mode 100644
index 0000000..9c63a5f
--- /dev/null
+++ b/tests/language/sealed_class/sealed_mixin_typedef_test.dart
@@ -0,0 +1,15 @@
+// Copyright (c) 2022, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// SharedOptions=--enable-experiment=sealed-class
+
+// Allow typedef sealed mixins to be mixed in by classes in the same library.
+
+import "package:expect/expect.dart";
+import 'sealed_mixin_typedef_lib.dart';
+
+main() {
+  var a = A();
+  Expect.equals(0, a.foo);
+}