Skip to content

Commit

Permalink
#2559. Add augmenting types tests. Part 6 (#2583)
Browse files Browse the repository at this point in the history
Add augmenting types tests. Part 6
  • Loading branch information
sgrekhov authored Apr 2, 2024
1 parent bd634b9 commit dfa8815
Show file tree
Hide file tree
Showing 17 changed files with 550 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2024, 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.

/// @description Common library for augmentation libraries tests
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=macros

library augmentation_libraries_lib;

class AL {}

final class FinalClass {}

base class BaseClass {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2024, 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.

/// @assertion A class, enum, extension type, or mixin augmentation may specify
/// extends, implements, on, and with clauses (when generally supported). The
/// types in these clauses are appended to the original declarations clauses of
/// the same kind, and if that clause did not exist previously then it is added
/// with the new types. All regular rules apply after this appending process, so
/// you cannot have multiple extends on a class, or an on clause on an enum, etc
///
/// @description Checks that a class augment may specify `extends` clause
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=macros

import '../../Utils/expect.dart';
import augment 'augmenting_types_A06_t01_lib.dart';

class A {}

class C {}

main() {
Expect.isTrue(C() is A);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2024, 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.

/// @assertion A class, enum, extension type, or mixin augmentation may specify
/// extends, implements, on, and with clauses (when generally supported). The
/// types in these clauses are appended to the original declarations clauses of
/// the same kind, and if that clause did not exist previously then it is added
/// with the new types. All regular rules apply after this appending process, so
/// you cannot have multiple extends on a class, or an on clause on an enum, etc
///
/// @description Checks that a class augment may specify `extends` clause
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=macros

augment library 'augmenting_types_A06_t01.dart';

augment class C extends A {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2024, 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.

/// @assertion A class, enum, extension type, or mixin augmentation may specify
/// extends, implements, on, and with clauses (when generally supported). The
/// types in these clauses are appended to the original declarations clauses of
/// the same kind, and if that clause did not exist previously then it is added
/// with the new types. All regular rules apply after this appending process, so
/// you cannot have multiple extends on a class, or an on clause on an enum, etc
///
/// @description Checks that it is a compile-time error if a class augment
/// specifies a final class in an `extends` clause
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=macros

import augment 'augmenting_types_A06_t02_lib.dart';

class A {}

class C {}

main() {
print(A);
print(C);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2024, 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.

/// @assertion A class, enum, extension type, or mixin augmentation may specify
/// extends, implements, on, and with clauses (when generally supported). The
/// types in these clauses are appended to the original declarations clauses of
/// the same kind, and if that clause did not exist previously then it is added
/// with the new types. All regular rules apply after this appending process, so
/// you cannot have multiple extends on a class, or an on clause on an enum, etc
///
/// @description Checks that it is a compile-time error if a class augment
/// specifies a final class in an `extends` clause
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=macros

augment library 'augmenting_types_A06_t02.dart';
import 'augmentation_libraries_lib.dart';

augment class A extends FinalClass {}
// ^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

augment class C extends String {}
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) 2024, 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.

/// @assertion A class, enum, extension type, or mixin augmentation may specify
/// extends, implements, on, and with clauses (when generally supported). The
/// types in these clauses are appended to the original declarations clauses of
/// the same kind, and if that clause did not exist previously then it is added
/// with the new types. All regular rules apply after this appending process, so
/// you cannot have multiple extends on a class, or an on clause on an enum, etc
///
/// @description Checks that a class, extension type, mixin and enum augment may
/// specify `implements` clause
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=macros

import '../../Utils/expect.dart';
import augment 'augmenting_types_A06_t03_lib.dart';

interface class I {
String get id => "I";
}

class C {}

extension type ET(I _) {}

mixin M {}

enum E {
e1;
}

class MA = Object with M;

main() {
I c = C();
I et = ET(I());
I m = MA();
I e = E.e1;
Expect.equals("C", c.id);
Expect.equals("I", et.id);
Expect.equals("M", m.id);
Expect.equals("E", e.id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2024, 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.

/// @assertion A class, enum, extension type, or mixin augmentation may specify
/// extends, implements, on, and with clauses (when generally supported). The
/// types in these clauses are appended to the original declarations clauses of
/// the same kind, and if that clause did not exist previously then it is added
/// with the new types. All regular rules apply after this appending process, so
/// you cannot have multiple extends on a class, or an on clause on an enum, etc
///
/// @description Checks that a class, extension type, mixin and enum augment may
/// specify `implements` clause
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=macros

augment library 'augmenting_types_A06_t03.dart';

augment class C implements I {
String get id => "C";
}

augment extension type ET(I _) implements I {}

augment mixin M implements I {
String get id => "M";
}

augment enum E implements I {
augment e1;
String get id => "E";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright (c) 2024, 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.

/// @assertion A class, enum, extension type, or mixin augmentation may specify
/// extends, implements, on, and with clauses (when generally supported). The
/// types in these clauses are appended to the original declarations clauses of
/// the same kind, and if that clause did not exist previously then it is added
/// with the new types. All regular rules apply after this appending process, so
/// you cannot have multiple extends on a class, or an on clause on an enum, etc
///
/// @description Checks that a class, extension type, mixin and enum augment may
/// specify an additional `implements` clause
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=macros

import '../../Utils/expect.dart';
import augment 'augmenting_types_A06_t04_lib.dart';

abstract class I0 {
String get id0;
}

class I1 impelements I0 {
String get id0 => "I1";
String get id1 => "I1";
}

class C implements I1 {
String get id1 => "C";
}

mixin M implements I1 {
String get id1 => "M";
}

extension type ET(I1 _) implements I1 {}

enum E implements I1 {
e1;
String get id1 => "E";
}

class MA = Object with M;

main() {
I1 c1 = C();
I1 et1 = ET(I1());
I1 m1 = MA();
I1 e1 = E.e1;
Expect.equals("C", c1.id1);
Expect.equals("I1", et1.id1);
Expect.equals("M", m1.id1);
Expect.equals("E", e1.id1);

I2 c2 = C();
I2 et2 = ET(I1());
I2 m2 = MA();
I2 e2 = E.e1;
Expect.equals("I2 from C", c2.id2);
Expect.equals("I0 from ET", et2.id0);
Expect.equals("I2 from M", m2.id2);
Expect.equals("I2 from E", e2.id2);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) 2024, 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.

/// @assertion A class, enum, extension type, or mixin augmentation may specify
/// extends, implements, on, and with clauses (when generally supported). The
/// types in these clauses are appended to the original declarations clauses of
/// the same kind, and if that clause did not exist previously then it is added
/// with the new types. All regular rules apply after this appending process, so
/// you cannot have multiple extends on a class, or an on clause on an enum, etc
///
/// @description Checks that a class, extension type, mixin and enum augment may
/// specify an additional `implements` clause
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=macros

augment library 'augmenting_types_A06_t04.dart';

interface class I2 {
String id2 => "I2";
}

interface class I3 extends I1 {
String id2 => "I2";
}

augment class C implements I2 {
String get id2 => "I2 from C";
}

extension type ET(I1 _) implements I0 {
String get id0 => "I0 from ET";
}

augment mixin M implements I2 {
String get id2 => "I2 from M";
}

augment enum E implements I2 {
augment e1;
String get id2 => "I2 from E";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) 2024, 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.

/// @assertion A class, enum, extension type, or mixin augmentation may specify
/// extends, implements, on, and with clauses (when generally supported). The
/// types in these clauses are appended to the original declarations clauses of
/// the same kind, and if that clause did not exist previously then it is added
/// with the new types. All regular rules apply after this appending process, so
/// you cannot have multiple extends on a class, or an on clause on an enum, etc
///
/// @description Checks that it is a compile-time error if a class, mixin or
/// enum augment specifies `implements` clause but doesn't implement this
/// interface
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=macros

import augment 'augmenting_types_A06_t05_lib.dart';

interface class I {
String get id => "I";
}

class C {}

mixin M {}

enum E {
e1;
}

class MA = Object with M;
// ^^
// [analyzer] unspecified
// [cfe] unspecified

main() {
print(C);
print(MA);
print(E);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2024, 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.

/// @assertion A class, enum, extension type, or mixin augmentation may specify
/// extends, implements, on, and with clauses (when generally supported). The
/// types in these clauses are appended to the original declarations clauses of
/// the same kind, and if that clause did not exist previously then it is added
/// with the new types. All regular rules apply after this appending process, so
/// you cannot have multiple extends on a class, or an on clause on an enum, etc
///
/// @description Checks that it is a compile-time error if a class, extension
/// type, mixin or enum augment specifies `implements` clause but doesn't
/// implement this interface
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=macros

augment library 'augmenting_types_A06_t05.dart';

augment class C implements I {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

augment mixin M implements I {}

augment enum E implements I {
// ^
// [analyzer] unspecified
// [cfe] unspecified
augment e1;
}
Loading

0 comments on commit dfa8815

Please sign in to comment.