Skip to content

Commit edee53f

Browse files
committed
Bring back the deleted 1.0 corelib tests.
What is dead may never die. Change-Id: I80ef766b8ce2b6e1416df8e1f9b91fb74169dc79 Reviewed-on: https://dart-review.googlesource.com/7483 Reviewed-by: William Hesse <whesse@google.com>
1 parent 8762998 commit edee53f

File tree

340 files changed

+41929
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

340 files changed

+41929
-0
lines changed

PRESUBMIT.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ def _CheckNewTests(input_api, output_api):
102102
# Dart 1 tests DDC tests
103103
# ================= ==========================
104104
("tests/language/", "tests/language_2/"),
105+
("tests/corelib/", "tests/corelib_2/"),
105106
("tests/lib/", "tests/lib_2/"),
106107
("tests/html/", "tests/lib_2/html/"),
107108
]

tests/corelib/apply2_test.dart

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// Copyright (c) 2012, 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+
import "package:expect/expect.dart";
6+
7+
apply(Function function, List positional, Map<Symbol, dynamic> named) {
8+
return Function.apply(function, positional, named);
9+
}
10+
11+
void throwsNSME(function, positional, named) {
12+
Expect.throws(
13+
() => apply(function, positional, named), (e) => e is NoSuchMethodError);
14+
}
15+
16+
main() {
17+
var c1 = () => 'c1';
18+
var c2 = (a) => 'c2 $a';
19+
var c3 = ([a = 1]) => 'c3 $a';
20+
var c4 = ({a: 1}) => 'c4 $a';
21+
var c5 = ({a: 1, b: 2}) => 'c5 $a $b';
22+
var c6 = ({b: 1, a: 2}) => 'c6 $a $b';
23+
var c7 = (x, {b: 1, a: 2}) => 'c7 $x $a $b';
24+
var c8 = (x, y, [a = 2, b = 3]) => 'c8 $x $y $a $b';
25+
26+
Expect.equals('c1', apply(c1, null, null));
27+
Expect.equals('c1', apply(c1, [], null));
28+
Expect.equals('c1', apply(c1, [], {}));
29+
Expect.equals('c1', apply(c1, null, {}));
30+
throwsNSME(c1, [1], null);
31+
throwsNSME(c1, [1], {#a: 2});
32+
throwsNSME(c1, null, {#a: 2});
33+
34+
Expect.equals('c2 1', apply(c2, [1], null));
35+
Expect.equals('c2 1', apply(c2, [1], {}));
36+
throwsNSME(c2, null, null);
37+
throwsNSME(c2, [], null);
38+
throwsNSME(c2, null, {});
39+
throwsNSME(c2, null, {#a: 1});
40+
throwsNSME(c2, [2], {#a: 1});
41+
42+
Expect.equals('c3 1', apply(c3, null, null));
43+
Expect.equals('c3 1', apply(c3, [], null));
44+
Expect.equals('c3 2', apply(c3, [2], {}));
45+
throwsNSME(c3, [1, 2], null);
46+
throwsNSME(c3, null, {#a: 1});
47+
48+
Expect.equals('c4 1', apply(c4, [], null));
49+
Expect.equals('c4 2', apply(c4, [], {#a: 2}));
50+
Expect.equals('c4 1', apply(c4, null, null));
51+
Expect.equals('c4 1', apply(c4, [], {}));
52+
throwsNSME(c4, [1], {#a: 1});
53+
throwsNSME(c4, [1], {});
54+
throwsNSME(c4, [], {#a: 1, #b: 2});
55+
56+
Expect.equals('c5 1 2', apply(c5, [], null));
57+
Expect.equals('c5 3 2', apply(c5, [], {#a: 3}));
58+
Expect.equals('c5 1 2', apply(c5, null, null));
59+
Expect.equals('c5 1 2', apply(c5, [], {}));
60+
Expect.equals('c5 3 4', apply(c5, [], {#a: 3, #b: 4}));
61+
Expect.equals('c5 4 3', apply(c5, [], {#b: 3, #a: 4}));
62+
Expect.equals('c5 1 3', apply(c5, [], {#b: 3}));
63+
throwsNSME(c5, [1], {#a: 1});
64+
throwsNSME(c5, [1], {});
65+
throwsNSME(c5, [], {#a: 1, #b: 2, #c: 3});
66+
67+
Expect.equals('c6 2 1', apply(c6, [], null));
68+
Expect.equals('c6 3 1', apply(c6, [], {#a: 3}));
69+
Expect.equals('c6 2 1', apply(c6, null, null));
70+
Expect.equals('c6 2 1', apply(c6, [], {}));
71+
Expect.equals('c6 3 4', apply(c6, [], {#a: 3, #b: 4}));
72+
Expect.equals('c6 4 3', apply(c6, [], {#b: 3, #a: 4}));
73+
Expect.equals('c6 2 3', apply(c6, [], {#b: 3}));
74+
throwsNSME(c6, [1], {#a: 1});
75+
throwsNSME(c6, [1], {});
76+
throwsNSME(c6, [], {#a: 1, #b: 2, #c: 3});
77+
78+
Expect.equals('c7 7 2 1', apply(c7, [7], null));
79+
Expect.equals('c7 7 3 1', apply(c7, [7], {#a: 3}));
80+
Expect.equals('c7 7 2 1', apply(c7, [7], {}));
81+
Expect.equals('c7 7 3 4', apply(c7, [7], {#a: 3, #b: 4}));
82+
Expect.equals('c7 7 4 3', apply(c7, [7], {#b: 3, #a: 4}));
83+
Expect.equals('c7 7 2 3', apply(c7, [7], {#b: 3}));
84+
throwsNSME(c7, [], {#a: 1});
85+
throwsNSME(c7, [], {});
86+
throwsNSME(c7, [7], {#a: 1, #b: 2, #c: 3});
87+
88+
Expect.equals('c8 7 8 2 3', apply(c8, [7, 8], null));
89+
Expect.equals('c8 7 8 2 3', apply(c8, [7, 8], {}));
90+
Expect.equals('c8 7 8 3 3', apply(c8, [7, 8, 3], null));
91+
Expect.equals('c8 7 8 3 4', apply(c8, [7, 8, 3, 4], null));
92+
throwsNSME(c8, [], null);
93+
throwsNSME(c8, [], {});
94+
throwsNSME(c8, [1], null);
95+
throwsNSME(c8, [7, 8, 9, 10, 11], null);
96+
}

tests/corelib/apply3_test.dart

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright (c) 2013, 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+
// Test [Function.apply] on user-defined classes that implement [noSuchMethod].
6+
7+
import "package:expect/expect.dart";
8+
import 'dart:mirrors';
9+
10+
class F {
11+
call([p1]) => "call";
12+
noSuchMethod(Invocation invocation) => "NSM";
13+
}
14+
15+
class G {
16+
call() => '42';
17+
noSuchMethod(Invocation invocation) => invocation;
18+
}
19+
20+
class H {
21+
call(required, {a}) => required + a;
22+
}
23+
24+
main() {
25+
Expect.equals('call', Function.apply(new F(), []));
26+
Expect.equals('call', Function.apply(new F(), [1]));
27+
Expect.equals('NSM', Function.apply(new F(), [1, 2]));
28+
Expect.equals('NSM', Function.apply(new F(), [1, 2, 3]));
29+
30+
var symbol = const Symbol('a');
31+
var requiredParameters = [1];
32+
var optionalParameters = new Map()..[symbol] = 42;
33+
Invocation i =
34+
Function.apply(new G(), requiredParameters, optionalParameters);
35+
36+
Expect.equals(const Symbol('call'), i.memberName);
37+
Expect.listEquals(requiredParameters, i.positionalArguments);
38+
Expect.mapEquals(optionalParameters, i.namedArguments);
39+
Expect.isTrue(i.isMethod);
40+
Expect.isFalse(i.isGetter);
41+
Expect.isFalse(i.isSetter);
42+
Expect.isFalse(i.isAccessor);
43+
44+
// Check that changing the passed list and map for parameters does
45+
// not affect [i].
46+
requiredParameters[0] = 42;
47+
optionalParameters[symbol] = 12;
48+
Expect.listEquals([1], i.positionalArguments);
49+
Expect.mapEquals(new Map()..[symbol] = 42, i.namedArguments);
50+
51+
// Check that using [i] for invocation yields the same [Invocation]
52+
// object.
53+
var mirror = reflect(new G());
54+
Invocation other = mirror.delegate(i);
55+
Expect.equals(i.memberName, other.memberName);
56+
Expect.listEquals(i.positionalArguments, other.positionalArguments);
57+
Expect.mapEquals(i.namedArguments, other.namedArguments);
58+
Expect.equals(i.isMethod, other.isMethod);
59+
Expect.equals(i.isGetter, other.isGetter);
60+
Expect.equals(i.isSetter, other.isSetter);
61+
Expect.equals(i.isAccessor, other.isAccessor);
62+
63+
// Test that [i] can be used to hit an existing method.
64+
Expect.equals(43, new H().call(1, a: 42));
65+
Expect.equals(43, Function.apply(new H(), [1], new Map()..[symbol] = 42));
66+
mirror = reflect(new H());
67+
Expect.equals(43, mirror.delegate(i));
68+
Expect.equals(43, mirror.delegate(other));
69+
}

tests/corelib/apply4_test.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) 2015, 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+
import "package:expect/expect.dart";
6+
7+
// Testing Function.apply calls work correctly for arities that are not
8+
// otherwise present in the program (and thus might not have stubs
9+
// generated).
10+
11+
class A {
12+
foo(x, [y, z, a, b, c, d = 99, e, f, g, h, i, j]) => "$x $d";
13+
}
14+
15+
main() {
16+
var a = new A();
17+
var clos = a.foo;
18+
Expect.equals(Function.apply(clos, ["well"]), "well 99");
19+
Expect.equals(Function.apply(clos, ["well", 0, 2, 4, 3, 6, 9, 10]), "well 9");
20+
}

tests/corelib/apply5_test.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) 2016, 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+
import "package:expect/expect.dart";
6+
7+
// Testing that, when compiled to JS, Function.apply works correctly for
8+
// functions with that will be invoked directly vs using .apply().
9+
10+
class A {
11+
foo([a = 10, b = 20, c = 30, d = 40, e = 50]) => "$a $b $c $d $e";
12+
}
13+
14+
main() {
15+
var a = new A();
16+
var clos = a.foo;
17+
Expect.equals(Function.apply(clos, []), "10 20 30 40 50");
18+
Expect.equals(Function.apply(clos, [11]), "11 20 30 40 50");
19+
Expect.equals(Function.apply(clos, [11, 21]), "11 21 30 40 50");
20+
Expect.equals(Function.apply(clos, [11, 21, 31]), "11 21 31 40 50");
21+
Expect.equals(Function.apply(clos, [11, 21, 31, 41]), "11 21 31 41 50");
22+
Expect.equals(Function.apply(clos, [11, 21, 31, 41, 51]), "11 21 31 41 51");
23+
}

tests/corelib/apply_test.dart

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright (c) 2012, 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+
import "package:expect/expect.dart";
6+
import "symbol_map_helper.dart";
7+
8+
// Testing Function.apply calls correctly.
9+
// This test is not testing error handling, only that correct parameters
10+
// cause a correct call.
11+
12+
int test0() => 42;
13+
int test0a({int a}) => 37 + a;
14+
int test1(int i) => i + 1;
15+
int test1a(int i, {int a}) => i + a;
16+
int test2(int i, int j) => i + j;
17+
int test2a(int i, int j, {int a}) => i + j + a;
18+
19+
class C {
20+
int x = 10;
21+
int foo(y) => this.x + y;
22+
}
23+
24+
class Callable {
25+
int call(int x, int y) => x + y;
26+
}
27+
28+
@NoInline()
29+
@AssumeDynamic()
30+
confuse(x) => x;
31+
32+
main() {
33+
testMap(res, func, map) {
34+
map = symbolMapToStringMap(map);
35+
Expect.equals(res, Function.apply(func, null, map));
36+
Expect.equals(res, Function.apply(func, [], map));
37+
}
38+
39+
testList(res, func, list) {
40+
Expect.equals(res, Function.apply(func, list));
41+
Expect.equals(res, Function.apply(func, list, null));
42+
Expect.equals(res, Function.apply(func, list, new Map<Symbol, dynamic>()));
43+
}
44+
45+
test(res, func, list, map) {
46+
map = symbolMapToStringMap(map);
47+
Expect.equals(res, Function.apply(func, list, map));
48+
}
49+
50+
testList(42, test0, null);
51+
testList(42, test0, []);
52+
testMap(42, test0a, {"a": 5});
53+
testList(42, test1, [41]);
54+
test(42, test1a, [20], {"a": 22});
55+
testList(42, test2, [20, 22]);
56+
test(42, test2a, [10, 15], {"a": 17});
57+
58+
// Test that "this" is correct when calling closurized functions.
59+
var cfoo = new C().foo;
60+
testList(42, cfoo, [32]);
61+
62+
// Test that apply works even with a different name.
63+
var app = confuse(Function.apply);
64+
Expect.equals(42, app(test2, [22, 20]));
65+
66+
// Test that apply can itself be applied.
67+
Expect.equals(
68+
42,
69+
Function.apply(Function.apply, [
70+
test2,
71+
[17, 25]
72+
]));
73+
74+
// Test that apply works on callable objects.
75+
testList(42, new Callable(), [13, 29]);
76+
}

0 commit comments

Comments
 (0)