Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 27 additions & 48 deletions LanguageFeatures/Augmentations/augmenting_functions_A01_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,49 @@
// 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 top-level function, static method, instance method, or operator
/// may be augmented to wrap the original code in additional code.
/// ...
/// The augmentation replaces the augmented function’s body with the augmenting
/// function’s body.
/// @assertion A top-level function, static method, instance method, operator,
/// getter, or setter may be augmented to provide a body or add metadata.
///
/// @description Checks that a top-level function may be augmented and the
/// original code is replaced by the augmentation
/// @description Checks that an incomplete top-level function may be augmented,
/// and that its body can be added by the augmentation.
/// @author [email protected]

// SharedOptions=--enable-experiment=macros
// SharedOptions=--enable-experiment=augmentations

import '../../Utils/expect.dart';
part 'augmenting_functions_A01_t01_lib.dart';

String _log = "";
String topLevelFunction1();

void clearLog() {
_log = "";
augment String topLevelFunction1() {
return "augmented";
}

String topLevelFunction1() {
_log += "Original topLevelFunction1;";
return "Original";
}

String topLevelFunction2(String v) {
_log += "Original topLevelFunction2($v);";
return "Original v=$v";
}
String topLevelFunction2(String v);

String topLevelFunction3(String v1, [String v2 = "v2 def"]) {
_log += "Original topLevelFunction3($v1, [$v2]);";
return "Original v1=$v1, [v2=$v2]";
}
augment String topLevelFunction2(String v) => v;

String topLevelFunction4(String v1, {String v2 = "v2 def"}) {
_log += "Original topLevelFunction4($v1, {$v2});";
return "Original v1=$v1, {v2=$v2}";
}
String topLevelFunction3(String v1, [String v2 = "v2 def"]);

String topLevelFunction5(String v1, {required String v2}) {
_log += "Original topLevelFunction5($v1, {required $v2});";
return "Original v1=$v1, {required v2=$v2}";
augment String topLevelFunction3(String v1, [String v2]) {
return "$v1;$v2";
}

main() {
Expect.equals("augment", topLevelFunction1());
Expect.equals("augment topLevelFunction1();", _log);
clearLog();
String topLevelFunction4(String v1, {String v2 = "v2 def"});

Expect.equals("augment v=A", topLevelFunction2("A"));
Expect.equals("augment topLevelFunction2(A);", _log);
clearLog();
augment String topLevelFunction4(String v1, {String v2}) {
return "$v1;$v2";
}

Expect.equals("augment v1=B, [v2=C]", topLevelFunction3("B", "C"));
Expect.equals("augment topLevelFunction3(B, [C]);", _log);
clearLog();
String topLevelFunction5(String v1, {required String v2});

Expect.equals("augment v1=D, {v2=E}", topLevelFunction4("D", v2: "E"));
Expect.equals("augment topLevelFunction4(D, {E});", _log);
clearLog();
augment String topLevelFunction5(String v1, {required String v2}) => "$v1;$v2";

Expect.equals("augment v1=F, {required v2=G}",
topLevelFunction5("F", v2: "G"));
Expect.equals("augment topLevelFunction5(F, {required G});", _log);
main() {
Expect.equals("augmented", topLevelFunction1());
Expect.equals("A", topLevelFunction2("A"));
Expect.equals("B;v2 def", topLevelFunction3("B"));
Expect.equals("B;C", topLevelFunction3("B", "C"));
Expect.equals("D;v2 def", topLevelFunction4("D", v2: "E"));
Expect.equals("D;E", topLevelFunction4("D", v2: "E"));
Expect.equals("F,G", topLevelFunction5("F", v2: "G"));
}

This file was deleted.

77 changes: 28 additions & 49 deletions LanguageFeatures/Augmentations/augmenting_functions_A01_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,50 @@
// 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 top-level function, static method, instance method, or operator
/// may be augmented to wrap the original code in additional code.
/// ...
/// The augmentation replaces the augmented function’s body with the augmenting
/// function’s body.
/// @assertion A top-level function, static method, instance method, operator,
/// getter, or setter may be augmented to provide a body or add metadata.
///
/// @description Checks that a static method may be augmented and the original
/// code is replaced by the augmentation. Test a class.
/// @description Checks that an incomplete static method may be augmented, and
/// that its body can be added by the augmentation. Test a class.
/// @author [email protected]

// SharedOptions=--enable-experiment=macros
// SharedOptions=--enable-experiment=augmentations

import '../../Utils/expect.dart';
part 'augmenting_functions_A01_t02_lib.dart';

String _log = "";

void clearLog() {
_log = "";
class C {
static String staticMethod1();
static String staticMethod2(String v);
static String staticMethod3(String v1, [String v2 = "v2 def"]);
static String staticMethod4(String v1, {String v2 = "v2 def"});
static String staticMethod5(String v1, {required String v2});
}

class C {
static String staticMethod1() {
_log += "Original staticMethod1;";
return "Original";
augment class C {
augment static String staticMethod1() {
return "augmented";
}

static String staticMethod2(String v) {
_log += "Original staticMethod2($v);";
return "Original v=$v";
}
augment static String staticMethod2(String v) => v;

static String staticMethod3(String v1, [String v2 = "v2 def"]) {
_log += "Original staticMethod3($v1, [$v2]);";
return "Original v1=$v1, [v2=$v2]";
}
augment static String staticMethod3(String v1, [String v2 = "v2 def"]) =>
"$v1,$v2";

static String staticMethod4(String v1, {String v2 = "v2 def"}) {
_log += "Original staticMethod4($v1, {$v2});";
return "Original v1=$v1, {v2=$v2}";
augment static String staticMethod4(String v1, {String v2 = "v2 def"}) {
return "$v1,$v2";
}

static String staticMethod5(String v1, {required String v2}) {
_log += "Original staticMethod5($v1, {required $v2});";
return "Original v1=$v1, {required v2=$v2}";
augment static String staticMethod5(String v1, {required String v2}) {
return "$v1,$v2";
}
}

main() {
Expect.equals("augment", C.staticMethod1());
Expect.equals("augment staticMethod1();", _log);
clearLog();

Expect.equals("augment v=A", C.staticMethod2("A"));
Expect.equals("augment staticMethod2(A);", _log);
clearLog();

Expect.equals("augment v1=B, [v2=C]", C.staticMethod3("B", "C"));
Expect.equals("augment staticMethod3(B, [C]);", _log);
clearLog();

Expect.equals("augment v1=D, {v2=E}", C.staticMethod4("D", v2: "E"));
Expect.equals("augment staticMethod4(D, {E});", _log);
clearLog();

Expect.equals("augment v1=F, {required v2=G}", C.staticMethod5("F", v2: "G"));
Expect.equals("augment staticMethod5(F, {required G});", _log);
Expect.equals("augmented", C.staticMethod1());
Expect.equals("A;v2 def", C.staticMethod2("A"));
Expect.equals("B,v2 def", C.staticMethod3("B"));
Expect.equals("B,C", C.staticMethod3("B", "C"));
Expect.equals("D;v2 def", C.staticMethod4("D"));
Expect.equals("D;E", C.staticMethod4("D", v2: "E"));
Expect.equals("F;G", C.staticMethod5("F", v2: "G"));
}

This file was deleted.

77 changes: 28 additions & 49 deletions LanguageFeatures/Augmentations/augmenting_functions_A01_t03.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,50 @@
// 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 top-level function, static method, instance method, or operator
/// may be augmented to wrap the original code in additional code.
/// ...
/// The augmentation replaces the augmented function’s body with the augmenting
/// function’s body.
/// @assertion A top-level function, static method, instance method, operator,
/// getter, or setter may be augmented to provide a body or add metadata.
///
/// @description Checks that a static method may be augmented and the original
/// code is replaced by the augmentation. Test a mixin.
/// @description Checks that an incomplete static method may be augmented, and
/// that its body can be added by the augmentation. Test a mixin.
/// @author [email protected]

// SharedOptions=--enable-experiment=macros
// SharedOptions=--enable-experiment=augmentations

import '../../Utils/expect.dart';
part 'augmenting_functions_A01_t03_lib.dart';

String _log = "";

void clearLog() {
_log = "";
mixin M {
static String staticMethod1();
static String staticMethod2(String v);
static String staticMethod3(String v1, [String v2 = "v2 def"]);
static String staticMethod4(String v1, {String v2 = "v2 def"});
static String staticMethod5(String v1, {required String v2});
}

mixin M {
static String staticMethod1() {
_log += "Original staticMethod1;";
return "Original";
augment mixin M {
augment static String staticMethod1() {
return "augmented";
}

static String staticMethod2(String v) {
_log += "Original staticMethod2($v);";
return "Original v=$v";
}
augment static String staticMethod2(String v) => v;

static String staticMethod3(String v1, [String v2 = "v2 def"]) {
_log += "Original staticMethod3($v1, [$v2]);";
return "Original v1=$v1, [v2=$v2]";
}
augment static String staticMethod3(String v1, [String v2 = "v2 def"]) =>
"$v1,$v2";

static String staticMethod4(String v1, {String v2 = "v2 def"}) {
_log += "Original staticMethod4($v1, {$v2});";
return "Original v1=$v1, {v2=$v2}";
augment static String staticMethod4(String v1, {String v2 = "v2 def"}) {
return "$v1,$v2";
}

static String staticMethod5(String v1, {required String v2}) {
_log += "Original staticMethod5($v1, {required $v2});";
return "Original v1=$v1, {required v2=$v2}";
augment static String staticMethod5(String v1, {required String v2}) {
return "$v1,$v2";
}
}

main() {
Expect.equals("augment", M.staticMethod1());
Expect.equals("augment staticMethod1();", _log);
clearLog();

Expect.equals("augment v=A", M.staticMethod2("A"));
Expect.equals("augment staticMethod2(A);", _log);
clearLog();

Expect.equals("augment v1=B, [v2=C]", M.staticMethod3("B", "C"));
Expect.equals("augment staticMethod3(B, [C]);", _log);
clearLog();

Expect.equals("augment v1=D, {v2=E}", M.staticMethod4("D", v2: "E"));
Expect.equals("augment staticMethod4(D, {E});", _log);
clearLog();

Expect.equals("augment v1=F, {required v2=G}", M.staticMethod5("F", v2: "G"));
Expect.equals("augment staticMethod5(F, {required G});", _log);
Expect.equals("augmented", M.staticMethod1());
Expect.equals("A;v2 def", M.staticMethod2("A"));
Expect.equals("B,v2 def", M.staticMethod3("B"));
Expect.equals("B,C", M.staticMethod3("B", "C"));
Expect.equals("D;v2 def", M.staticMethod4("D"));
Expect.equals("D;E", M.staticMethod4("D", v2: "E"));
Expect.equals("F;G", M.staticMethod5("F", v2: "G"));
}
Loading
Loading