Skip to content

Commit

Permalink
dart-lang#2559. Add augmented expression tests for getters
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov committed Apr 23, 2024
1 parent 052d8a7 commit 29650a2
Show file tree
Hide file tree
Showing 15 changed files with 1,011 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// 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 getters: Within an augmenting getter `augmented` invokes the
/// getter and evaluates to the return value. If augmenting a field with a
/// getter, this will invoke the implicit getter from the augmented field.
///
/// @description Checks that within an augmenting getter `augmented` invokes the
/// augmented getter and evaluates it to the return value.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=macros

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

String get augmented => "Getter augmented";

String get topLevelGetter => "Original";

class C {
static String get staticGetter => "Original";
String get instanceGetter => "Original";
}

mixin M {
static String get staticGetter => "Original";
String get instanceGetter => "Original";
}

enum E {
e1;

static String get staticGetter => "Original";
String get instanceGetter => "Original";
}

class A {}

extension Ext on A {
static String get staticGetter => "Original";
String get instanceGetter => "Original";
}

class MA = Object with M;

main() {
Expect.equals("Augmented", topLevelGetter);
Expect.equals("Augmented", C.staticGetter);
Expect.equals("Augmented", C().instanceGetter);
Expect.equals("Augmented", M.staticGetter);
Expect.equals("Augmented", MA().instanceGetter);
Expect.equals("Augmented", E.staticGetter);
Expect.equals("Augmented", E.e1.instanceGetter);
Expect.equals("Augmented", Ext.staticGetter);
Expect.equals("Augmented", A().instanceGetter);
}
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 getters: Within an augmenting getter `augmented` invokes the
/// getter and evaluates to the return value. If augmenting a field with a
/// getter, this will invoke the implicit getter from the augmented field.
///
/// @description Checks that within an augmenting getter `augmented` invokes the
/// augmented getter and evaluates it to the return value.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=macros

augment library 'augmented_expression_A01_t01.dart';

augment String get topLevelGetter {
Expect.equals("Original", augmented);
return "Augmented";
}

augment class C {
augment static String get staticGetter {
Expect.equals("Original", augmented);
return "Augmented";
}
augment String get instanceGetter {
Expect.equals("Original", augmented);
return "Augmented";
}
}

augment mixin M {
augment static String get staticGetter {
Expect.equals("Original", augmented);
return "Augmented";
}
augment String get instanceGetter {
Expect.equals("Original", augmented);
return "Augmented";
}
}

augment enum E {
augment e1;

augment static String get staticGetter {
Expect.equals("Original", augmented);
return "Augmented";
}
augment String get instanceGetter {
Expect.equals("Original", augmented);
return "Augmented";
}
}

augment extension Ext {
augment static String get staticGetter {
Expect.equals("Original", augmented);
return "Augmented";
}
augment String get instanceGetter {
Expect.equals("Original", augmented);
return "Augmented";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// 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 getters: Within an augmenting getter `augmented` invokes the
/// getter and evaluates to the return value. If augmenting a field with a
/// getter, this will invoke the implicit getter from the augmented field.
///
/// @description Checks that within an augmenting getter `augmented` invokes the
/// augmented implicit getter and evaluates it to the return value.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=macros

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

String get augmented => "Getter augmented";

String topLevelVariable = "Original";

class C {
static String staticField = "Original";
String instanceField = "Original";
}

mixin M {
static String staticField = "Original";
String instanceField = "Original";
}

enum E {
e1;

static String staticField = "Original";
final String instanceField = "Original";
}

class A {}

extension Ext on A {
static String staticField = "Original";
}

class MA = Object with M;

main() {
Expect.equals("Augmented", topLevelVariable);
Expect.equals("Augmented", C.staticField);
Expect.equals("Augmented", C().instanceField);
Expect.equals("Augmented", M.staticField);
Expect.equals("Augmented", MA().instanceField);
Expect.equals("Augmented", E.staticField);
Expect.equals("Augmented", E.e1.instanceField);
Expect.equals("Augmented", Ext.staticField);
}
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 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 getters: Within an augmenting getter `augmented` invokes the
/// getter and evaluates to the return value. If augmenting a field with a
/// getter, this will invoke the implicit getter from the augmented field.
///
/// @description Checks that within an augmenting getter `augmented` invokes the
/// augmented implicit getter and evaluates it to the return value.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=macros

augment library 'augmented_expression_A01_t02.dart';

augment String get topLevelVariable {
Expect.equals("Original", augmented);
return "Augmented";
}

augment class C {
augment static String get staticField {
Expect.equals("Original", augmented);
return "Augmented";
}
augment String get instanceField {
Expect.equals("Original", augmented);
return "Augmented";
}
}

augment mixin M {
augment static String get staticField {
Expect.equals("Original", augmented);
return "Augmented";
}
augment String get instanceField {
Expect.equals("Original", augmented);
return "Augmented";
}
}

augment enum E {
augment e1;

augment static String get staticField {
Expect.equals("Original", augmented);
return "Augmented";
}
augment String get instanceField {
Expect.equals("Original", augmented);
return "Augmented";
}
}

augment extension Ext {
augment static String get staticField {
Expect.equals("Original", augmented);
return "Augmented";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// 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 getters: Within an augmenting getter `augmented` invokes the
/// getter and evaluates to the return value. If augmenting a field with a
/// getter, this will invoke the implicit getter from the augmented field.
///
/// @description Checks that it is a compile-time error if within an augmenting
/// getter `augmented()` expression is invoked.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=macros

import augment 'augmented_expression_A01_t03_lib.dart';

String augmented() => "Function augmented()";

String get topLevelGetter => "Original";

class C {
static String get staticGetter => "Original";
String get instanceGetter => "Original";
}

mixin M {
static String get staticGetter => "Original";
String get instanceGetter => "Original";
}

enum E {
e1;

static String get staticGetter => "Original";
String get instanceGetter => "Original";
}

class A {}

extension Ext on A {
static String get staticGetter => "Original";
String get instanceGetter => "Original";
}

class MA = Object with M;

main() {
print(topLevelGetter);
print(C);
print(M);
print(E);
print(A);
}

0 comments on commit 29650a2

Please sign in to comment.