Skip to content

Commit e9a9797

Browse files
author
sgrekhov
committed
#1228. More named arguments anywhere tests added
1 parent 5c05fa8 commit e9a9797

16 files changed

+279
-1
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Since named arguments are distinguishable from positional ones,
6+
/// allowing named arguments to be placed anywhere in the argument list can be
7+
/// done without changing calling semantics.
8+
///
9+
/// @description Checks that named arguments may be placed anywhere in the
10+
/// argument list. Test constructors
11+
/// @author [email protected]
12+
13+
// SharedOptions=--enable-experiment=named-arguments-anywhere
14+
15+
import "../../Utils/expect.dart";
16+
17+
class C {
18+
String log = "";
19+
20+
C(int x, int y, {int z = 42}) {
21+
log = "x=$x, y=$y, z=$z";
22+
}
23+
24+
C.named(int x, int y, {int z = 42}) {
25+
log = "x=$x, y=$y, z=$z";
26+
}
27+
}
28+
29+
main() {
30+
Expect.equals("x=1, y=2, z=3", C(1, 2, z: 3).log);
31+
Expect.equals("x=1, y=2, z=3", C(z: 3, 1, 2).log);
32+
Expect.equals("x=1, y=2, z=3", C(1, z: 3, 2).log);
33+
Expect.equals("x=1, y=2, z=3", C.named(1, 2, z: 3).log);
34+
Expect.equals("x=1, y=2, z=3", C.named(z: 3, 1, 2).log);
35+
Expect.equals("x=1, y=2, z=3", C.named(1, z: 3, 2).log);
36+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Since named arguments are distinguishable from positional ones,
6+
/// allowing named arguments to be placed anywhere in the argument list can be
7+
/// done without changing calling semantics.
8+
///
9+
/// @description Checks that named arguments may be placed anywhere in the
10+
/// argument list. Test constructors
11+
/// @author [email protected]
12+
13+
// SharedOptions=--enable-experiment=named-arguments-anywhere
14+
15+
import "../../Utils/expect.dart";
16+
17+
class C<T> {
18+
String log = "";
19+
20+
C(T x, T y, {T? z}) {
21+
log = "x=$x, y=$y, z=$z";
22+
}
23+
24+
C.named(T x, T y, {T? z}) {
25+
log = "x=$x, y=$y, z=$z";
26+
}
27+
}
28+
29+
main() {
30+
Expect.equals("x=1, y=2, z=3", C<int>(1, 2, z: 3).log);
31+
Expect.equals("x=1, y=2, z=3", C<int>(z: 3, 1, 2).log);
32+
Expect.equals("x=1, y=2, z=3", C<int>(1, z: 3, 2).log);
33+
Expect.equals("x=1, y=2, z=3", C.named<int>(1, 2, z: 3).log);
34+
Expect.equals("x=1, y=2, z=3", C.named<int>(z: 3, 1, 2).log);
35+
Expect.equals("x=1, y=2, z=3", C.named<int>(1, z: 3, 2).log);
36+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Since named arguments are distinguishable from positional ones,
6+
/// allowing named arguments to be placed anywhere in the argument list can be
7+
/// done without changing calling semantics.
8+
///
9+
/// @description Checks that named arguments may be placed anywhere in the
10+
/// argument list. Test constructors
11+
/// @author [email protected]
12+
13+
// SharedOptions=--enable-experiment=named-arguments-anywhere
14+
15+
import "../../Utils/expect.dart";
16+
17+
class C {
18+
String log = "";
19+
20+
C(int x, int y, {int z = 42}) {
21+
log = "x=$x, y=$y, z=$z";
22+
}
23+
24+
C.named1(int x, int y, int z) : this(x, y, z: z);
25+
C.named2(int x, int y, int z) : this(x, z: z, y);
26+
C.named3(int x, int y, int z) : this(z: z, x, y);
27+
}
28+
29+
main() {
30+
Expect.equals("x=1, y=2, z=3", C(1, 2, z: 3).log);
31+
Expect.equals("x=1, y=2, z=3", C(z: 3, 1, 2).log);
32+
Expect.equals("x=1, y=2, z=3", C(1, z: 3, 2).log);
33+
Expect.equals("x=1, y=2, z=3", C.named1(1, 2, 3).log);
34+
Expect.equals("x=1, y=2, z=3", C.named2(1, 2, 3).log);
35+
Expect.equals("x=1, y=2, z=3", C.named3(1, 2, 3).log);
36+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Since named arguments are distinguishable from positional ones,
6+
/// allowing named arguments to be placed anywhere in the argument list can be
7+
/// done without changing calling semantics.
8+
///
9+
/// @description Checks that named arguments may be placed anywhere in the
10+
/// argument list. Test constructors
11+
/// @author [email protected]
12+
13+
// SharedOptions=--enable-experiment=named-arguments-anywhere
14+
15+
import "../../Utils/expect.dart";
16+
17+
class C<T> {
18+
String log = "";
19+
20+
C(T x, T y, {T? z}) {
21+
log = "x=$x, y=$y, z=$z";
22+
}
23+
24+
C.named1(T x, T y, T z) : this(x, y, z: z);
25+
C.named2(T x, T y, T z) : this(x, z: z, y);
26+
C.named3(T x, T y, T z) : this(z: z, x, y);
27+
}
28+
29+
main() {
30+
Expect.equals("x=1, y=2, z=3", C<int>(1, 2, z: 3).log);
31+
Expect.equals("x=1, y=2, z=3", C<int>(z: 3, 1, 2).log);
32+
Expect.equals("x=1, y=2, z=3", C<int>(1, z: 3, 2).log);
33+
Expect.equals("x=1, y=2, z=3", C<int>.named1(1, 2, 3).log);
34+
Expect.equals("x=1, y=2, z=3", C<int>.named2(1, 2, 3).log);
35+
Expect.equals("x=1, y=2, z=3", C<int>.named3(1, 2, 3).log);
36+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Since named arguments are distinguishable from positional ones,
6+
/// allowing named arguments to be placed anywhere in the argument list can be
7+
/// done without changing calling semantics.
8+
///
9+
/// @description Checks that named arguments may be placed anywhere in the
10+
/// argument list. Test factory constructors
11+
/// @author [email protected]
12+
13+
// SharedOptions=--enable-experiment=named-arguments-anywhere
14+
15+
import "../../Utils/expect.dart";
16+
17+
class C {
18+
String log = "";
19+
20+
C(int x, int y, int z) {
21+
log = "x=$x, y=$y, z=$z";
22+
}
23+
24+
factory C.f1(int x, int y, {int z = 42}) {
25+
return new C(x, y, z);
26+
}
27+
28+
factory C.f2(int x, int y, {int z}) = D;
29+
}
30+
31+
class D extends C {
32+
D(int x, int y, {int z = 42}) : super(x, y, z);
33+
}
34+
35+
main() {
36+
Expect.equals("x=1, y=2, z=3", C.f1(1, 2, z: 3).log);
37+
Expect.equals("x=1, y=2, z=3", C.f1(z: 3, 1, 2).log);
38+
Expect.equals("x=1, y=2, z=3", C.f1(1, z: 3, 2).log);
39+
Expect.equals("x=1, y=2, z=3", C.f2(1, 2, z: 3).log);
40+
Expect.equals("x=1, y=2, z=3", C.f2(z: 3, 1, 2).log);
41+
Expect.equals("x=1, y=2, z=3", C.f2(1, z: 3, 2).log);
42+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Since named arguments are distinguishable from positional ones,
6+
/// allowing named arguments to be placed anywhere in the argument list can be
7+
/// done without changing calling semantics.
8+
///
9+
/// @description Checks that named arguments may be placed anywhere in the
10+
/// argument list. Test factory constructors
11+
/// @author [email protected]
12+
13+
// SharedOptions=--enable-experiment=named-arguments-anywhere
14+
15+
import "../../Utils/expect.dart";
16+
17+
class C<T> {
18+
String log = "";
19+
20+
C(T x, T y, T? z) {
21+
log = "x=$x, y=$y, z=$z";
22+
}
23+
24+
factory C.f1(T x, T y, {T? z}) {
25+
return new C(x, y, z);
26+
}
27+
28+
factory C.f2(Tx, T y, {T? z}) = D;
29+
}
30+
31+
class D<T> extends C<T> {
32+
D(T x, T y, {T? z}) : super(x, y, z);
33+
}
34+
35+
main() {
36+
Expect.equals("x=1, y=2, z=3", C<int>.f1(1, 2, z: 3).log);
37+
Expect.equals("x=1, y=2, z=3", C<int>.f1(z: 3, 1, 2).log);
38+
Expect.equals("x=1, y=2, z=3", C<int>.f1(1, z: 3, 2).log);
39+
Expect.equals("x=1, y=2, z=3", C<int>.f2(1, 2, z: 3).log);
40+
Expect.equals("x=1, y=2, z=3", C<int>.f2(z: 3, 1, 2).log);
41+
Expect.equals("x=1, y=2, z=3", C<int>.f2(1, z: 3, 2).log);
42+
}

LanguageFeatures/NamedArgumentsAnywhere/method_t02.dart renamed to LanguageFeatures/Named-arguments-anywhere/method_t02.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import "../../Utils/expect.dart";
1616

1717
class C<T> {
18-
String foo(T x, T y, {T z}) => "x=$x, y=$y, z=$z";
18+
String foo(T x, T y, {T? z}) => "x=$x, y=$y, z=$z";
1919
}
2020

2121
main() {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Since named arguments are distinguishable from positional ones,
6+
/// allowing named arguments to be placed anywhere in the argument list can be
7+
/// done without changing calling semantics.
8+
///
9+
/// @description Checks that named arguments may be placed anywhere in the
10+
/// argument list. Test static method
11+
/// @author [email protected]
12+
13+
// SharedOptions=--enable-experiment=named-arguments-anywhere
14+
15+
import "../../Utils/expect.dart";
16+
17+
class C {
18+
static String foo(int x, int y, {int z = 42}) => "x=$x, y=$y, z=$z";
19+
}
20+
21+
main() {
22+
Expect.equals("x=1, y=2, z=3", C.foo(1, 2, z: 3));
23+
Expect.equals("x=1, y=2, z=3", C.foo(z: 3, 1, 2));
24+
Expect.equals("x=1, y=2, z=3", C.foo(1, z: 3, 2));
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Since named arguments are distinguishable from positional ones,
6+
/// allowing named arguments to be placed anywhere in the argument list can be
7+
/// done without changing calling semantics.
8+
///
9+
/// @description Checks that named arguments may be placed anywhere in the
10+
/// argument list. Test instance method
11+
/// @author [email protected]
12+
13+
// SharedOptions=--enable-experiment=named-arguments-anywhere
14+
15+
import "../../Utils/expect.dart";
16+
17+
class C {
18+
static String foo<T>(T x, T y, {T? z}) => "x=$x, y=$y, z=$z";
19+
}
20+
21+
main() {
22+
Expect.equals("x=1, y=2, z=3", C.foo<int>(1, 2, z: 3));
23+
Expect.equals("x=1, y=2, z=3", C.foo<int>(z: 3, 1, 2));
24+
Expect.equals("x=1, y=2, z=3", C.foo<int>(1, z: 3, 2));
25+
}

0 commit comments

Comments
 (0)