Skip to content

Commit

Permalink
dart-lang#2559. Add augmented expression tests for setters
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov committed Apr 24, 2024
1 parent 233bca7 commit 9abe0bd
Show file tree
Hide file tree
Showing 20 changed files with 1,193 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// SharedOptions=--enable-experiment=macros

augment library 'augmented_expression_A01_t01.dart';
import '../../Utils/expect.dart';

augment String get topLevelGetter {
Expect.equals("Original", augmented);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// SharedOptions=--enable-experiment=macros

augment library 'augmented_expression_A01_t02.dart';
import '../../Utils/expect.dart';

augment String get topLevelVariable {
Expect.equals("Original", augmented);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// SharedOptions=--enable-experiment=macros

augment library 'augmented_expression_A01_t06.dart';
import '../../Utils/expect.dart';

augment String get topLevelGetter {
Expect.equals("topLevelGetter: Getter augmented", augmented);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// SharedOptions=--enable-experiment=macros

augment library 'augmented_expression_A01_t07.dart';
import '../../Utils/expect.dart';

augment String get topLevelGetter {
Expect.equals("Original", augmented);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// SharedOptions=--enable-experiment=macros

augment library 'augmented_expression_A01_t07.dart';
import '../../Utils/expect.dart';

augment String get topLevelGetter {
Expect.equals("Augmented1", augmented);
Expand Down
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);
}
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";
}
}
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);
}
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";
}
}

0 comments on commit 9abe0bd

Please sign in to comment.