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. Add augmented expression tests for setters
- Loading branch information
Showing
20 changed files
with
1,193 additions
and
0 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
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
95 changes: 95 additions & 0 deletions
95
LanguageFeatures/Augmentation-libraries/augmented_expression_A02_t01.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,95 @@ | ||
// 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 The exact result of an `augmented` expression depends on what is | ||
/// being augmented, but it generally follows the same rules as any normal | ||
/// identifier: | ||
/// ... | ||
/// - Augmenting setters: Within an augmenting setter `augmented` must be | ||
/// followed by an `=` and will directly invoke the augmented setter. If | ||
/// augmenting a field with a setter, this will invoke the implicit setter | ||
/// from the augmented field. | ||
/// | ||
/// @description Checks that within an augmenting setter `augmented=` invokes | ||
/// the augmented setter. | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=macros | ||
|
||
import augment 'augmented_expression_A02_t01_lib.dart'; | ||
import '../../Utils/expect.dart'; | ||
|
||
String _log = ""; | ||
|
||
void set augmented(String value) { | ||
_log = "Setter augmented: $value"; | ||
} | ||
|
||
void set topLevelSetter(String value) { | ||
_log = "topLevelSetter: $value"; | ||
} | ||
|
||
|
||
class C { | ||
static void set staticSetter(String value) { | ||
_log = "C.staticSetter: $value"; | ||
} | ||
void set instanceSetter(String value) { | ||
_log = "C.instanceSetter: $value"; | ||
} | ||
} | ||
|
||
mixin M { | ||
static void set staticSetter(String value) { | ||
_log = "M.staticSetter: $value"; | ||
} | ||
void set instanceSetter(String value) { | ||
_log = "M.instanceSetter: $value"; | ||
} | ||
} | ||
|
||
enum E { | ||
e1; | ||
|
||
static void set staticSetter(String value) { | ||
_log = "E.staticSetter: $value"; | ||
} | ||
void set instanceSetter(String value) { | ||
_log = "E.instanceSetter: $value"; | ||
} | ||
} | ||
|
||
class A {} | ||
|
||
extension Ext on A { | ||
static void set staticSetter(String value) { | ||
_log = "Ext.staticSetter: $value"; | ||
} | ||
void set instanceSetter(String value) { | ||
_log = "Ext.instanceSetter: $value"; | ||
} | ||
} | ||
|
||
class MA = Object with M; | ||
|
||
main() { | ||
topLevelSetter = "1"; | ||
Expect.equals("Augmented: 1", _log); | ||
C.staticSetter = "2"; | ||
Expect.equals("Augmented: 2", _log); | ||
C().instanceSetter = "3"; | ||
Expect.equals("Augmented: 3", _log); | ||
M.staticSetter = "4"; | ||
Expect.equals("Augmented: 4", _log); | ||
MA().instanceSetter = "5"; | ||
Expect.equals("Augmented: 5", _log); | ||
E.staticSetter = "6"; | ||
Expect.equals("Augmented: 6", _log); | ||
E.e1.instanceSetter = "7"; | ||
Expect.equals("Augmented: 7", _log); | ||
Ext.staticSetter = "8"; | ||
Expect.equals("Augmented: 8", _log); | ||
A().instanceSetter = "9"; | ||
Expect.equals("Augmented: 9", _log); | ||
} |
81 changes: 81 additions & 0 deletions
81
LanguageFeatures/Augmentation-libraries/augmented_expression_A02_t01_lib.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,81 @@ | ||
// 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 The exact result of an `augmented` expression depends on what is | ||
/// being augmented, but it generally follows the same rules as any normal | ||
/// identifier: | ||
/// ... | ||
/// - Augmenting setters: Within an augmenting setter `augmented` must be | ||
/// followed by an `=` and will directly invoke the augmented setter. If | ||
/// augmenting a field with a setter, this will invoke the implicit setter | ||
/// from the augmented field. | ||
/// | ||
/// @description Checks that within an augmenting setter `augmented=` invokes | ||
/// the augmented setter. | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=macros | ||
|
||
augment library 'augmented_expression_A02_t01.dart'; | ||
import '../../Utils/expect.dart'; | ||
|
||
augment void set topLevelSetter(String value) { | ||
augmented = "a"; | ||
Expect.equals("topLevelSetter: a", _log); | ||
_log = "Augmented: $value"; | ||
} | ||
|
||
augment class C { | ||
augment static void set staticSetter(String value) { | ||
augmented = "b"; | ||
Expect.equals("C.staticSetter: b", _log); | ||
_log = "Augmented: $value"; | ||
} | ||
augment void set instanceSetter(String value) { | ||
augmented = "c"; | ||
Expect.equals("C.instanceSetter: c", _log); | ||
_log = "Augmented: $value"; | ||
} | ||
} | ||
|
||
augment mixin M { | ||
augment static void set staticSetter(String value) { | ||
augmented = "d"; | ||
Expect.equals("M.staticSetter: d", _log); | ||
_log = "Augmented: $value"; | ||
} | ||
augment void set instanceSetter(String value) { | ||
augmented = "e"; | ||
Expect.equals("M.instanceSetter: e", _log); | ||
_log = "Augmented: $value"; | ||
} | ||
} | ||
|
||
augment enum E { | ||
augment e1; | ||
|
||
augment static void set staticSetter(String value) { | ||
augmented = "f"; | ||
Expect.equals("E.staticSetter: f", _log); | ||
_log = "Augmented: $value"; | ||
} | ||
augment void set instanceSetter(String value) { | ||
augmented = "g"; | ||
Expect.equals("E.instanceSetter: g", _log); | ||
_log = "Augmented: $value"; | ||
} | ||
} | ||
|
||
augment extension Ext { | ||
augment static void set staticSetter(String value) { | ||
augmented = "h"; | ||
Expect.equals("E.staticSetter: h", _log); | ||
_log = "Augmented: $value"; | ||
} | ||
augment void set instanceSetter(String value) { | ||
augmented = "g"; | ||
Expect.equals("E.instanceSetter: g", _log); | ||
_log = "Augmented: $value"; | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
LanguageFeatures/Augmentation-libraries/augmented_expression_A02_t02.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,69 @@ | ||
// 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 The exact result of an `augmented` expression depends on what is | ||
/// being augmented, but it generally follows the same rules as any normal | ||
/// identifier: | ||
/// ... | ||
/// - Augmenting setters: Within an augmenting setter `augmented` must be | ||
/// followed by an `=` and will directly invoke the augmented setter. If | ||
/// augmenting a field with a setter, this will invoke the implicit setter | ||
/// from the augmented field. | ||
/// | ||
/// @description Checks that within an augmenting setter `augmented=` invokes | ||
/// the implicit augmented setter. | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=macros | ||
|
||
import augment 'augmented_expression_A02_t02_lib.dart'; | ||
import '../../Utils/expect.dart'; | ||
|
||
String _log = ""; | ||
|
||
void set augmented(String value) { | ||
throw Exception("Wrong setter is called"); | ||
} | ||
|
||
String topLevelVariable = ""; | ||
|
||
class C { | ||
static String staticVariable = ""; | ||
String instanceVariable = ""; | ||
} | ||
|
||
mixin M { | ||
static String staticVariable = ""; | ||
String instanceVariable = ""; | ||
} | ||
|
||
enum E { | ||
e1; | ||
static String staticVariable = ""; | ||
} | ||
|
||
class A {} | ||
|
||
extension Ext on A { | ||
static String staticVariable = ""; | ||
} | ||
|
||
class MA = Object with M; | ||
|
||
main() { | ||
topLevelSetter = "1"; | ||
Expect.equals("Augmented: 1", _log); | ||
C.staticVariable = "2"; | ||
Expect.equals("Augmented: 2", _log); | ||
C().instanceVariable = "3"; | ||
Expect.equals("Augmented: 3", _log); | ||
M.staticVariable = "4"; | ||
Expect.equals("Augmented: 4", _log); | ||
MA().instanceVariable = "5"; | ||
Expect.equals("Augmented: 5", _log); | ||
E.staticVariable = "6"; | ||
Expect.equals("Augmented: 6", _log); | ||
Ext.staticVariable = "7"; | ||
Expect.equals("Augmented: 7", _log); | ||
} |
71 changes: 71 additions & 0 deletions
71
LanguageFeatures/Augmentation-libraries/augmented_expression_A02_t02_lib.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,71 @@ | ||
// 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 The exact result of an `augmented` expression depends on what is | ||
/// being augmented, but it generally follows the same rules as any normal | ||
/// identifier: | ||
/// ... | ||
/// - Augmenting setters: Within an augmenting setter `augmented` must be | ||
/// followed by an `=` and will directly invoke the augmented setter. If | ||
/// augmenting a field with a setter, this will invoke the implicit setter | ||
/// from the augmented field. | ||
/// | ||
/// @description Checks that within an augmenting setter `augmented=` invokes | ||
/// the implicit augmented setter. | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=macros | ||
|
||
augment library 'augmented_expression_A02_t02.dart'; | ||
import '../../Utils/expect.dart'; | ||
|
||
augment void set topLevelVariable(String value) { | ||
augmented = "a"; | ||
Expect.equals("a", topLevelVariable); | ||
_log = "Augmented: $value"; | ||
} | ||
|
||
augment class C { | ||
augment static void set staticVariable(String value) { | ||
augmented = "b"; | ||
Expect.equals("b", staticVariable); | ||
_log = "Augmented: $value"; | ||
} | ||
augment void set instanceVariable(String value) { | ||
augmented = "c"; | ||
Expect.equals("c", instanceVariable); | ||
_log = "Augmented: $value"; | ||
} | ||
} | ||
|
||
augment mixin M { | ||
augment static void set staticVariable(String value) { | ||
augmented = "d"; | ||
Expect.equals("d", staticVariable); | ||
_log = "Augmented: $value"; | ||
} | ||
augment void set instanceVariable(String value) { | ||
augmented = "e"; | ||
Expect.equals("e", instanceVariable); | ||
_log = "Augmented: $value"; | ||
} | ||
} | ||
|
||
augment enum E { | ||
augment e1; | ||
|
||
augment static void set staticVariable(String value) { | ||
augmented = "f"; | ||
Expect.equals("f", staticVariable); | ||
_log = "Augmented: $value"; | ||
} | ||
} | ||
|
||
augment extension Ext { | ||
augment static void set staticVariable(String value) { | ||
augmented = "g"; | ||
Expect.equals("g", staticVariable); | ||
_log = "Augmented: $value"; | ||
} | ||
} |
Oops, something went wrong.