forked from dart-lang/co19
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dart-lang#2559.Update non-redirecting generative constructors tests
- Loading branch information
Showing
45 changed files
with
602 additions
and
1,008 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,56 +2,61 @@ | |
// 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 non-redirecting generative constructor marked `augment` may: | ||
/// ... | ||
/// - If the augmenting constructor has an explicit block body, then that body | ||
/// replaces any existing constructor body. | ||
/// @assertion At a high level, a non-redirecting generative constructor marked | ||
/// `augment` may: | ||
/// - Augment the constructor with an additional constructor body (bodies are | ||
/// invoked in augmentation order, starting at the introductory declaration). | ||
/// | ||
/// @description Checks that if the augmenting constructor has an explicit block | ||
/// body, then that body replaces any existing constructor body. | ||
/// body, then that body is executed after the body of the introductory | ||
/// constructor. | ||
/// @author [email protected] | ||
// SharedOptions=--enable-experiment=macros | ||
|
||
import '../../Utils/expect.dart'; | ||
part 'augmenting_constructors_A09_t01_lib.dart'; | ||
|
||
String _log = ""; | ||
String log = ""; | ||
|
||
class C1 { | ||
C1() { | ||
_log += "Original"; | ||
log += "Original;"; | ||
} | ||
} | ||
|
||
class C2 { | ||
C2() { | ||
_log += "Original"; | ||
log += "Original;"; | ||
} | ||
} | ||
|
||
class C3 { | ||
C3.new() { | ||
_log += "Original"; | ||
log += "Original;"; | ||
} | ||
} | ||
|
||
extension type ET(int id) { | ||
ET.foo(this.id) { | ||
_log += "Original"; | ||
log += "Original;"; | ||
} | ||
} | ||
|
||
void checkLog(String expected) { | ||
Expect.equals(expected, log); | ||
log = ""; | ||
} | ||
|
||
main() { | ||
C1(); | ||
Expect.equals("Augmented", _log); | ||
_log = ""; | ||
checkLog("Original;Augmented"); | ||
C2(); | ||
Expect.equals("Augmented", _log); | ||
_log = ""; | ||
checkLog("Original;Augmented"); | ||
C3(); | ||
Expect.equals("Augmented", _log); | ||
_log = ""; | ||
checkLog("Original;Augmented"); | ||
ET(0); | ||
Expect.equals("Augmented", _log); | ||
checkLog("Augmented"); | ||
ET.foo(0); | ||
checkLog("Original;Augmented"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,14 @@ | |
// 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 non-redirecting generative constructor marked `augment` may: | ||
/// ... | ||
/// - If the augmenting constructor has an explicit block body, then that body | ||
/// replaces any existing constructor body. | ||
/// @assertion At a high level, a non-redirecting generative constructor marked | ||
/// `augment` may: | ||
/// - Augment the constructor with an additional constructor body (bodies are | ||
/// invoked in augmentation order, starting at the introductory declaration). | ||
/// | ||
/// @description Checks that if the augmenting constructor has an explicit block | ||
/// body, then that body replaces any existing constructor body. | ||
/// body, then that body is executed after the body of the introductory | ||
/// constructor. | ||
/// @author [email protected] | ||
// SharedOptions=--enable-experiment=macros | ||
|
@@ -17,24 +18,27 @@ part of 'augmenting_constructors_A09_t01.dart'; | |
|
||
augment class C1 { | ||
augment C1() { | ||
_log += "Augmented"; | ||
log += "Augmented"; | ||
} | ||
} | ||
|
||
augment class C2 { | ||
augment C2.new() { | ||
_log += "Augmented"; | ||
log += "Augmented"; | ||
} | ||
} | ||
|
||
augment class C3 { | ||
augment C3() { | ||
_log += "Augmented"; | ||
log += "Augmented"; | ||
} | ||
} | ||
|
||
augment extension type ET { | ||
augment ET(int id) { | ||
log += "Augmented"; | ||
} | ||
augment ET.foo(this.id) { | ||
_log += "Augmented"; | ||
log += "Augmented"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
LanguageFeatures/Augmentation-libraries/augmenting_constructors_A09_t04.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// 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 At a high level, a non-redirecting generative constructor marked | ||
/// `augment` may: | ||
/// - Augment the constructor with an additional constructor body (bodies are | ||
/// invoked in augmentation order, starting at the introductory declaration). | ||
/// | ||
/// @description Checks that it is not an error if an augmenting constructor has | ||
/// no body. | ||
/// @author [email protected] | ||
// SharedOptions=--enable-experiment=macros | ||
|
||
import '../../Utils/expect.dart'; | ||
|
||
class C { | ||
int v; | ||
C() : v = 0; | ||
C.id(this.v) { | ||
v++; | ||
} | ||
} | ||
|
||
augment class C { | ||
augment C(); | ||
augment C.id(int x); | ||
} | ||
|
||
enum E { | ||
e0, e1.id(); | ||
const E(); | ||
const E.id(); | ||
} | ||
|
||
augment enum E { | ||
e2; | ||
augment const E(); | ||
augment const E.id(); | ||
} | ||
|
||
extension type ET(int v) { | ||
ET.foo(this.v) { | ||
assert(v > 0); | ||
} | ||
} | ||
|
||
augment extension type ET { | ||
augment ET(int v); | ||
augment ET.foo(int v); | ||
} | ||
|
||
main() { | ||
Expect.equals(0, C().v); | ||
Expect.equals(2, C.id(1).v); | ||
Expect.equals(1, ET(1).v); | ||
Expect.equals(2, ET.foo(2).v); | ||
if (assertStatementsEnabled) { | ||
Expect.throws(() { | ||
ET.foo(0); | ||
}); | ||
} | ||
} |
Oops, something went wrong.