Skip to content

Commit 284f662

Browse files
munificentcommit-bot@chromium.org
authored andcommitted
Migrate the corelib_2/ tests starting with "e" through "i".
Change-Id: I764d0457da85b2935e1d83309eab4c4b5b3ea000 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/126204 Commit-Queue: Bob Nystrom <rnystrom@google.com> Reviewed-by: Lasse R.H. Nielsen <lrn@google.com> Auto-Submit: Bob Nystrom <rnystrom@google.com>
1 parent a4d799c commit 284f662

File tree

77 files changed

+6669
-2
lines changed

Some content is hidden

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

77 files changed

+6669
-2
lines changed

sdk_nnbd/lib/core/invocation.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ abstract class Invocation {
2121
* If the named arguments are omitted, they default to no named arguments.
2222
*/
2323
factory Invocation.method(
24-
Symbol memberName, Iterable<Object?> positionalArguments,
24+
Symbol memberName, Iterable<Object?>? positionalArguments,
2525
[Map<Symbol, Object?>? namedArguments]) =>
2626
_Invocation.method(memberName, null, positionalArguments, namedArguments);
2727

@@ -35,7 +35,7 @@ abstract class Invocation {
3535
* If the named arguments are omitted, they default to no named arguments.
3636
*/
3737
factory Invocation.genericMethod(Symbol memberName,
38-
Iterable<Type> typeArguments, Iterable<Object?> positionalArguments,
38+
Iterable<Type>? typeArguments, Iterable<Object?>? positionalArguments,
3939
[Map<Symbol, Object?>? namedArguments]) =>
4040
_Invocation.method(
4141
memberName, typeArguments, positionalArguments, namedArguments);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
import "package:expect/expect.dart";
6+
7+
class A {
8+
static Aa() => Ab();
9+
static Ab() => Ac();
10+
static Ac() => throw "abc";
11+
}
12+
13+
class B {
14+
static Ba() => Bb();
15+
static Bb() => Bc();
16+
static Bc() {
17+
try {
18+
A.Aa();
19+
} catch (e) {
20+
// This should produce a NoSuchMethodError.
21+
var trace = e.stackTrace;
22+
}
23+
}
24+
}
25+
26+
main() {
27+
bool hasThrown = false;
28+
try {
29+
B.Ba();
30+
} catch (e, stackTrace) {
31+
hasThrown = true;
32+
var trace = stackTrace.toString();
33+
print(trace);
34+
Expect.isTrue(trace.contains("Bc"));
35+
Expect.isTrue(trace.contains("Bb"));
36+
Expect.isTrue(trace.contains("Ba"));
37+
Expect.isTrue(trace.contains("main"));
38+
}
39+
Expect.isTrue(hasThrown);
40+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
import "package:expect/expect.dart";
6+
7+
class A {
8+
get foo => cyclicStatic;
9+
}
10+
11+
var a = new A();
12+
dynamic cyclicStatic = (() => a.foo + 1)();
13+
14+
cyclicInitialization() {
15+
return cyclicStatic;
16+
}
17+
18+
main() {
19+
bool hasThrown = false;
20+
try {
21+
cyclicStatic + 1;
22+
} catch (e2) {
23+
var e = e2;
24+
hasThrown = true;
25+
Expect.isTrue(
26+
e.stackTrace is StackTrace, "$e doesn't have a non-null stack trace");
27+
}
28+
Expect.isTrue(hasThrown);
29+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
import "package:expect/expect.dart";
6+
7+
void argument() {
8+
throw new ArgumentError(499);
9+
}
10+
11+
// Verify that
12+
void noSuchMethod() {
13+
(499 as dynamic).doesNotExist();
14+
}
15+
16+
void nullThrown() {
17+
throw null as dynamic;
18+
}
19+
20+
void range() {
21+
throw new RangeError.range(0, 1, 2);
22+
}
23+
24+
abstract class A {
25+
foo();
26+
}
27+
28+
void unsupported() {
29+
throw new UnsupportedError("unsupported");
30+
}
31+
32+
void unimplemented() {
33+
throw new UnimplementedError("unimplemented");
34+
}
35+
36+
void state() {
37+
[1, 2].single;
38+
}
39+
40+
void cast() {
41+
dynamic d = 1;
42+
d as String;
43+
}
44+
45+
main() {
46+
List<Function> errorFunctions = [
47+
argument,
48+
noSuchMethod,
49+
nullThrown, //# nullThrown: ok
50+
range,
51+
unsupported,
52+
unimplemented,
53+
state,
54+
cast,
55+
];
56+
57+
for (var f in errorFunctions) {
58+
bool hasThrown = false;
59+
try {
60+
f();
61+
} catch (e) {
62+
hasThrown = true;
63+
Expect.isTrue(
64+
e.stackTrace is StackTrace, "$e doesn't have a non-null stack trace");
65+
}
66+
Expect.isTrue(hasThrown);
67+
}
68+
}

tests/corelib/errors_test.dart

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
// Test that error constructors do what they are documented as doing.
8+
9+
main() {
10+
Expect.equals("Invalid argument(s)", new ArgumentError().toString());
11+
Expect.equals(
12+
"Invalid argument(s): message", new ArgumentError("message").toString());
13+
Expect.equals(
14+
"Invalid argument: null", new ArgumentError.value(null).toString());
15+
Expect.equals("Invalid argument: 42", new ArgumentError.value(42).toString());
16+
Expect.equals(
17+
"Invalid argument: \"bad\"", new ArgumentError.value("bad").toString());
18+
Expect.equals("Invalid argument (foo): null",
19+
new ArgumentError.value(null, "foo").toString());
20+
Expect.equals("Invalid argument (foo): 42",
21+
new ArgumentError.value(42, "foo").toString());
22+
Expect.equals("Invalid argument (foo): message: 42",
23+
new ArgumentError.value(42, "foo", "message").toString());
24+
Expect.equals("Invalid argument: message: 42",
25+
new ArgumentError.value(42, null, "message").toString());
26+
Expect.equals("Invalid argument(s): Must not be null",
27+
new ArgumentError.notNull().toString());
28+
Expect.equals("Invalid argument(s) (foo): Must not be null",
29+
new ArgumentError.notNull("foo").toString());
30+
31+
Expect.equals("RangeError", new RangeError(null).toString());
32+
Expect.equals("RangeError: message", new RangeError("message").toString());
33+
Expect.equals("RangeError: Value not in range: 42",
34+
new RangeError.value(42).toString());
35+
Expect.equals("RangeError (foo): Value not in range: 42",
36+
new RangeError.value(42, "foo").toString());
37+
Expect.equals("RangeError (foo): message: 42",
38+
new RangeError.value(42, "foo", "message").toString());
39+
Expect.equals("RangeError: message: 42",
40+
new RangeError.value(42, null, "message").toString());
41+
42+
Expect.equals("RangeError: Invalid value: Not in range 2..9, inclusive: 42",
43+
new RangeError.range(42, 2, 9).toString());
44+
Expect.equals(
45+
"RangeError (foo): Invalid value: Not in range 2..9, "
46+
"inclusive: 42",
47+
new RangeError.range(42, 2, 9, "foo").toString());
48+
Expect.equals("RangeError (foo): message: Not in range 2..9, inclusive: 42",
49+
new RangeError.range(42, 2, 9, "foo", "message").toString());
50+
Expect.equals("RangeError: message: Not in range 2..9, inclusive: 42",
51+
new RangeError.range(42, 2, 9, null, "message").toString());
52+
53+
Expect.equals(
54+
"RangeError: Index out of range: "
55+
"index should be less than 3: 42",
56+
new RangeError.index(42, [1, 2, 3]).toString());
57+
Expect.equals(
58+
"RangeError (foo): Index out of range: "
59+
"index should be less than 3: 42",
60+
new RangeError.index(42, [1, 2, 3], "foo").toString());
61+
Expect.equals(
62+
"RangeError (foo): message: "
63+
"index should be less than 3: 42",
64+
new RangeError.index(42, [1, 2, 3], "foo", "message").toString());
65+
Expect.equals(
66+
"RangeError: message: "
67+
"index should be less than 3: 42",
68+
new RangeError.index(42, [1, 2, 3], null, "message").toString());
69+
Expect.equals(
70+
"RangeError (foo): message: "
71+
"index should be less than 2: 42",
72+
new RangeError.index(42, [1, 2, 3], "foo", "message", 2).toString());
73+
Expect.equals(
74+
"RangeError: Index out of range: "
75+
"index must not be negative: -5",
76+
new RangeError.index(-5, [1, 2, 3]).toString());
77+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2011, 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+
library exception_implementation_test;
6+
7+
import "package:expect/expect.dart";
8+
9+
main() {
10+
final msg = 1;
11+
try {
12+
throw new Exception(msg);
13+
Expect.fail("Unreachable");
14+
} on Exception catch (e) {
15+
Expect.isTrue(e is Exception);
16+
Expect.equals("Exception: $msg", e.toString());
17+
}
18+
}

tests/corelib/expando_test.dart

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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+
class ExpandoTest {
8+
static Expando<int> visits = Expando('visits');
9+
10+
static testMain() {
11+
var legal = [
12+
new Object(),
13+
new List(),
14+
[1, 2, 3],
15+
const [1, 2, 3],
16+
new Map(),
17+
{'x': 1, 'y': 2},
18+
const {'x': 1, 'y': 2},
19+
new Expando(),
20+
new Expando('horse')
21+
];
22+
for (var object in legal) {
23+
testNamedExpando(object);
24+
testUnnamedExpando(object);
25+
}
26+
for (var object in legal) {
27+
Expect.equals(2, visits[object], "$object");
28+
}
29+
testIllegal();
30+
testIdentity();
31+
}
32+
33+
static visit(object) {
34+
int count = visits[object]!;
35+
count = (count == null) ? 1 : count + 1;
36+
visits[object] = count;
37+
}
38+
39+
static testNamedExpando(object) {
40+
Expando<int> expando = new Expando<int>('myexpando');
41+
Expect.equals('myexpando', expando.name);
42+
Expect.isTrue(expando.toString().startsWith('Expando:myexpando'));
43+
testExpando(expando, object);
44+
}
45+
46+
static testUnnamedExpando(object) {
47+
Expando<int> expando = new Expando<int>();
48+
Expect.isNull(expando.name);
49+
Expect.isTrue(expando.toString().startsWith('Expando:'));
50+
testExpando(expando, object);
51+
}
52+
53+
static testExpando(Expando<int> expando, object) {
54+
visit(object);
55+
56+
Expect.isNull(expando[object]);
57+
expando[object] = 42;
58+
Expect.equals(42, expando[object]);
59+
expando[object] = null;
60+
Expect.isNull(expando[object]);
61+
62+
Expando<int> alternative = new Expando('myexpando');
63+
Expect.isNull(alternative[object]);
64+
alternative[object] = 87;
65+
Expect.isNull(expando[object]);
66+
expando[object] = 99;
67+
Expect.equals(99, expando[object]);
68+
Expect.equals(87, alternative[object]);
69+
}
70+
71+
static testIllegal() {
72+
Expando<int> expando = new Expando<int>();
73+
Expect.throwsArgumentError(() => expando['string'], "'string'");
74+
Expect.throwsArgumentError(() => expando[42], "42");
75+
Expect.throwsArgumentError(() => expando[42.87], "42.87");
76+
Expect.throwsArgumentError(() => expando[true], "true");
77+
Expect.throwsArgumentError(() => expando[false], "false");
78+
}
79+
80+
static testIdentity() {
81+
// Expando only depends on identity of object.
82+
Expando<int> expando = new Expando<int>();
83+
var m1 = new Mutable(1);
84+
var m2 = new Mutable(7);
85+
var m3 = new Mutable(13);
86+
expando[m1] = 42;
87+
Expect.equals(42, expando[m1]);
88+
m1.id = 37;
89+
Expect.equals(42, expando[m1]);
90+
expando[m2] = 37;
91+
expando[m3] = 10;
92+
m3.id = 1;
93+
Expect.equals(42, expando[m1]);
94+
Expect.equals(37, expando[m2]);
95+
Expect.equals(10, expando[m3]);
96+
}
97+
}
98+
99+
main() => ExpandoTest.testMain();
100+
101+
class Mutable {
102+
int id;
103+
Mutable(this.id);
104+
int get hashCode => id;
105+
bool operator ==(other) => other is Mutable && other.id == id;
106+
}

0 commit comments

Comments
 (0)