Use the Expect.throws___() helper methods throughout tests.

No behavioral changes, just getting rid of a lot of redundant closures
and helper functions.

Change-Id: I55c52c2cc9e5505bb64203c31aad8d76847f8eeb
Reviewed-on: https://dart-review.googlesource.com/14320
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Reviewed-by: William Hesse <whesse@google.com>
This commit is contained in:
Bob Nystrom 2017-10-17 23:37:15 +00:00 committed by commit-bot@chromium.org
parent 02252479ff
commit 07b9df22ac
196 changed files with 1178 additions and 1745 deletions

View file

@ -456,37 +456,45 @@ class Expect {
_fail('Expect.throws$msg fails: Did not throw');
}
static void throwsArgumentError(void f()) {
Expect.throws(f, (error) => error is ArgumentError, "ArgumentError");
}
static void throwsAssertionError(void f()) {
Expect.throws(f, (error) => error is AssertionError, "AssertionError");
}
static void throwsCastError(void f()) {
Expect.throws(f, (error) => error is CastError, "CastError");
}
static void throwsNoSuchMethodError(void f()) {
static void throwsArgumentError(void f(), [String reason]) {
Expect.throws(
f, (error) => error is NoSuchMethodError, "NoSuchMethodError");
f, (error) => error is ArgumentError, reason ?? "ArgumentError");
}
static void throwsRangeError(void f()) {
Expect.throws(f, (error) => error is RangeError, "RangeError");
static void throwsAssertionError(void f(), [String reason]) {
Expect.throws(
f, (error) => error is AssertionError, reason ?? "AssertionError");
}
static void throwsStateError(void f()) {
Expect.throws(f, (error) => error is StateError, "StateError");
static void throwsCastError(void f(), [String reason]) {
Expect.throws(f, (error) => error is CastError, reason ?? "CastError");
}
static void throwsTypeError(void f()) {
Expect.throws(f, (error) => error is TypeError, "TypeError");
static void throwsFormatException(void f(), [String reason]) {
Expect.throws(
f, (error) => error is FormatException, reason ?? "FormatException");
}
static void throwsUnsupportedError(void f()) {
Expect.throws(f, (error) => error is UnsupportedError, "UnsupportedError");
static void throwsNoSuchMethodError(void f(), [String reason]) {
Expect.throws(f, (error) => error is NoSuchMethodError,
reason ?? "NoSuchMethodError");
}
static void throwsRangeError(void f(), [String reason]) {
Expect.throws(f, (error) => error is RangeError, reason ?? "RangeError");
}
static void throwsStateError(void f(), [String reason]) {
Expect.throws(f, (error) => error is StateError, reason ?? "StateError");
}
static void throwsTypeError(void f(), [String reason]) {
Expect.throws(f, (error) => error is TypeError, reason ?? "TypeError");
}
static void throwsUnsupportedError(void f(), [String reason]) {
Expect.throws(
f, (error) => error is UnsupportedError, reason ?? "UnsupportedError");
}
static String _getMessage(String reason) =>

View file

@ -9,8 +9,7 @@ apply(Function function, List positional, Map<Symbol, dynamic> named) {
}
void throwsNSME(function, positional, named) {
Expect.throws(
() => apply(function, positional, named), (e) => e is NoSuchMethodError);
Expect.throwsNoSuchMethodError(() => apply(function, positional, named));
}
main() {

View file

@ -10,18 +10,8 @@ main() {
testImmutable(const [1, 2]);
}
void expectUOE(f()) {
Expect.throws(f, (e) => e is UnsupportedError);
}
testImmutable(var list) {
expectUOE(() {
list.removeRange(0, 0);
});
expectUOE(() {
list.removeRange(0, 1);
});
expectUOE(() {
list.removeRange(-1, 1);
});
Expect.throwsUnsupportedError(() => list.removeRange(0, 0));
Expect.throwsUnsupportedError(() => list.removeRange(0, 1));
Expect.throwsUnsupportedError(() => list.removeRange(-1, 1));
}

View file

@ -10,42 +10,16 @@ main() {
testImmutable(const [1, 2]);
}
void expectUOE(f()) {
Expect.throws(f, (e) => e is UnsupportedError);
}
testImmutable(List list) {
expectUOE(() {
list.setRange(0, 0, const []);
});
expectUOE(() {
list.setRange(0, 1, const [], 1);
});
expectUOE(() {
list.setRange(0, 1, const []);
});
expectUOE(() {
list.setRange(0, 0, []);
});
expectUOE(() {
list.setRange(0, 1, [], 1);
});
expectUOE(() {
list.setRange(0, 1, []);
});
expectUOE(() {
list.setRange(0, 0, const [1]);
});
expectUOE(() {
list.setRange(0, 1, const [1]);
});
expectUOE(() {
list.setRange(0, 0, [1]);
});
expectUOE(() {
list.setRange(0, 1, [1]);
});
expectUOE(() {
list.setRange(0, 1, [1], 1);
});
Expect.throwsUnsupportedError(() => list.setRange(0, 0, const []));
Expect.throwsUnsupportedError(() => list.setRange(0, 1, const [], 1));
Expect.throwsUnsupportedError(() => list.setRange(0, 1, const []));
Expect.throwsUnsupportedError(() => list.setRange(0, 0, []));
Expect.throwsUnsupportedError(() => list.setRange(0, 1, [], 1));
Expect.throwsUnsupportedError(() => list.setRange(0, 1, []));
Expect.throwsUnsupportedError(() => list.setRange(0, 0, const [1]));
Expect.throwsUnsupportedError(() => list.setRange(0, 1, const [1]));
Expect.throwsUnsupportedError(() => list.setRange(0, 0, [1]));
Expect.throwsUnsupportedError(() => list.setRange(0, 1, [1]));
Expect.throwsUnsupportedError(() => list.setRange(0, 1, [1], 1));
}

View file

@ -187,51 +187,32 @@ void testNormalization() {
uri.toString());
}
bool badArgument(e) => e is ArgumentError;
bool badFormat(e) => e is FormatException;
void testErrors() {
// Invalid constructor parameters.
Expect.throws(() {
new UriData.fromBytes([], mimeType: "noslash");
}, badArgument);
Expect.throws(() {
new UriData.fromBytes([257]);
}, badArgument);
Expect.throws(() {
new UriData.fromBytes([-1]);
}, badArgument);
Expect.throws(() {
new UriData.fromBytes([0x10000000]);
}, badArgument);
Expect.throws(() {
new UriData.fromString("", mimeType: "noslash");
}, badArgument);
Expect.throwsArgumentError(
() => new UriData.fromBytes([], mimeType: "noslash"));
Expect.throwsArgumentError(() => new UriData.fromBytes([257]));
Expect.throwsArgumentError(() => new UriData.fromBytes([-1]));
Expect.throwsArgumentError(() => new UriData.fromBytes([0x10000000]));
Expect.throwsArgumentError(
() => new UriData.fromString("", mimeType: "noslash"));
Expect.throws(() {
new Uri.dataFromBytes([], mimeType: "noslash");
}, badArgument);
Expect.throws(() {
new Uri.dataFromBytes([257]);
}, badArgument);
Expect.throws(() {
new Uri.dataFromBytes([-1]);
}, badArgument);
Expect.throws(() {
new Uri.dataFromBytes([0x10000000]);
}, badArgument);
Expect.throws(() {
new Uri.dataFromString("", mimeType: "noslash");
}, badArgument);
Expect.throwsArgumentError(
() => new Uri.dataFromBytes([], mimeType: "noslash"));
Expect.throwsArgumentError(() => new Uri.dataFromBytes([257]));
Expect.throwsArgumentError(() => new Uri.dataFromBytes([-1]));
Expect.throwsArgumentError(() => new Uri.dataFromBytes([0x10000000]));
Expect.throwsArgumentError(
() => new Uri.dataFromString("", mimeType: "noslash"));
// Empty parameters allowed, not an error.
var uri = new UriData.fromString("", mimeType: "", parameters: {});
Expect.equals("data:,", "$uri");
// Empty parameter key or value is an error.
Expect.throws(
() => new UriData.fromString("", parameters: {"": "X"}), badArgument);
Expect.throws(
() => new UriData.fromString("", parameters: {"X": ""}), badArgument);
Expect.throwsArgumentError(
() => new UriData.fromString("", parameters: {"": "X"}));
Expect.throwsArgumentError(
() => new UriData.fromString("", parameters: {"X": ""}));
// Not recognizing charset is an error.
uri = UriData.parse("data:;charset=arglebargle,X");
@ -242,36 +223,21 @@ void testErrors() {
Expect.equals("X", uri.contentAsString(encoding: ASCII));
// Parse format.
Expect.throws(() {
UriData.parse("notdata:,");
}, badFormat);
Expect.throws(() {
UriData.parse("text/plain,noscheme");
}, badFormat);
Expect.throws(() {
UriData.parse("data:noseparator");
}, badFormat);
Expect.throws(() {
UriData.parse("data:noslash,text");
}, badFormat);
Expect.throws(() {
UriData.parse("data:type/sub;noequals,text");
}, badFormat);
Expect.throws(() {
UriData.parse("data:type/sub;knocomma=");
}, badFormat);
Expect.throws(() {
UriData.parse("data:type/sub;k=v;nocomma");
}, badFormat);
Expect.throws(() {
UriData.parse("data:type/sub;k=nocomma");
}, badFormat);
Expect.throws(() {
UriData.parse("data:type/sub;k=v;base64");
}, badFormat);
Expect.throwsFormatException(() => UriData.parse("notdata:,"));
Expect.throwsFormatException(() => UriData.parse("text/plain,noscheme"));
Expect.throwsFormatException(() => UriData.parse("data:noseparator"));
Expect.throwsFormatException(() => UriData.parse("data:noslash,text"));
Expect.throwsFormatException(
() => UriData.parse("data:type/sub;noequals,text"));
Expect.throwsFormatException(() => UriData.parse("data:type/sub;knocomma="));
Expect.throwsFormatException(
() => UriData.parse("data:type/sub;k=v;nocomma"));
Expect.throwsFormatException(() => UriData.parse("data:type/sub;k=nocomma"));
Expect.throwsFormatException(() => UriData.parse("data:type/sub;k=v;base64"));
void formatError(String input) {
Expect.throws(() => UriData.parse("data:;base64,$input"), badFormat, input);
Expect.throwsFormatException(() => UriData.parse("data:;base64,$input"),
input);
}
// Invalid base64 format (detected when parsed).

View file

@ -1201,32 +1201,32 @@ void testDateStrings() {
Expect.equals(9, dt1.millisecond);
Expect.equals(true, dt1.isUtc);
Expect.throws(() => DateTime.parse("bad"), (e) => e is FormatException);
Expect.throwsFormatException(() => DateTime.parse("bad"));
var bad_year =
1970 + (_MAX_MILLISECONDS ~/ (1000 * 60 * 60 * 24 * 365.2425)) + 1;
Expect.throws(() => DateTime.parse(bad_year.toString() + "-01-01"),
(e) => e is FormatException);
Expect.throwsFormatException(
() => DateTime.parse(bad_year.toString() + "-01-01"));
// The last valid time; should not throw.
dt1 = DateTime.parse("275760-09-13T00:00:00.000Z");
Expect.throws(() => DateTime.parse("275760-09-14T00:00:00.000Z"),
(e) => e is FormatException);
Expect.throws(() => DateTime.parse("275760-09-13T00:00:00.001Z"),
(e) => e is FormatException);
Expect.throwsFormatException(
() => DateTime.parse("275760-09-14T00:00:00.000Z"));
Expect.throwsFormatException(
() => DateTime.parse("275760-09-13T00:00:00.001Z"));
if (supportsMicroseconds) {
Expect.throws(() => DateTime.parse("275760-09-13T00:00:00.000001Z"),
(e) => e is FormatException);
Expect.throwsFormatException(
() => DateTime.parse("275760-09-13T00:00:00.000001Z"));
} else {
dt1 = DateTime.parse("275760-09-13T00:00:00.000001Z");
}
// first valid time; should not throw.
dt1 = DateTime.parse("-271821-04-20T00:00:00.000Z");
Expect.throws(() => DateTime.parse("-271821-04-19T23:59:59.999Z"),
(e) => e is FormatException);
Expect.throwsFormatException(
() => DateTime.parse("-271821-04-19T23:59:59.999Z"));
if (supportsMicroseconds) {
Expect.throws(() => DateTime.parse("-271821-04-19T23:59:59.999999Z"),
(e) => e is FormatException);
Expect.throwsFormatException(
() => DateTime.parse("-271821-04-19T23:59:59.999999Z"));
}
}

View file

@ -5,8 +5,7 @@
import 'package:expect/expect.dart';
main() {
Expect.throws(() => double.INFINITY.ceil(), (e) => e is UnsupportedError);
Expect.throws(
() => double.NEGATIVE_INFINITY.ceil(), (e) => e is UnsupportedError);
Expect.throws(() => double.NAN.ceil(), (e) => e is UnsupportedError);
Expect.throwsUnsupportedError(() => double.INFINITY.ceil());
Expect.throwsUnsupportedError(() => double.NEGATIVE_INFINITY.ceil());
Expect.throwsUnsupportedError(() => double.NAN.ceil());
}

View file

@ -5,8 +5,7 @@
import 'package:expect/expect.dart';
main() {
Expect.throws(() => double.INFINITY.floor(), (e) => e is UnsupportedError);
Expect.throws(
() => double.NEGATIVE_INFINITY.floor(), (e) => e is UnsupportedError);
Expect.throws(() => double.NAN.floor(), (e) => e is UnsupportedError);
Expect.throwsUnsupportedError(() => double.INFINITY.floor());
Expect.throwsUnsupportedError(() => double.NEGATIVE_INFINITY.floor());
Expect.throwsUnsupportedError(() => double.NAN.floor());
}

View file

@ -5,8 +5,7 @@
import 'package:expect/expect.dart';
main() {
Expect.throws(() => double.INFINITY.round(), (e) => e is UnsupportedError);
Expect.throws(
() => double.NEGATIVE_INFINITY.round(), (e) => e is UnsupportedError);
Expect.throws(() => double.NAN.round(), (e) => e is UnsupportedError);
Expect.throwsUnsupportedError(() => double.INFINITY.round());
Expect.throwsUnsupportedError(() => double.NEGATIVE_INFINITY.round());
Expect.throwsUnsupportedError(() => double.NAN.round());
}

View file

@ -5,8 +5,7 @@
import 'package:expect/expect.dart';
main() {
Expect.throws(() => double.INFINITY.truncate(), (e) => e is UnsupportedError);
Expect.throws(
() => double.NEGATIVE_INFINITY.truncate(), (e) => e is UnsupportedError);
Expect.throws(() => double.NAN.truncate(), (e) => e is UnsupportedError);
Expect.throwsUnsupportedError(() => double.INFINITY.truncate());
Expect.throwsUnsupportedError(() => double.NEGATIVE_INFINITY.truncate());
Expect.throwsUnsupportedError(() => double.NAN.truncate());
}

View file

@ -62,18 +62,18 @@ main() {
// Verify that noSuchMethod errors are triggered even when the JS object
// happens to have a matching member name.
dynamic f = new Foo();
Expect.throws(() => f.prototype, (e) => e is NoSuchMethodError);
Expect.throws(() => f.prototype(), (e) => e is NoSuchMethodError);
Expect.throws(() => f.prototype = 42, (e) => e is NoSuchMethodError);
Expect.throwsNoSuchMethodError(() => f.prototype);
Expect.throwsNoSuchMethodError(() => f.prototype());
Expect.throwsNoSuchMethodError(() => f.prototype = 42);
Expect.throws(() => f.constructor, (e) => e is NoSuchMethodError);
Expect.throws(() => f.constructor(), (e) => e is NoSuchMethodError);
Expect.throws(() => f.constructor = 42, (e) => e is NoSuchMethodError);
Expect.throwsNoSuchMethodError(() => f.constructor);
Expect.throwsNoSuchMethodError(() => f.constructor());
Expect.throwsNoSuchMethodError(() => f.constructor = 42);
Expect.throws(() => f.__proto__, (e) => e is NoSuchMethodError);
Expect.throwsNoSuchMethodError(() => f.__proto__);
// These are valid JS properties but not Dart methods.
Expect.throws(() => f.toLocaleString, (e) => e is NoSuchMethodError);
Expect.throwsNoSuchMethodError(() => f.toLocaleString);
Expect.throws(() => f.hasOwnProperty, (e) => e is NoSuchMethodError);
Expect.throwsNoSuchMethodError(() => f.hasOwnProperty);
}

View file

@ -71,20 +71,12 @@ class ExpandoTest {
static testIllegal() {
Expando<int> expando = new Expando<int>();
Expect.throws(
() => expando[null], (exception) => exception is ArgumentError, "null");
Expect.throws(() => expando['string'],
(exception) => exception is ArgumentError, "'string'");
Expect.throws(() => expando['string'],
(exception) => exception is ArgumentError, "'string'");
Expect.throws(
() => expando[42], (exception) => exception is ArgumentError, "42");
Expect.throws(() => expando[42.87],
(exception) => exception is ArgumentError, "42.87");
Expect.throws(
() => expando[true], (exception) => exception is ArgumentError, "true");
Expect.throws(() => expando[false],
(exception) => exception is ArgumentError, "false");
Expect.throwsArgumentError(() => expando[null], "null");
Expect.throwsArgumentError(() => expando['string'], "'string'");
Expect.throwsArgumentError(() => expando[42], "42");
Expect.throwsArgumentError(() => expando[42.87], "42.87");
Expect.throwsArgumentError(() => expando[true], "true");
Expect.throwsArgumentError(() => expando[false], "false");
}
static testIdentity() {

View file

@ -78,6 +78,8 @@ void testConstructor() {
Expect.equals(length, list.length);
}
// TODO(rnystrom): Checked-mode specific behavior does not apply to Dart 2.0.
// Revisit this.
bool checked = false;
assert((checked = true));
testThrowsOrTypeError(fn, test, [name]) {
@ -91,11 +93,10 @@ void testConstructor() {
testGrowable(new List<int>());
testGrowable(new List<int>()..length = 5);
testGrowable(new List<int>.filled(5, null, growable: true));
Expect.throws(() => new List<int>(-1), (e) => e is ArgumentError, "-1");
Expect.throwsArgumentError(() => new List<int>(-1), "-1");
// There must be limits. Fix this test if we ever allow 10^30 elements.
Expect.throws(() => new List<int>(0x7fffffffffffffff),
(e) => e is ArgumentError, "bignum");
Expect.throws(() => new List<int>(null), (e) => e is ArgumentError, "null");
Expect.throwsArgumentError(() => new List<int>(0x7fffffffffffffff), "bignum");
Expect.throwsArgumentError(() => new List<int>(null), "null");
testThrowsOrTypeError(
() => new List([] as Object), // Cast to avoid warning.
(e) => e is ArgumentError,

View file

@ -11,7 +11,7 @@ main() {
var it = new HasNextIterator([].iterator);
Expect.isFalse(it.hasNext);
Expect.isFalse(it.hasNext);
Expect.throws(() => it.next(), (e) => e is StateError);
Expect.throwsStateError(() => it.next());
Expect.isFalse(it.hasNext);
it = new HasNextIterator([1].iterator);
@ -20,7 +20,7 @@ main() {
Expect.equals(1, it.next());
Expect.isFalse(it.hasNext);
Expect.isFalse(it.hasNext);
Expect.throws(() => it.next(), (e) => e is StateError);
Expect.throwsStateError(() => it.next());
Expect.isFalse(it.hasNext);
it = new HasNextIterator([1, 2].iterator);
@ -32,6 +32,6 @@ main() {
Expect.equals(2, it.next());
Expect.isFalse(it.hasNext);
Expect.isFalse(it.hasNext);
Expect.throws(() => it.next(), (e) => e is StateError);
Expect.throwsStateError(() => it.next());
Expect.isFalse(it.hasNext);
}

View file

@ -114,8 +114,7 @@ void main() {
}
testBadTypes(var source, var radix) {
Expect.throws(() => int.parse(source, radix: radix, onError: (s) => 0), //# badTypes: ok
(e) => e is TypeError); //# badTypes: ok
Expect.throwsTypeError(() => int.parse(source, radix: radix, onError: (s) => 0)); //# badTypes: ok
}
testBadTypes(9, 10);
@ -125,8 +124,8 @@ void main() {
testBadArguments(String source, int radix) {
// If the types match, it should be an ArgumentError of some sort.
Expect.throws(() => int.parse(source, radix: radix, onError: (s) => 0),
(e) => e is ArgumentError);
Expect.throwsArgumentError(
() => int.parse(source, radix: radix, onError: (s) => 0));
}
testBadArguments("0", -1);

View file

@ -21,8 +21,7 @@ main() {
Expect.equals(-0x7fffffffffffffff, int.parse("-0x7fffffffffffffff"));
Expect.equals(-0x7fffffffffffffff - 1, int.parse("-0x8000000000000000"));
Expect.throws(
() => int.parse("0x8000000000000000"), (e) => e is FormatException);
Expect.throwsFormatException(() => int.parse("0x8000000000000000"));
Expect.equals(ERROR, int.parse("0x8000000000000000", onError: returnError));
Expect.equals(ERROR, int.parse("-0x8000000000000001", onError: returnError));

View file

@ -16,24 +16,24 @@ main() {
Expect.equals(2, list1.elementAt(1));
Expect.equals(3, list1.elementAt(2));
list1.elementAt("2"); //# static: compile-time error
Expect.throws(() => list1.elementAt(-1), (e) => e is ArgumentError);
Expect.throws(() => list1.elementAt(3), (e) => e is RangeError);
Expect.throwsArgumentError(() => list1.elementAt(-1));
Expect.throwsRangeError(() => list1.elementAt(3));
Expect.equals(4, list2.elementAt(0));
Expect.equals(5, list2.elementAt(1));
Expect.equals(6, list2.elementAt(2));
list2.elementAt("2"); //# static: compile-time error
Expect.throws(() => list2.elementAt(-1), (e) => e is ArgumentError);
Expect.throws(() => list2.elementAt(3), (e) => e is RangeError);
Expect.throwsArgumentError(() => list2.elementAt(-1));
Expect.throwsRangeError(() => list2.elementAt(3));
Expect.isTrue(set1.contains(set1.elementAt(0)));
Expect.isTrue(set1.contains(set1.elementAt(1)));
Expect.isTrue(set1.contains(set1.elementAt(2)));
Expect.throws(() => set1.elementAt(-1), (e) => e is ArgumentError);
Expect.throws(() => set1.elementAt(3), (e) => e is RangeError);
Expect.throwsArgumentError(() => set1.elementAt(-1));
Expect.throwsRangeError(() => set1.elementAt(3));
set2.elementAt("2"); //# static: compile-time error
Expect.throws(() => set2.elementAt(-1), (e) => e is ArgumentError);
Expect.throws(() => set2.elementAt(0), (e) => e is RangeError);
Expect.throws(() => set2.elementAt(1), (e) => e is RangeError);
Expect.throwsArgumentError(() => set2.elementAt(-1));
Expect.throwsRangeError(() => set2.elementAt(0));
Expect.throwsRangeError(() => set2.elementAt(1));
}

View file

@ -12,13 +12,12 @@ main() {
Expect.isFalse(it.contains(null), name);
Expect.isFalse(it.any((x) => true), name);
Expect.isTrue(it.every((x) => false), name);
Expect.throws(() => it.first, (e) => e is StateError, name);
Expect.throws(() => it.last, (e) => e is StateError, name);
Expect.throws(() => it.single, (e) => e is StateError, name);
Expect.throws(() => it.elementAt(0), (e) => e is RangeError, name);
Expect.throws(() => it.reduce((a, b) => a), (e) => e is StateError, name);
Expect.throws(
() => it.singleWhere((_) => true), (e) => e is StateError, name);
Expect.throwsStateError(() => it.first, name);
Expect.throwsStateError(() => it.last, name);
Expect.throwsStateError(() => it.single, name);
Expect.throwsRangeError(() => it.elementAt(0), name);
Expect.throwsStateError(() => it.reduce((a, b) => a), name);
Expect.throwsStateError(() => it.singleWhere((_) => true), name);
Expect.equals(42, it.fold(42, (a, b) => "not 42"), name);
Expect.equals(42, it.firstWhere((v) => true, orElse: () => 42), name);
Expect.equals(42, it.lastWhere((v) => true, orElse: () => 42), name);

View file

@ -14,9 +14,9 @@ main() {
Expect.equals(1, list1.first);
Expect.equals(4, list2.first);
Expect.throws(() => list3.first, (e) => e is StateError);
Expect.throwsStateError(() => list3.first);
Expect.isTrue(set1.contains(set1.first));
Expect.throws(() => set2.first, (e) => e is StateError);
Expect.throwsStateError(() => set2.first);
}

View file

@ -14,30 +14,30 @@ main() {
Expect.equals(2, list1.firstWhere((x) => x.isEven));
Expect.equals(1, list1.firstWhere((x) => x.isOdd));
Expect.throws(() => list1.firstWhere((x) => x > 3), (e) => e is StateError);
Expect.throwsStateError(() => list1.firstWhere((x) => x > 3));
Expect.equals(null, list1.firstWhere((x) => x > 3, orElse: () => null));
Expect.equals(499, list1.firstWhere((x) => x > 3, orElse: () => 499));
Expect.equals(4, list2.firstWhere((x) => x.isEven));
Expect.equals(5, list2.firstWhere((x) => x.isOdd));
Expect.throws(() => list2.firstWhere((x) => x == 0), (e) => e is StateError);
Expect.throwsStateError(() => list2.firstWhere((x) => x == 0));
Expect.equals(null, list2.firstWhere((x) => false, orElse: () => null));
Expect.equals(499, list2.firstWhere((x) => false, orElse: () => 499));
Expect.throws(() => list3.firstWhere((x) => x == 0), (e) => e is StateError);
Expect.throws(() => list3.firstWhere((x) => true), (e) => e is StateError);
Expect.throwsStateError(() => list3.firstWhere((x) => x == 0));
Expect.throwsStateError(() => list3.firstWhere((x) => true));
Expect.equals(null, list3.firstWhere((x) => true, orElse: () => null));
Expect.equals("str", list3.firstWhere((x) => false, orElse: () => "str"));
Expect.equals(12, set1.firstWhere((x) => x.isEven));
var odd = set1.firstWhere((x) => x.isOdd);
Expect.isTrue(odd == 11 || odd == 13);
Expect.throws(() => set1.firstWhere((x) => false), (e) => e is StateError);
Expect.throwsStateError(() => set1.firstWhere((x) => false));
Expect.equals(null, set1.firstWhere((x) => false, orElse: () => null));
Expect.equals(499, set1.firstWhere((x) => false, orElse: () => 499));
Expect.throws(() => set2.firstWhere((x) => false), (e) => e is StateError);
Expect.throws(() => set2.firstWhere((x) => true), (e) => e is StateError);
Expect.throwsStateError(() => set2.firstWhere((x) => false));
Expect.throwsStateError(() => set2.firstWhere((x) => true));
Expect.equals(null, set2.firstWhere((x) => true, orElse: () => null));
Expect.equals(499, set2.firstWhere((x) => false, orElse: () => 499));
}

View file

@ -14,9 +14,9 @@ main() {
Expect.equals(3, list1.last);
Expect.equals(5, list2.last);
Expect.throws(() => list3.last, (e) => e is StateError);
Expect.throwsStateError(() => list3.last);
Expect.isTrue(set1.contains(set1.last));
Expect.throws(() => set2.last, (e) => e is StateError);
Expect.throwsStateError(() => set2.last);
}

View file

@ -14,30 +14,30 @@ main() {
Expect.equals(2, list1.lastWhere((x) => x.isEven));
Expect.equals(3, list1.lastWhere((x) => x.isOdd));
Expect.throws(() => list1.lastWhere((x) => x > 3), (e) => e is StateError);
Expect.throwsStateError(() => list1.lastWhere((x) => x > 3));
Expect.equals(null, list1.lastWhere((x) => x > 3, orElse: () => null));
Expect.equals(499, list1.lastWhere((x) => x > 3, orElse: () => 499));
Expect.equals(6, list2.lastWhere((x) => x.isEven));
Expect.equals(5, list2.lastWhere((x) => x.isOdd));
Expect.throws(() => list2.lastWhere((x) => x == 0), (e) => e is StateError);
Expect.throwsStateError(() => list2.lastWhere((x) => x == 0));
Expect.equals(null, list2.lastWhere((x) => false, orElse: () => null));
Expect.equals(499, list2.lastWhere((x) => false, orElse: () => 499));
Expect.throws(() => list3.lastWhere((x) => x == 0), (e) => e is StateError);
Expect.throws(() => list3.lastWhere((x) => true), (e) => e is StateError);
Expect.throwsStateError(() => list3.lastWhere((x) => x == 0));
Expect.throwsStateError(() => list3.lastWhere((x) => true));
Expect.equals(null, list3.lastWhere((x) => true, orElse: () => null));
Expect.equals("str", list3.lastWhere((x) => false, orElse: () => "str"));
Expect.equals(12, set1.lastWhere((x) => x.isEven));
var odd = set1.lastWhere((x) => x.isOdd);
Expect.isTrue(odd == 11 || odd == 13);
Expect.throws(() => set1.lastWhere((x) => false), (e) => e is StateError);
Expect.throwsStateError(() => set1.lastWhere((x) => false));
Expect.equals(null, set1.lastWhere((x) => false, orElse: () => null));
Expect.equals(499, set1.lastWhere((x) => false, orElse: () => 499));
Expect.throws(() => set2.lastWhere((x) => false), (e) => e is StateError);
Expect.throws(() => set2.lastWhere((x) => true), (e) => e is StateError);
Expect.throwsStateError(() => set2.lastWhere((x) => false));
Expect.throwsStateError(() => set2.lastWhere((x) => true));
Expect.equals(null, set2.lastWhere((x) => true, orElse: () => null));
Expect.equals(499, set2.lastWhere((x) => false, orElse: () => 499));
}

View file

@ -110,9 +110,8 @@ main() {
"".runes,
new MyList([]),
]) {
Expect.throws(() {
iterable.reduce((x, y) => throw "Unreachable");
}, (e) => e is StateError);
Expect.throwsStateError(
() => iterable.reduce((x, y) => throw "Unreachable"));
}
// Singleton iterables not calling reduce function.

View file

@ -18,14 +18,14 @@ main() {
Set set3 = new Set();
Expect.equals(1, list1a.single);
Expect.throws(() => list1b.single, (e) => e is StateError);
Expect.throws(() => list1c.single, (e) => e is StateError);
Expect.throwsStateError(() => list1b.single);
Expect.throwsStateError(() => list1c.single);
Expect.equals(5, list2a.single);
Expect.throws(() => list2b.single, (e) => e is StateError);
Expect.throws(() => list2c.single, (e) => e is StateError);
Expect.throwsStateError(() => list2b.single);
Expect.throwsStateError(() => list2c.single);
Expect.equals(22, set1.single);
Expect.throws(() => set2.single, (e) => e is StateError);
Expect.throws(() => set3.single, (e) => e is StateError);
Expect.throwsStateError(() => set2.single);
Expect.throwsStateError(() => set3.single);
}

View file

@ -14,19 +14,17 @@ main() {
Expect.equals(2, list1.singleWhere((x) => x.isEven));
Expect.equals(3, list1.singleWhere((x) => x == 3));
Expect.throws(
() => list1.singleWhere((x) => x.isOdd), (e) => e is StateError);
Expect.throwsStateError(() => list1.singleWhere((x) => x.isOdd));
Expect.equals(6, list2.singleWhere((x) => x == 6));
Expect.equals(5, list2.singleWhere((x) => x.isOdd));
Expect.throws(
() => list2.singleWhere((x) => x.isEven), (e) => e is StateError);
Expect.throwsStateError(() => list2.singleWhere((x) => x.isEven));
Expect.throws(() => list3.singleWhere((x) => x == 0), (e) => e is StateError);
Expect.throwsStateError(() => list3.singleWhere((x) => x == 0));
Expect.equals(12, set1.singleWhere((x) => x.isEven));
Expect.equals(11, set1.singleWhere((x) => x == 11));
Expect.throws(() => set1.singleWhere((x) => x.isOdd));
Expect.throwsStateError(() => set1.singleWhere((x) => x.isOdd));
Expect.throws(() => set2.singleWhere((x) => true), (e) => e is StateError);
Expect.throwsStateError(() => set2.singleWhere((x) => true));
}

View file

@ -252,6 +252,6 @@ main() {
testSkipTake(collection, 15, 5);
testSkipTake(collection, 20, 0);
testSkipTake(collection, 20, 5);
Expect.throws(() => longList.skip(-1), (e) => e is RangeError);
Expect.throwsRangeError(() => longList.skip(-1));
}
}

View file

@ -214,14 +214,14 @@ main() {
Expect.isFalse(dynamicIt.moveNext());
Expect.isNull(dynamicIt.current);
Expect.throws(() => list1.skip(-1), (e) => e is RangeError);
Expect.throws(() => list2.skip(-1), (e) => e is RangeError);
Expect.throws(() => list3.skip(-1), (e) => e is RangeError);
Expect.throws(() => set1.skip(-1), (e) => e is RangeError);
Expect.throws(() => set2.skip(-1), (e) => e is RangeError);
Expect.throws(() => list1.map((x) => x).skip(-1), (e) => e is RangeError);
Expect.throws(() => list2.map((x) => x).skip(-1), (e) => e is RangeError);
Expect.throws(() => list3.map((x) => x).skip(-1), (e) => e is RangeError);
Expect.throws(() => set1.map((x) => x).skip(-1), (e) => e is RangeError);
Expect.throws(() => set2.map((x) => x).skip(-1), (e) => e is RangeError);
Expect.throwsRangeError(() => list1.skip(-1));
Expect.throwsRangeError(() => list2.skip(-1));
Expect.throwsRangeError(() => list3.skip(-1));
Expect.throwsRangeError(() => set1.skip(-1));
Expect.throwsRangeError(() => set2.skip(-1));
Expect.throwsRangeError(() => list1.map((x) => x).skip(-1));
Expect.throwsRangeError(() => list2.map((x) => x).skip(-1));
Expect.throwsRangeError(() => list3.map((x) => x).skip(-1));
Expect.throwsRangeError(() => set1.map((x) => x).skip(-1));
Expect.throwsRangeError(() => set2.map((x) => x).skip(-1));
}

View file

@ -47,10 +47,9 @@ void testConstAsMap(List list) {
testListMapCorrespondence(list, map);
Expect.throws(() => map[0] = 499, (e) => e is UnsupportedError);
Expect.throws(
() => map.putIfAbsent(0, () => 499), (e) => e is UnsupportedError);
Expect.throws(() => map.clear(), (e) => e is UnsupportedError);
Expect.throwsUnsupportedError(() => map[0] = 499);
Expect.throwsUnsupportedError(() => map.putIfAbsent(0, () => 499));
Expect.throwsUnsupportedError(() => map.clear());
}
void testFixedAsMap(List list) {

View file

@ -56,25 +56,17 @@ main() {
test(new MyList([1, 2, 3]), 3, 3);
test(new MyList([1, 2, 3]), 3, 3, 499);
expectRE(() => test([1, 2, 3], -1, 0));
expectRE(() => test([1, 2, 3], 2, 1));
expectRE(() => test([1, 2, 3], 0, -1));
expectRE(() => test([1, 2, 3], 1, 4));
expectRE(() => test(new MyList([1, 2, 3]), -1, 0));
expectRE(() => test(new MyList([1, 2, 3]), 2, 1));
expectRE(() => test(new MyList([1, 2, 3]), 0, -1));
expectRE(() => test(new MyList([1, 2, 3]), 1, 4));
expectUE(() => test(const [1, 2, 3], 2, 3));
expectUE(() => test(const [1, 2, 3], -1, 0));
expectUE(() => test(const [1, 2, 3], 2, 1));
expectUE(() => test(const [1, 2, 3], 0, -1));
expectUE(() => test(const [1, 2, 3], 1, 4));
}
void expectRE(void f()) {
Expect.throws(f, (e) => e is RangeError);
}
void expectUE(void f()) {
Expect.throws(f, (e) => e is UnsupportedError);
Expect.throwsRangeError(() => test([1, 2, 3], -1, 0));
Expect.throwsRangeError(() => test([1, 2, 3], 2, 1));
Expect.throwsRangeError(() => test([1, 2, 3], 0, -1));
Expect.throwsRangeError(() => test([1, 2, 3], 1, 4));
Expect.throwsRangeError(() => test(new MyList([1, 2, 3]), -1, 0));
Expect.throwsRangeError(() => test(new MyList([1, 2, 3]), 2, 1));
Expect.throwsRangeError(() => test(new MyList([1, 2, 3]), 0, -1));
Expect.throwsRangeError(() => test(new MyList([1, 2, 3]), 1, 4));
Expect.throwsUnsupportedError(() => test(const [1, 2, 3], 2, 3));
Expect.throwsUnsupportedError(() => test(const [1, 2, 3], -1, 0));
Expect.throwsUnsupportedError(() => test(const [1, 2, 3], 2, 1));
Expect.throwsUnsupportedError(() => test(const [1, 2, 3], 0, -1));
Expect.throwsUnsupportedError(() => test(const [1, 2, 3], 1, 4));
}

View file

@ -6,7 +6,7 @@ import "package:expect/expect.dart";
void test(List list) {
if (list.isEmpty) {
Expect.throws(() => list.first, (e) => e is StateError);
Expect.throwsStateError(() => list.first);
} else {
Expect.equals(list[0], list.first);
}

View file

@ -9,21 +9,21 @@ main() {
a = new List(42);
Expect.equals(42, a.length);
Expect.throws(() => a.add(499), (e) => e is UnsupportedError);
Expect.throwsUnsupportedError(() => a.add(499));
Expect.equals(42, a.length);
for (int i = 0; i < 42; i++) {
Expect.equals(null, a[i]);
}
Expect.throws(() => a.clear(), (e) => e is UnsupportedError);
Expect.throwsUnsupportedError(() => a.clear());
Expect.equals(42, a.length);
a = new List.filled(42, -2);
Expect.equals(42, a.length);
Expect.throws(() => a.add(499), (e) => e is UnsupportedError);
Expect.throwsUnsupportedError(() => a.add(499));
Expect.equals(42, a.length);
for (int i = 0; i < 42; i++) {
Expect.equals(-2, a[i]);
}
Expect.throws(() => a.clear(), (e) => e is UnsupportedError);
Expect.throwsUnsupportedError(() => a.clear());
Expect.equals(42, a.length);
}

View file

@ -5,21 +5,12 @@
import "package:expect/expect.dart";
testGetRange(list, start, end, bool isModifiable) {
expectRE(() {
list.getRange(-1, 0);
});
expectRE(() {
list.getRange(0, -1);
});
expectRE(() {
list.getRange(1, 0);
});
expectRE(() {
list.getRange(0, list.length + 1);
});
expectRE(() {
list.getRange(list.length + 1, list.length + 1);
});
Expect.throwsRangeError(() => list.getRange(-1, 0));
Expect.throwsRangeError(() => list.getRange(0, -1));
Expect.throwsRangeError(() => list.getRange(1, 0));
Expect.throwsRangeError(() => list.getRange(0, list.length + 1));
Expect.throwsRangeError(
() => list.getRange(list.length + 1, list.length + 1));
Iterable iterable = list.getRange(start, end);
Expect.isFalse(iterable is List);
if (start == end) {
@ -60,9 +51,9 @@ main() {
testGetRange("abcd".codeUnits, 0, 0, false);
testGetRange("abcd".codeUnits, 1, 3, false);
expectRE(() => [1].getRange(-1, 1));
expectRE(() => [3].getRange(0, -1));
expectRE(() => [4].getRange(1, 0));
Expect.throwsRangeError(() => [1].getRange(-1, 1));
Expect.throwsRangeError(() => [3].getRange(0, -1));
Expect.throwsRangeError(() => [4].getRange(1, 0));
var list = [1, 2, 3, 4];
var iterable = list.getRange(1, 3);
@ -76,7 +67,3 @@ main() {
Expect.equals(499, iterable.last);
Expect.equals(2, iterable.length);
}
void expectRE(void f()) {
Expect.throws(f, (e) => e is RangeError);
}

View file

@ -12,7 +12,7 @@ main() {
Expect.equals(499, a[0]);
a.clear();
Expect.equals(0, a.length);
Expect.throws(() => a[0], (e) => e is RangeError);
Expect.throwsRangeError(() => a[0]);
a = new List(42).toList();
Expect.equals(42, a.length);
@ -22,7 +22,7 @@ main() {
Expect.equals(null, a[23]);
a.clear();
Expect.equals(0, a.length);
Expect.throws(() => a[0], (e) => e is RangeError);
Expect.throwsRangeError(() => a[0]);
a = new List<int>(42).toList();
Expect.equals(42, a.length);
@ -34,5 +34,5 @@ main() {
}
a.clear();
Expect.equals(0, a.length);
Expect.throws(() => a[0], (e) => e is RangeError);
Expect.throwsRangeError(() => a[0]);
}

View file

@ -75,16 +75,10 @@ main() {
test(new MyList([1, 2, 3]), 2, [4].map((x) => x));
test(new MyList([1, 2, 3]), 3, [].map((x) => x));
expectRE(() => test([1, 2, 3], -1, [4, 5]));
expectUE(() => test([1, 2, 3].toList(growable: false), -1, [4, 5]));
expectRE(() => test(new MyList([1, 2, 3]), -1, [4, 5]));
expectUE(() => test([1, 2, 3].toList(growable: false), 0, [4, 5]));
}
void expectRE(void f()) {
Expect.throws(f, (e) => e is RangeError);
}
void expectUE(void f()) {
Expect.throws(f, (e) => e is UnsupportedError);
Expect.throwsRangeError(() => test([1, 2, 3], -1, [4, 5]));
Expect.throwsUnsupportedError(
() => test([1, 2, 3].toList(growable: false), -1, [4, 5]));
Expect.throwsRangeError(() => test(new MyList([1, 2, 3]), -1, [4, 5]));
Expect.throwsUnsupportedError(
() => test([1, 2, 3].toList(growable: false), 0, [4, 5]));
}

View file

@ -22,25 +22,12 @@ class MyList extends ListBase {
// l1 must be a modifiable list with 5 elements from 0 to 4.
void testModifiableList(l1) {
bool checkedMode = false;
assert(checkedMode = true);
// Index must be integer and in range.
Expect.throws(() {
l1.insert(-1, 5);
}, (e) => e is RangeError, "negative");
Expect.throws(() {
l1.insert(6, 5);
}, (e) => e is RangeError, "too large");
Expect.throws(() {
l1.insert(null, 5);
});
Expect.throws(() {
l1.insert("1", 5);
});
Expect.throws(() {
l1.insert(1.5, 5);
});
Expect.throwsRangeError(() => l1.insert(-1, 5), "negative");
Expect.throwsRangeError(() => l1.insert(6, 5), "too large");
Expect.throws(() => l1.insert(null, 5));
Expect.throws(() => l1.insert("1", 5));
Expect.throws(() => l1.insert(1.5, 5));
l1.insert(5, 5);
Expect.equals(6, l1.length);
@ -61,15 +48,11 @@ void main() {
// Fixed size list.
var l2 = new List(5);
for (var i = 0; i < 5; i++) l2[i] = i;
Expect.throws(() {
l2.insert(2, 5);
}, (e) => e is UnsupportedError, "fixed-length");
Expect.throwsUnsupportedError(() => l2.insert(2, 5), "fixed-length");
// Unmodifiable list.
var l3 = const [0, 1, 2, 3, 4];
Expect.throws(() {
l3.insert(2, 5);
}, (e) => e is UnsupportedError, "unmodifiable");
Expect.throwsUnsupportedError(() => l3.insert(2, 5), "unmodifiable");
// Empty list is not special.
var l4 = [];

View file

@ -6,7 +6,7 @@ import "package:expect/expect.dart";
void test(List list) {
if (list.isEmpty) {
Expect.throws(() => list.last, (e) => e is StateError);
Expect.throwsStateError(() => list.last);
} else {
Expect.equals(list[list.length - 1], list.last);
}

View file

@ -8,18 +8,14 @@ main() {
var list = [];
list.removeRange(0, 0);
Expect.equals(0, list.length);
expectIOORE(() {
list.removeRange(0, 1);
});
Expect.throwsRangeError(() => list.removeRange(0, 1));
list.add(1);
list.removeRange(0, 0);
Expect.equals(1, list.length);
Expect.equals(1, list[0]);
expectIOORE(() {
list.removeRange(0, 2);
});
Expect.throwsRangeError(() => list.removeRange(0, 2));
Expect.equals(1, list.length);
Expect.equals(1, list[0]);
@ -36,9 +32,7 @@ main() {
Expect.listEquals([3, 4], list);
list.addAll([5, 6]);
expectIOORE(() {
list.removeRange(4, 5);
});
Expect.throwsRangeError(() => list.removeRange(4, 5));
Expect.listEquals([3, 4, 5, 6], list);
list.removeRange(1, 3);
@ -47,34 +41,19 @@ main() {
testNegativeIndices();
}
void expectIOORE(void f()) {
Expect.throws(f, (e) => e is RangeError);
}
void testNegativeIndices() {
var list = [1, 2];
expectIOORE(() {
list.removeRange(-1, 1);
});
Expect.throwsRangeError(() => list.removeRange(-1, 1));
Expect.listEquals([1, 2], list);
// A negative length throws an ArgumentError.
expectIOORE(() {
list.removeRange(0, -1);
});
Expect.throwsRangeError(() => list.removeRange(0, -1));
Expect.listEquals([1, 2], list);
expectIOORE(() {
list.removeRange(-1, -1);
});
Expect.throwsRangeError(() => list.removeRange(-1, -1));
Expect.listEquals([1, 2], list);
expectIOORE(() {
list.removeRange(-1, 0);
});
Expect.throwsRangeError(() => list.removeRange(-1, 0));
expectIOORE(() {
list.removeRange(4, 4);
});
Expect.throwsRangeError(() => list.removeRange(4, 4));
Expect.listEquals([1, 2], list);
}

View file

@ -23,15 +23,9 @@ class MyList extends ListBase {
// l1 must be a modifiable list with 5 elements from 0 to 4.
void testModifiableList(l1) {
// Index must be integer and in range.
Expect.throws(() {
l1.removeAt(-1);
}, (e) => e is RangeError, "negative");
Expect.throws(() {
l1.removeAt(5);
}, (e) => e is RangeError, "too large");
Expect.throws(() {
l1.removeAt(null);
}, (e) => e is ArgumentError, "too large");
Expect.throwsRangeError(() => l1.removeAt(-1), "negative");
Expect.throwsRangeError(() => l1.removeAt(5), "too large");
Expect.throwsArgumentError(() => l1.removeAt(null), "too large");
Expect.equals(2, l1.removeAt(2), "l1-remove2");
Expect.equals(1, l1[1], "l1-1[1]");
@ -55,19 +49,13 @@ void main() {
// Fixed size list.
var l2 = new List(5);
for (var i = 0; i < 5; i++) l2[i] = i;
Expect.throws(() {
l2.removeAt(2);
}, (e) => e is UnsupportedError, "fixed-length");
Expect.throwsUnsupportedError(() => l2.removeAt(2), "fixed-length");
// Unmodifiable list.
var l3 = const [0, 1, 2, 3, 4];
Expect.throws(() {
l3.removeAt(2);
}, (e) => e is UnsupportedError, "unmodifiable");
Expect.throwsUnsupportedError(() => l3.removeAt(2), "unmodifiable");
// Empty list is not special.
var l4 = [];
Expect.throws(() {
l4.removeAt(0);
}, (e) => e is RangeError, "empty");
Expect.throwsRangeError(() => l4.removeAt(0), "empty");
}

View file

@ -94,30 +94,27 @@ main() {
test(new MyList([1, 2, 3]), 0, 3, new Iterable.generate(2, (x) => x + 4));
test(new MyList([1, 2, 3]), 2, 3, new Iterable.generate(2, (x) => x + 4));
expectRE(() => test([1, 2, 3], -1, 0, []));
expectRE(() => test([1, 2, 3], 2, 1, []));
expectRE(() => test([1, 2, 3], 0, -1, []));
expectRE(() => test([1, 2, 3], 1, 4, []));
expectRE(() => test(new MyList([1, 2, 3]), -1, 0, []));
expectRE(() => test(new MyList([1, 2, 3]), 2, 1, []));
expectRE(() => test(new MyList([1, 2, 3]), 0, -1, []));
expectRE(() => test(new MyList([1, 2, 3]), 1, 4, []));
expectUE(() => test([1, 2, 3].toList(growable: false), 2, 3, []));
expectUE(() => test([1, 2, 3].toList(growable: false), -1, 0, []));
expectUE(() => test([1, 2, 3].toList(growable: false), 2, 1, []));
expectUE(() => test([1, 2, 3].toList(growable: false), 0, -1, []));
expectUE(() => test([1, 2, 3].toList(growable: false), 1, 4, []));
expectUE(() => test(const [1, 2, 3], 2, 3, []));
expectUE(() => test(const [1, 2, 3], -1, 0, []));
expectUE(() => test(const [1, 2, 3], 2, 1, []));
expectUE(() => test(const [1, 2, 3], 0, -1, []));
expectUE(() => test(const [1, 2, 3], 1, 4, []));
}
void expectRE(void f()) {
Expect.throws(f, (e) => e is RangeError);
}
void expectUE(void f()) {
Expect.throws(f, (e) => e is UnsupportedError);
Expect.throwsRangeError(() => test([1, 2, 3], -1, 0, []));
Expect.throwsRangeError(() => test([1, 2, 3], 2, 1, []));
Expect.throwsRangeError(() => test([1, 2, 3], 0, -1, []));
Expect.throwsRangeError(() => test([1, 2, 3], 1, 4, []));
Expect.throwsRangeError(() => test(new MyList([1, 2, 3]), -1, 0, []));
Expect.throwsRangeError(() => test(new MyList([1, 2, 3]), 2, 1, []));
Expect.throwsRangeError(() => test(new MyList([1, 2, 3]), 0, -1, []));
Expect.throwsRangeError(() => test(new MyList([1, 2, 3]), 1, 4, []));
Expect.throwsUnsupportedError(
() => test([1, 2, 3].toList(growable: false), 2, 3, []));
Expect.throwsUnsupportedError(
() => test([1, 2, 3].toList(growable: false), -1, 0, []));
Expect.throwsUnsupportedError(
() => test([1, 2, 3].toList(growable: false), 2, 1, []));
Expect.throwsUnsupportedError(
() => test([1, 2, 3].toList(growable: false), 0, -1, []));
Expect.throwsUnsupportedError(
() => test([1, 2, 3].toList(growable: false), 1, 4, []));
Expect.throwsUnsupportedError(() => test(const [1, 2, 3], 2, 3, []));
Expect.throwsUnsupportedError(() => test(const [1, 2, 3], -1, 0, []));
Expect.throwsUnsupportedError(() => test(const [1, 2, 3], 2, 1, []));
Expect.throwsUnsupportedError(() => test(const [1, 2, 3], 0, -1, []));
Expect.throwsUnsupportedError(() => test(const [1, 2, 3], 1, 4, []));
}

View file

@ -83,21 +83,15 @@ main() {
test(new MyList([1, 2, 3]), 2, [4].map((x) => x));
test(new MyList([1, 2, 3]), 3, [].map((x) => x));
expectRE(() => test([1, 2, 3], -1, [4, 5]));
expectRE(() => test([1, 2, 3].toList(growable: false), -1, [4, 5]));
expectRE(() => test([1, 2, 3], 1, [4, 5, 6]));
expectRE(() => test([1, 2, 3].toList(growable: false), 1, [4, 5, 6]));
expectRE(() => test(new MyList([1, 2, 3]), -1, [4, 5]));
expectRE(() => test(new MyList([1, 2, 3]), 1, [4, 5, 6]));
expectUE(() => test(const [1, 2, 3], 0, [4, 5]));
expectUE(() => test(const [1, 2, 3], -1, [4, 5]));
expectUE(() => test(const [1, 2, 3], 1, [4, 5, 6]));
}
void expectRE(void f()) {
Expect.throws(f, (e) => e is RangeError);
}
void expectUE(void f()) {
Expect.throws(f, (e) => e is UnsupportedError);
Expect.throwsRangeError(() => test([1, 2, 3], -1, [4, 5]));
Expect.throwsRangeError(
() => test([1, 2, 3].toList(growable: false), -1, [4, 5]));
Expect.throwsRangeError(() => test([1, 2, 3], 1, [4, 5, 6]));
Expect.throwsRangeError(
() => test([1, 2, 3].toList(growable: false), 1, [4, 5, 6]));
Expect.throwsRangeError(() => test(new MyList([1, 2, 3]), -1, [4, 5]));
Expect.throwsRangeError(() => test(new MyList([1, 2, 3]), 1, [4, 5, 6]));
Expect.throwsUnsupportedError(() => test(const [1, 2, 3], 0, [4, 5]));
Expect.throwsUnsupportedError(() => test(const [1, 2, 3], -1, [4, 5]));
Expect.throwsUnsupportedError(() => test(const [1, 2, 3], 1, [4, 5, 6]));
}

View file

@ -11,15 +11,9 @@ main() {
list.setRange(0, 0, const [], 1);
list.setRange(0, 0, [], 1);
Expect.equals(0, list.length);
expectIOORE(() {
list.setRange(0, 1, []);
});
expectIOORE(() {
list.setRange(0, 1, [], 1);
});
expectIOORE(() {
list.setRange(0, 1, [1], 0);
});
Expect.throwsRangeError(() => list.setRange(0, 1, []));
Expect.throwsRangeError(() => list.setRange(0, 1, [], 1));
Expect.throwsRangeError(() => list.setRange(0, 1, [1], 0));
list.add(1);
list.setRange(0, 0, [], 0);
@ -29,15 +23,11 @@ main() {
Expect.equals(1, list.length);
Expect.equals(1, list[0]);
expectIOORE(() {
list.setRange(0, 2, [1, 2]);
});
Expect.throwsRangeError(() => list.setRange(0, 2, [1, 2]));
Expect.equals(1, list.length);
Expect.equals(1, list[0]);
expectSE(() {
list.setRange(0, 1, [1, 2], 2);
});
Expect.throwsStateError(() => list.setRange(0, 1, [1, 2], 2));
Expect.equals(1, list.length);
Expect.equals(1, list[0]);
@ -57,9 +47,7 @@ main() {
list.setRange(2, 4, [5, 6, 7, 8]);
Expect.listEquals([1, 2, 5, 6], list);
expectIOORE(() {
list.setRange(4, 5, [5, 6, 7, 8]);
});
Expect.throwsRangeError(() => list.setRange(4, 5, [5, 6, 7, 8]));
Expect.listEquals([1, 2, 5, 6], list);
list.setRange(1, 3, [9, 10, 11, 12]);
@ -70,40 +58,17 @@ main() {
testNonExtendableList();
}
void expectIOORE(void f()) {
Expect.throws(f, (e) => e is RangeError);
}
void expectSE(void f()) {
Expect.throws(f, (e) => e is StateError);
}
void expectAE(void f()) {
Expect.throws(f, (e) => e is ArgumentError);
}
void testNegativeIndices() {
var list = [1, 2];
expectIOORE(() {
list.setRange(-1, 1, [1]);
});
expectAE(() {
list.setRange(0, 1, [1], -1);
});
Expect.throwsRangeError(() => list.setRange(-1, 1, [1]));
Expect.throwsArgumentError(() => list.setRange(0, 1, [1], -1));
// A negative length throws an ArgumentError.
expectIOORE(() {
list.setRange(2, 1, [1]);
});
Expect.throwsRangeError(() => list.setRange(2, 1, [1]));
expectAE(() {
list.setRange(-1, -2, [1], -1);
});
Expect.throwsArgumentError(() => list.setRange(-1, -2, [1], -1));
Expect.listEquals([1, 2], list);
expectIOORE(() {
list.setRange(-1, -1, [1]);
});
Expect.throwsRangeError(() => list.setRange(-1, -1, [1]));
Expect.listEquals([1, 2], list);
// The skipCount is only used if the length is not 0.

View file

@ -26,32 +26,28 @@ main() {
Expect.listEquals([2, 3], [1, 2, 3, 4].sublist(1, 3));
Expect.listEquals([2, 3], const [1, 2, 3, 4].sublist(1, 3));
expectAE(() => [].sublist(-1, null));
expectAE(() => const [].sublist(-1, null));
expectAE(() => [].sublist(-1, 0));
expectAE(() => const [].sublist(-1, 0));
expectAE(() => [].sublist(-1, -1));
expectAE(() => const [].sublist(-1, -1));
expectAE(() => [].sublist(-1, 1));
expectAE(() => const [].sublist(-1, 1));
expectAE(() => [].sublist(0, -1));
expectAE(() => const [].sublist(0, -1));
expectAE(() => [].sublist(0, 1));
expectAE(() => const [].sublist(0, 1));
expectAE(() => [].sublist(1, null));
expectAE(() => const [].sublist(1, null));
expectAE(() => [].sublist(1, 0));
expectAE(() => const [].sublist(1, 0));
expectAE(() => [].sublist(1, -1));
expectAE(() => const [].sublist(1, -1));
expectAE(() => [].sublist(1, 1));
expectAE(() => const [].sublist(1, 1));
Expect.throwsArgumentError(() => [].sublist(-1, null));
Expect.throwsArgumentError(() => const [].sublist(-1, null));
Expect.throwsArgumentError(() => [].sublist(-1, 0));
Expect.throwsArgumentError(() => const [].sublist(-1, 0));
Expect.throwsArgumentError(() => [].sublist(-1, -1));
Expect.throwsArgumentError(() => const [].sublist(-1, -1));
Expect.throwsArgumentError(() => [].sublist(-1, 1));
Expect.throwsArgumentError(() => const [].sublist(-1, 1));
Expect.throwsArgumentError(() => [].sublist(0, -1));
Expect.throwsArgumentError(() => const [].sublist(0, -1));
Expect.throwsArgumentError(() => [].sublist(0, 1));
Expect.throwsArgumentError(() => const [].sublist(0, 1));
Expect.throwsArgumentError(() => [].sublist(1, null));
Expect.throwsArgumentError(() => const [].sublist(1, null));
Expect.throwsArgumentError(() => [].sublist(1, 0));
Expect.throwsArgumentError(() => const [].sublist(1, 0));
Expect.throwsArgumentError(() => [].sublist(1, -1));
Expect.throwsArgumentError(() => const [].sublist(1, -1));
Expect.throwsArgumentError(() => [].sublist(1, 1));
Expect.throwsArgumentError(() => const [].sublist(1, 1));
expectAE(() => [1].sublist(0, 2));
expectAE(() => [1].sublist(1, 2));
expectAE(() => [1].sublist(1, 0));
}
void expectAE(void f()) {
Expect.throws(f, (e) => e is ArgumentError);
Expect.throwsArgumentError(() => [1].sublist(0, 2));
Expect.throwsArgumentError(() => [1].sublist(1, 2));
Expect.throwsArgumentError(() => [1].sublist(1, 0));
}

View file

@ -278,44 +278,40 @@ void testUntypedListTests(List list) {
void testLengthInvariantOperations(List<int> list) {
testTypedLengthInvariantOperations(list);
Expect.throws(() {
testUntypedListTests(list);
}, (e) => e is TypeError, 'List<int> cannot store non-ints');
Expect.throwsTypeError(() => testUntypedListTests(list),
'List<int> cannot store non-ints');
// Argument errors on bad indices. List is still [0, 1, 2, 3].
testArgumentError(action()) {
Expect.throws(action, (e) => e is ArgumentError);
}
// Direct indices (0 <= index < length).
testArgumentError(() => list[-1]);
testArgumentError(() => list[4]);
testArgumentError(() => list[-1] = 99);
testArgumentError(() => list[4] = 99);
testArgumentError(() => list.elementAt(-1));
testArgumentError(() => list.elementAt(4));
Expect.throwsArgumentError(() => list[-1]);
Expect.throwsArgumentError(() => list[4]);
Expect.throwsArgumentError(() => list[-1] = 99);
Expect.throwsArgumentError(() => list[4] = 99);
Expect.throwsArgumentError(() => list.elementAt(-1));
Expect.throwsArgumentError(() => list.elementAt(4));
// Ranges (0 <= start <= end <= length).
testArgumentError(() => list.sublist(-1, 2));
testArgumentError(() => list.sublist(-1, 5));
testArgumentError(() => list.sublist(2, 5));
testArgumentError(() => list.sublist(4, 2));
testArgumentError(() => list.getRange(-1, 2));
testArgumentError(() => list.getRange(-1, 5));
testArgumentError(() => list.getRange(2, 5));
testArgumentError(() => list.getRange(4, 2));
testArgumentError(() => list.setRange(-1, 2, [1, 2, 3]));
testArgumentError(() => list.setRange(-1, 5, [1, 2, 3, 4, 5, 6]));
testArgumentError(() => list.setRange(2, 5, [1, 2, 3]));
testArgumentError(() => list.setRange(4, 2, [1, 2]));
Expect.throwsArgumentError(() => list.sublist(-1, 2));
Expect.throwsArgumentError(() => list.sublist(-1, 5));
Expect.throwsArgumentError(() => list.sublist(2, 5));
Expect.throwsArgumentError(() => list.sublist(4, 2));
Expect.throwsArgumentError(() => list.getRange(-1, 2));
Expect.throwsArgumentError(() => list.getRange(-1, 5));
Expect.throwsArgumentError(() => list.getRange(2, 5));
Expect.throwsArgumentError(() => list.getRange(4, 2));
Expect.throwsArgumentError(() => list.setRange(-1, 2, [1, 2, 3]));
Expect.throwsArgumentError(() => list.setRange(-1, 5, [1, 2, 3, 4, 5, 6]));
Expect.throwsArgumentError(() => list.setRange(2, 5, [1, 2, 3]));
Expect.throwsArgumentError(() => list.setRange(4, 2, [1, 2]));
// for setAll, end is implicitly start + values.length.
testArgumentError(() => list.setAll(-1, []));
testArgumentError(() => list.setAll(5, []));
testArgumentError(() => list.setAll(2, [1, 2, 3]));
testArgumentError(() => list.fillRange(-1, 2));
testArgumentError(() => list.fillRange(-1, 5));
testArgumentError(() => list.fillRange(2, 5));
testArgumentError(() => list.fillRange(4, 2));
Expect.throwsArgumentError(() => list.setAll(-1, []));
Expect.throwsArgumentError(() => list.setAll(5, []));
Expect.throwsArgumentError(() => list.setAll(2, [1, 2, 3]));
Expect.throwsArgumentError(() => list.fillRange(-1, 2));
Expect.throwsArgumentError(() => list.fillRange(-1, 5));
Expect.throwsArgumentError(() => list.fillRange(2, 5));
Expect.throwsArgumentError(() => list.fillRange(4, 2));
}
void testTypedList(List<int> list) {
@ -330,20 +326,17 @@ void testFixedLengthList(List<T> Function<T>() createList) {
}
void testCannotChangeLength(List<int> list) {
isUnsupported(action()) {
Expect.throws(action, (e) => e is UnsupportedError);
}
list.setAll(0, [0, 1, 2, 3]);
isUnsupported(() => list.add(0));
isUnsupported(() => list.addAll([0]));
isUnsupported(() => list.removeLast());
isUnsupported(() => list.insert(0, 1));
isUnsupported(() => list.insertAll(0, [1]));
isUnsupported(() => list.clear());
isUnsupported(() => list.remove(1));
isUnsupported(() => list.removeAt(1));
isUnsupported(() => list.removeRange(0, 1));
isUnsupported(() => list.replaceRange(0, 1, []));
Expect.throwsUnsupportedError(() => list.add(0));
Expect.throwsUnsupportedError(() => list.addAll([0]));
Expect.throwsUnsupportedError(() => list.removeLast());
Expect.throwsUnsupportedError(() => list.insert(0, 1));
Expect.throwsUnsupportedError(() => list.insertAll(0, [1]));
Expect.throwsUnsupportedError(() => list.clear());
Expect.throwsUnsupportedError(() => list.remove(1));
Expect.throwsUnsupportedError(() => list.removeAt(1));
Expect.throwsUnsupportedError(() => list.removeRange(0, 1));
Expect.throwsUnsupportedError(() => list.replaceRange(0, 1, []));
}
void testTypedGrowableList(List<int> list) {
@ -518,29 +511,26 @@ void testGrowableListOperations(List<int> list) {
// on growable lists.
list.length = 4;
list.setAll(0, [0, 1, 2, 3]);
testArgumentError(action()) {
Expect.throws(action, (e) => e is ArgumentError);
}
// Direct indices (0 <= index < length).
testArgumentError(() => list.removeAt(-1));
testArgumentError(() => list.removeAt(4));
Expect.throwsArgumentError(() => list.removeAt(-1));
Expect.throwsArgumentError(() => list.removeAt(4));
// Direct indices including end (0 <= index <= length).
testArgumentError(() => list.insert(-1, 0));
testArgumentError(() => list.insert(5, 0));
testArgumentError(() => list.insertAll(-1, [0]));
testArgumentError(() => list.insertAll(5, [0]));
testArgumentError(() => list.insertAll(-1, [0]));
testArgumentError(() => list.insertAll(5, [0]));
Expect.throwsArgumentError(() => list.insert(-1, 0));
Expect.throwsArgumentError(() => list.insert(5, 0));
Expect.throwsArgumentError(() => list.insertAll(-1, [0]));
Expect.throwsArgumentError(() => list.insertAll(5, [0]));
Expect.throwsArgumentError(() => list.insertAll(-1, [0]));
Expect.throwsArgumentError(() => list.insertAll(5, [0]));
// Ranges (0 <= start <= end <= length).
testArgumentError(() => list.removeRange(-1, 2));
testArgumentError(() => list.removeRange(2, 5));
testArgumentError(() => list.removeRange(-1, 5));
testArgumentError(() => list.removeRange(4, 2));
testArgumentError(() => list.replaceRange(-1, 2, [9]));
testArgumentError(() => list.replaceRange(2, 5, [9]));
testArgumentError(() => list.replaceRange(-1, 5, [9]));
testArgumentError(() => list.replaceRange(4, 2, [9]));
Expect.throwsArgumentError(() => list.removeRange(-1, 2));
Expect.throwsArgumentError(() => list.removeRange(2, 5));
Expect.throwsArgumentError(() => list.removeRange(-1, 5));
Expect.throwsArgumentError(() => list.removeRange(4, 2));
Expect.throwsArgumentError(() => list.replaceRange(-1, 2, [9]));
Expect.throwsArgumentError(() => list.replaceRange(2, 5, [9]));
Expect.throwsArgumentError(() => list.replaceRange(-1, 5, [9]));
Expect.throwsArgumentError(() => list.replaceRange(4, 2, [9]));
}
class Yes {
@ -578,25 +568,15 @@ class MyFixedList<E> extends ListBase<E> {
void testListConstructor() {
// Is fixed-length.
Expect.throws(() {
new List(0).add(4);
});
Expect.throws(() { new List(-2); }); // Not negative. //# 01: ok
Expect.throws(() => new List(0).add(4));
Expect.throws(() => new List(-2)); // Not negative. //# 01: ok
// Not null.
Expect.throws(() {
new List(null);
});
Expect.throws(() => new List(null));
Expect.listEquals([4], new List()..add(4));
// Is fixed-length.
Expect.throws(() {
new List.filled(0, 42).add(4);
});
Expect.throws(() => new List.filled(0, 42).add(4));
// Not negative.
Expect.throws(() {
new List.filled(-2, 42);
});
Expect.throws(() => new List.filled(-2, 42));
// Not null.
Expect.throws(() {
new List.filled(null, 42);
});
Expect.throws(() => new List.filled(null, 42));
}

View file

@ -15,7 +15,7 @@ testIntClamp() {
Expect.equals(0, 1.clamp(0, 0));
Expect.equals(0, (-1).clamp(0, 0));
Expect.equals(0, 0.clamp(0, 0));
Expect.throws(() => 0.clamp(0, -1), (e) => e is ArgumentError);
Expect.throwsArgumentError(() => 0.clamp(0, -1));
}
testDoubleClamp() {
@ -28,7 +28,7 @@ testDoubleClamp() {
Expect.equals(0.0, 1.0.clamp(0.0, 0.0));
Expect.equals(0.0, (-1.0).clamp(0.0, 0.0));
Expect.equals(0.0, 0.0.clamp(0.0, 0.0));
Expect.throws(() => 0.0.clamp(0.0, -1.0), (e) => e is ArgumentError);
Expect.throwsArgumentError(() => 0.0.clamp(0.0, -1.0));
}
testDoubleClampInt() {
@ -48,7 +48,7 @@ testDoubleClampInt() {
Expect.isTrue((-1.0).clamp(0, 0) is int);
Expect.equals(0.0, 0.0.clamp(0, 0));
Expect.isTrue(0.0.clamp(0, 0) is double);
Expect.throws(() => 0.0.clamp(0, -1), (e) => e is ArgumentError);
Expect.throwsArgumentError(() => 0.0.clamp(0, -1));
}
testDoubleClampExtremes() {
@ -56,8 +56,7 @@ testDoubleClampExtremes() {
Expect.equals(2.0, 2.0.clamp(-double.INFINITY, double.NAN));
Expect.equals(double.INFINITY, 2.0.clamp(double.INFINITY, double.NAN));
Expect.isTrue(2.0.clamp(double.NAN, double.NAN).isNaN);
Expect.throws(
() => 0.0.clamp(double.NAN, double.INFINITY), (e) => e is ArgumentError);
Expect.throwsArgumentError(() => 0.0.clamp(double.NAN, double.INFINITY));
}
main() {

View file

@ -13,5 +13,5 @@ main() {
Queue queue2 = new Queue();
Expect.equals(11, queue1.first);
Expect.throws(() => queue2.first, (e) => e is StateError);
Expect.throwsStateError(() => queue2.first);
}

View file

@ -13,5 +13,5 @@ main() {
Queue queue2 = new Queue();
Expect.equals(13, queue1.last);
Expect.throws(() => queue2.last, (e) => e is StateError);
Expect.throwsStateError(() => queue2.last);
}

View file

@ -15,6 +15,6 @@ main() {
Queue queue3 = new Queue();
Expect.equals(42, queue1.single);
Expect.throws(() => queue2.single, (e) => e is StateError);
Expect.throws(() => queue3.single, (e) => e is StateError);
Expect.throwsStateError(() => queue2.single);
Expect.throwsStateError(() => queue3.single);
}

View file

@ -6,44 +6,9 @@
import "package:expect/expect.dart";
main() {
try {
RegExp ex = new RegExp(null);
Expect.fail("Expected: ArgumentError got: no exception");
} catch (ex) {
if (!(ex is ArgumentError)) {
Expect.fail("Expected: ArgumentError got: ${ex}");
}
}
try {
new RegExp(r"^\w+$").hasMatch(null);
Expect.fail("Expected: ArgumentError got: no exception");
} catch (ex) {
if (!(ex is ArgumentError)) {
Expect.fail("Expected: ArgumentError got: ${ex}");
}
}
try {
new RegExp(r"^\w+$").firstMatch(null);
Expect.fail("Expected: ArgumentError got: no exception");
} catch (ex) {
if (!(ex is ArgumentError)) {
Expect.fail("Expected: ArgumentError got: ${ex}");
}
}
try {
new RegExp(r"^\w+$").allMatches(null);
Expect.fail("Expected: ArgumentError got: no exception");
} catch (ex) {
if (!(ex is ArgumentError)) {
Expect.fail("Expected: ArgumentError got: ${ex}");
}
}
try {
new RegExp(r"^\w+$").stringMatch(null);
Expect.fail("Expected: ArgumentError got: no exception");
} catch (ex) {
if (!(ex is ArgumentError)) {
Expect.fail("Expected: ArgumentError got: ${ex}");
}
}
Expect.throwsArgumentError(() => new RegExp(null));
Expect.throwsArgumentError(() => new RegExp(r"^\w+$").hasMatch(null));
Expect.throwsArgumentError(() => new RegExp(r"^\w+$").firstMatch(null));
Expect.throwsArgumentError(() => new RegExp(r"^\w+$").allMatches(null));
Expect.throwsArgumentError(() => new RegExp(r"^\w+$").stringMatch(null));
}

View file

@ -29,10 +29,10 @@ main() {
units.map((x) => x.toRadixString(16)).toList());
if (s == "") {
Expect.throws(() => units.first, (e) => e is StateError);
Expect.throws(() => units.last, (e) => e is StateError);
Expect.throws(() => units[0], (e) => e is RangeError);
Expect.throws(() => units[0] = 499, (e) => e is UnsupportedError);
Expect.throwsStateError(() => units.first);
Expect.throwsStateError(() => units.last);
Expect.throwsRangeError(() => units[0]);
Expect.throwsUnsupportedError(() => units[0] = 499);
Expect.listEquals([], units.sublist(0, 0));
Expect.equals(-1, units.indexOf(42));
Expect.equals(-1, units.lastIndexOf(499));
@ -40,9 +40,7 @@ main() {
Expect.equals(s.codeUnitAt(0), units.first);
Expect.equals(s.codeUnitAt(s.length - 1), units.last);
Expect.equals(s.codeUnitAt(0), units[0]);
Expect.throws(() {
units[0] = 499;
}, (e) => e is UnsupportedError);
Expect.throwsUnsupportedError(() => units[0] = 499);
List<int> sub = units.sublist(1);
Expect.listEquals(s.substring(1, s.length).codeUnits, sub);
Expect.equals(-1, units.indexOf(-1));

View file

@ -20,12 +20,9 @@ main() {
Expect.equals(1, unmatched.length);
Expect.equals(0xDC00, unmatched.codeUnitAt(0));
Expect.throws(() => new String.fromCharCode(-1), (e) => e is ArgumentError);
Expect.throwsArgumentError(() => new String.fromCharCode(-1));
// Invalid code point.
Expect.throws(
() => new String.fromCharCode(0x110000), (e) => e is ArgumentError);
Expect.throws(
() => new String.fromCharCode(0x110001), (e) => e is ArgumentError);
Expect.throwsArgumentError(() => new String.fromCharCode(0x110000));
Expect.throwsArgumentError(() => new String.fromCharCode(0x110001));
}

View file

@ -166,8 +166,8 @@ main() {
test("\u{10FFFF}", [0x10FFFF], 0, 1);
void testThrowsRange(iterable, [start = 0, end]) {
Expect.throws(() => new String.fromCharCodes(iterable, start, end),
(e) => e is RangeError);
Expect.throwsRangeError(
() => new String.fromCharCodes(iterable, start, end));
}
// Test varying slices of the code units of a string.

View file

@ -11,7 +11,7 @@ returnStringOrNull() {
}
main() {
Expect.throws(() => 'foo' + returnStringOrNull(), (e) => e is ArgumentError);
Expect.throwsArgumentError(() => 'foo' + returnStringOrNull());
Expect.throws(() => 'foo'.split(returnStringOrNull()),
(e) => e is ArgumentError || e is NoSuchMethodError);
}

View file

@ -67,16 +67,13 @@ main() {
Expect.equals("aaa{3}aaX", "aaa{3}aaa{3}".replaceFirst("a{3}", "X", 3));
// Test negative startIndex
Expect.throws(
() => "hello".replaceFirst("h", "X", -1), (e) => e is RangeError);
Expect.throwsRangeError(() => "hello".replaceFirst("h", "X", -1));
// Test startIndex too large
Expect.throws(
() => "hello".replaceFirst("h", "X", 6), (e) => e is RangeError);
Expect.throwsRangeError(() => "hello".replaceFirst("h", "X", 6));
// Test null startIndex
Expect.throws(
() => "hello".replaceFirst("h", "X", null), (e) => e is ArgumentError);
Expect.throwsArgumentError(() => "hello".replaceFirst("h", "X", null));
// Test replaceFirstMapped.
Expect.equals(
@ -145,16 +142,15 @@ main() {
"aaa{3}aaX", "aaa{3}aaa{3}".replaceFirstMapped("a{3}", (_) => "X", 3));
// Test negative startIndex
Expect.throws(() => "hello".replaceFirstMapped("h", (_) => "X", -1),
(e) => e is RangeError);
Expect.throwsRangeError(
() => "hello".replaceFirstMapped("h", (_) => "X", -1));
// Test startIndex too large
Expect.throws(() => "hello".replaceFirstMapped("h", (_) => "X", 6),
(e) => e is RangeError);
Expect.throwsRangeError(() => "hello".replaceFirstMapped("h", (_) => "X", 6));
// Test null startIndex
Expect.throws(() => "hello".replaceFirstMapped("h", (_) => "X", null),
(e) => e is ArgumentError);
Expect.throwsArgumentError(
() => "hello".replaceFirstMapped("h", (_) => "X", null));
// Test replacement depending on argument.
Expect.equals("foo-BAR-foo-bar",

View file

@ -28,9 +28,8 @@ testSplit(List<String> expect, String string, Pattern pattern) {
// Ensure that the correct type is reified.
actual = actual as List<String>;
Expect.throws(() {
actual.add(42);
}, (e) => e is TypeError, 'List<String>.add should not accept an int');
Expect.throwsTypeError(() => actual.add(42),
'List<String>.add should not accept an int');
Expect.listEquals(expect, actual, '"$string".split($patternString)');
}

View file

@ -7,25 +7,25 @@ import "package:expect/expect.dart";
main() {
// Test that not providing an optional argument goes to the end.
Expect.equals("".substring(0), "");
Expect.throws(() => "".substring(1), (e) => e is RangeError);
Expect.throws(() => "".substring(-1), (e) => e is RangeError);
Expect.throwsRangeError(() => "".substring(1));
Expect.throwsRangeError(() => "".substring(-1));
Expect.equals("abc".substring(0), "abc");
Expect.equals("abc".substring(1), "bc");
Expect.equals("abc".substring(2), "c");
Expect.equals("abc".substring(3), "");
Expect.throws(() => "abc".substring(4), (e) => e is RangeError);
Expect.throws(() => "abc".substring(-1), (e) => e is RangeError);
Expect.throwsRangeError(() => "abc".substring(4));
Expect.throwsRangeError(() => "abc".substring(-1));
// Test that providing null goes to the end.
Expect.equals("".substring(0, null), "");
Expect.throws(() => "".substring(1, null), (e) => e is RangeError);
Expect.throws(() => "".substring(-1, null), (e) => e is RangeError);
Expect.throwsRangeError(() => "".substring(1, null));
Expect.throwsRangeError(() => "".substring(-1, null));
Expect.equals("abc".substring(0, null), "abc");
Expect.equals("abc".substring(1, null), "bc");
Expect.equals("abc".substring(2, null), "c");
Expect.equals("abc".substring(3, null), "");
Expect.throws(() => "abc".substring(4, null), (e) => e is RangeError);
Expect.throws(() => "abc".substring(-1, null), (e) => e is RangeError);
Expect.throwsRangeError(() => "abc".substring(4, null));
Expect.throwsRangeError(() => "abc".substring(-1, null));
}

View file

@ -5,7 +5,7 @@
import "package:expect/expect.dart";
void checkBadSymbol(String s) {
Expect.throws(() => new Symbol(s), (e) => e is ArgumentError);
Expect.throwsArgumentError(() => new Symbol(s));
}
main() {

View file

@ -35,8 +35,7 @@ testFileUri() {
Uri uri = Uri.parse(s);
if (filePath is Error) {
if (filePath is UnsupportedError) {
Expect.throws(() => uri.toFilePath(windows: windows),
(e) => e is UnsupportedError);
Expect.throwsUnsupportedError(() => uri.toFilePath(windows: windows));
} else {
Expect.throws(() => uri.toFilePath(windows: windows));
}
@ -112,16 +111,13 @@ testFileUriWindowsWin32Namespace() {
Expect.equals(test[2], uri.toFilePath(windows: true));
}
Expect.throws(() => new Uri.file("\\\\?\\file", windows: true),
(e) => e is ArgumentError);
Expect.throws(
() => new Uri.file("\\\\?\\UNX\\server\\share\\file", windows: true),
(e) => e is ArgumentError);
Expect.throws(() => new Uri.directory("\\\\?\\file", windows: true),
(e) => e is ArgumentError);
Expect.throws(
() => new Uri.directory("\\\\?\\UNX\\server\\share\\file", windows: true),
(e) => e is ArgumentError);
Expect.throwsArgumentError(() => new Uri.file("\\\\?\\file", windows: true));
Expect.throwsArgumentError(
() => new Uri.file("\\\\?\\UNX\\server\\share\\file", windows: true));
Expect.throwsArgumentError(
() => new Uri.directory("\\\\?\\file", windows: true));
Expect.throwsArgumentError(() =>
new Uri.directory("\\\\?\\UNX\\server\\share\\file", windows: true));
}
testFileUriDriveLetter() {
@ -132,8 +128,7 @@ testFileUriDriveLetter() {
if (windows != null) {
Expect.equals(windows, uri.toFilePath(windows: true));
} else {
Expect.throws(
() => uri.toFilePath(windows: true), (e) => e is UnsupportedError);
Expect.throwsUnsupportedError(() => uri.toFilePath(windows: true));
}
}
@ -142,18 +137,12 @@ testFileUriDriveLetter() {
check("file:///C:a", "/C:a", null);
check("file:///C:a/", "/C:a/", null);
Expect.throws(
() => new Uri.file("C:", windows: true), (e) => e is ArgumentError);
Expect.throws(
() => new Uri.file("C:a", windows: true), (e) => e is ArgumentError);
Expect.throws(
() => new Uri.file("C:a\b", windows: true), (e) => e is ArgumentError);
Expect.throws(
() => new Uri.directory("C:", windows: true), (e) => e is ArgumentError);
Expect.throws(
() => new Uri.directory("C:a", windows: true), (e) => e is ArgumentError);
Expect.throws(() => new Uri.directory("C:a\b", windows: true),
(e) => e is ArgumentError);
Expect.throwsArgumentError(() => new Uri.file("C:", windows: true));
Expect.throwsArgumentError(() => new Uri.file("C:a", windows: true));
Expect.throwsArgumentError(() => new Uri.file("C:a\b", windows: true));
Expect.throwsArgumentError(() => new Uri.directory("C:", windows: true));
Expect.throwsArgumentError(() => new Uri.directory("C:a", windows: true));
Expect.throwsArgumentError(() => new Uri.directory("C:a\b", windows: true));
}
testFileUriResolve() {
@ -191,10 +180,8 @@ testFileUriIllegalCharacters() {
// Slash is an invalid character in file names on both non-Windows
// and Windows.
Uri uri = Uri.parse("file:///a%2Fb");
Expect.throws(
() => uri.toFilePath(windows: false), (e) => e is UnsupportedError);
Expect.throws(
() => uri.toFilePath(windows: true), (e) => e is UnsupportedError);
Expect.throwsUnsupportedError(() => uri.toFilePath(windows: false));
Expect.throwsUnsupportedError(() => uri.toFilePath(windows: true));
// Illegal characters in windows file names.
var illegalWindowsPaths = [
@ -209,28 +196,22 @@ testFileUriIllegalCharacters() {
];
for (var test in illegalWindowsPaths) {
Expect.throws(
() => new Uri.file(test, windows: true), (e) => e is ArgumentError);
Expect.throws(() => new Uri.file("\\$test", windows: true),
(e) => e is ArgumentError);
Expect.throws(() => new Uri.directory(test, windows: true),
(e) => e is ArgumentError);
Expect.throws(() => new Uri.directory("\\$test", windows: true),
(e) => e is ArgumentError);
Expect.throwsArgumentError(() => new Uri.file(test, windows: true));
Expect.throwsArgumentError(() => new Uri.file("\\$test", windows: true));
Expect.throwsArgumentError(() => new Uri.directory(test, windows: true));
Expect
.throwsArgumentError(() => new Uri.directory("\\$test", windows: true));
// It is possible to create non-Windows URIs, but not Windows URIs.
Uri uri = new Uri.file(test, windows: false);
Uri absoluteUri = new Uri.file("/$test", windows: false);
Uri dirUri = new Uri.directory(test, windows: false);
Uri dirAbsoluteUri = new Uri.directory("/$test", windows: false);
Expect.throws(
() => new Uri.file(test, windows: true), (e) => e is ArgumentError);
Expect.throws(() => new Uri.file("\\$test", windows: true),
(e) => e is ArgumentError);
Expect.throws(() => new Uri.directory(test, windows: true),
(e) => e is ArgumentError);
Expect.throws(() => new Uri.directory("\\$test", windows: true),
(e) => e is ArgumentError);
Expect.throwsArgumentError(() => new Uri.file(test, windows: true));
Expect.throwsArgumentError(() => new Uri.file("\\$test", windows: true));
Expect.throwsArgumentError(() => new Uri.directory(test, windows: true));
Expect
.throwsArgumentError(() => new Uri.directory("\\$test", windows: true));
// It is possible to extract non-Windows file path, but not
// Windows file path.
@ -238,14 +219,11 @@ testFileUriIllegalCharacters() {
Expect.equals("/$test", absoluteUri.toFilePath(windows: false));
Expect.equals("$test/", dirUri.toFilePath(windows: false));
Expect.equals("/$test/", dirAbsoluteUri.toFilePath(windows: false));
Expect.throws(
() => uri.toFilePath(windows: true), (e) => e is UnsupportedError);
Expect.throws(() => absoluteUri.toFilePath(windows: true),
(e) => e is UnsupportedError);
Expect.throws(
() => dirUri.toFilePath(windows: true), (e) => e is UnsupportedError);
Expect.throws(() => dirAbsoluteUri.toFilePath(windows: true),
(e) => e is UnsupportedError);
Expect.throwsUnsupportedError(() => uri.toFilePath(windows: true));
Expect.throwsUnsupportedError(() => absoluteUri.toFilePath(windows: true));
Expect.throwsUnsupportedError(() => dirUri.toFilePath(windows: true));
Expect
.throwsUnsupportedError(() => dirAbsoluteUri.toFilePath(windows: true));
}
// Backslash
@ -266,42 +244,33 @@ testFileUriIllegalCharacters() {
Expect.equals("/$test", absoluteUri.toFilePath(windows: false));
Expect.equals("$test/", dirUri.toFilePath(windows: false));
Expect.equals("/$test/", dirAbsoluteUri.toFilePath(windows: false));
Expect.throws(
() => uri.toFilePath(windows: true), (e) => e is UnsupportedError);
Expect.throws(() => absoluteUri.toFilePath(windows: true),
(e) => e is UnsupportedError);
Expect.throws(
() => dirUri.toFilePath(windows: true), (e) => e is UnsupportedError);
Expect.throws(() => dirAbsoluteUri.toFilePath(windows: true),
(e) => e is UnsupportedError);
Expect.throwsUnsupportedError(() => uri.toFilePath(windows: true));
Expect.throwsUnsupportedError(() => absoluteUri.toFilePath(windows: true));
Expect.throwsUnsupportedError(() => dirUri.toFilePath(windows: true));
Expect
.throwsUnsupportedError(() => dirAbsoluteUri.toFilePath(windows: true));
}
}
testFileUriIllegalDriveLetter() {
Expect.throws(
() => new Uri.file("1:\\", windows: true), (e) => e is ArgumentError);
Expect.throws(() => new Uri.directory("1:\\", windows: true),
(e) => e is ArgumentError);
Expect.throwsArgumentError(() => new Uri.file("1:\\", windows: true));
Expect.throwsArgumentError(() => new Uri.directory("1:\\", windows: true));
Uri uri = new Uri.file("1:\\", windows: false);
Uri dirUri = new Uri.directory("1:\\", windows: false);
Expect.equals("1:\\", uri.toFilePath(windows: false));
Expect.equals("1:\\/", dirUri.toFilePath(windows: false));
Expect.throws(
() => uri.toFilePath(windows: true), (e) => e is UnsupportedError);
Expect.throws(
() => dirUri.toFilePath(windows: true), (e) => e is UnsupportedError);
Expect.throwsUnsupportedError(() => uri.toFilePath(windows: true));
Expect.throwsUnsupportedError(() => dirUri.toFilePath(windows: true));
}
testAdditionalComponents() {
check(String s, {bool windowsOk: false}) {
Uri uri = Uri.parse(s);
Expect.throws(
() => uri.toFilePath(windows: false), (e) => e is UnsupportedError);
Expect.throwsUnsupportedError(() => uri.toFilePath(windows: false));
if (windowsOk) {
Expect.isTrue(uri.toFilePath(windows: true) is String);
} else {
Expect.throws(
() => uri.toFilePath(windows: true), (e) => e is UnsupportedError);
Expect.throwsUnsupportedError(() => uri.toFilePath(windows: true));
}
}

View file

@ -10,8 +10,7 @@ void testParseIPv4Address() {
}
void fail(String host) {
Expect.throws(
() => Uri.parseIPv4Address(host), (e) => e is FormatException);
Expect.throwsFormatException(() => Uri.parseIPv4Address(host));
}
pass('127.0.0.1', [127, 0, 0, 1]);

View file

@ -112,8 +112,7 @@ void testParseIPv6Address() {
}
void fail(String host) {
Expect.throws(
() => Uri.parseIPv6Address(host), (e) => e is FormatException);
Expect.throwsFormatException(() => Uri.parseIPv6Address(host));
}
pass('::127.0.0.1', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 0, 0, 1]);

View file

@ -142,33 +142,31 @@ void testPathCompare() {
testPathSegmentsUnmodifiableList() {
void test(list) {
bool isUnsupported(e) => e is UnsupportedError;
Expect.equals("a", list[0]);
Expect.throws(() => list[0] = "c", isUnsupported);
Expect.throwsUnsupportedError(() => list[0] = "c");
Expect.equals(2, list.length);
Expect.throws(() => list.length = 1, isUnsupported);
Expect.throws(() => list.add("c"), isUnsupported);
Expect.throws(() => list.addAll(["c", "d"]), isUnsupported);
Expect.throwsUnsupportedError(() => list.length = 1);
Expect.throwsUnsupportedError(() => list.add("c"));
Expect.throwsUnsupportedError(() => list.addAll(["c", "d"]));
Expect.listEquals(["b", "a"], list.reversed.toList());
Expect.throws(() => list.sort(), isUnsupported);
Expect.throws(() => list.sort());
Expect.equals(0, list.indexOf("a"));
Expect.equals(0, list.lastIndexOf("a"));
Expect.throws(() => list.clear(), isUnsupported);
Expect.throws(() => list.insert(1, "c"), isUnsupported);
Expect.throws(() => list.insertAll(1, ["c", "d"]), isUnsupported);
Expect.throws(() => list.setAll(1, ["c", "d"]), isUnsupported);
Expect.throws(() => list.remove("a"), isUnsupported);
Expect.throws(() => list.removeAt(0), isUnsupported);
Expect.throws(() => list.removeLast(), isUnsupported);
Expect.throws(() => list.removeWhere((e) => true), isUnsupported);
Expect.throws(() => list.retainWhere((e) => false), isUnsupported);
Expect.throwsUnsupportedError(() => list.clear());
Expect.throwsUnsupportedError(() => list.insert(1, "c"));
Expect.throwsUnsupportedError(() => list.insertAll(1, ["c", "d"]));
Expect.throwsUnsupportedError(() => list.setAll(1, ["c", "d"]));
Expect.throwsUnsupportedError(() => list.remove("a"));
Expect.throwsUnsupportedError(() => list.removeAt(0));
Expect.throwsUnsupportedError(() => list.removeLast());
Expect.throwsUnsupportedError(() => list.removeWhere((e) => true));
Expect.throwsUnsupportedError(() => list.retainWhere((e) => false));
Expect.listEquals(["a"], list.sublist(0, 1));
Expect.listEquals(["a"], list.getRange(0, 1).toList());
Expect.throws(() => list.setRange(0, 1, ["c"]), isUnsupported);
Expect.throws(() => list.removeRange(0, 1), isUnsupported);
Expect.throws(() => list.fillRange(0, 1, "c"), isUnsupported);
Expect.throws(() => list.replaceRange(0, 1, ["c"]), isUnsupported);
Expect.throwsUnsupportedError(() => list.setRange(0, 1, ["c"]));
Expect.throwsUnsupportedError(() => list.removeRange(0, 1));
Expect.throwsUnsupportedError(() => list.fillRange(0, 1, "c"));
Expect.throwsUnsupportedError(() => list.replaceRange(0, 1, ["c"]));
Map map = new Map();
map[0] = "a";
map[1] = "b";

View file

@ -150,15 +150,13 @@ testInvalidQueryParameters() {
testQueryParametersImmutableMap() {
test(map) {
bool isUnsupported(e) => e is UnsupportedError;
Expect.isTrue(map.containsValue("b"));
Expect.isTrue(map.containsKey("a"));
Expect.equals("b", map["a"]);
Expect.throws(() => map["a"] = "c", isUnsupported);
Expect.throws(() => map.putIfAbsent("b", () => "e"), isUnsupported);
Expect.throws(() => map.remove("a"), isUnsupported);
Expect.throws(() => map.clear(), isUnsupported);
Expect.throwsUnsupportedError(() => map["a"] = "c");
Expect.throwsUnsupportedError(() => map.putIfAbsent("b", () => "e"));
Expect.throwsUnsupportedError(() => map.remove("a"));
Expect.throwsUnsupportedError(() => map.clear());
var count = 0;
map.forEach((key, value) => count++);
Expect.equals(2, count);

View file

@ -5,10 +5,9 @@
import "package:expect/expect.dart";
void testInvalidArguments() {
Expect.throws(() => new Uri(scheme: "_"), (e) => e is FormatException);
Expect.throws(() => new Uri(scheme: "http_s"), (e) => e is FormatException);
Expect.throws(
() => new Uri(scheme: "127.0.0.1:80"), (e) => e is FormatException);
Expect.throwsFormatException(() => new Uri(scheme: "_"));
Expect.throwsFormatException(() => new Uri(scheme: "http_s"));
Expect.throwsFormatException(() => new Uri(scheme: "127.0.0.1:80"));
}
void testScheme() {

View file

@ -65,8 +65,8 @@ testEncodeDecodeQueryComponent(String orig, String encodedUTF8,
d = Uri.decodeQueryComponent(encodedAscii, encoding: ASCII);
Expect.stringEquals(orig, d);
} else {
Expect.throws(() => Uri.encodeQueryComponent(orig, encoding: ASCII),
(e) => e is ArgumentError);
Expect.throwsArgumentError(
() => Uri.encodeQueryComponent(orig, encoding: ASCII));
}
}
@ -524,10 +524,9 @@ main() {
Uri.parse("http://example.com:1234/a/b/c").origin);
Expect.stringEquals("https://example.com:1234",
Uri.parse("https://example.com:1234/a/b/c").origin);
Expect.throws(() => Uri.parse("http:").origin, (e) {
return e is StateError;
}, "origin for uri with empty host should fail");
Expect.throws(
Expect.throwsStateError(() => Uri.parse("http:").origin,
"origin for uri with empty host should fail");
Expect.throwsStateError(
() => new Uri(
scheme: "http",
userInfo: null,
@ -536,10 +535,9 @@ main() {
path: "/a/b/c",
query: "query",
fragment: "fragment")
.origin, (e) {
return e is StateError;
}, "origin for uri with empty host should fail");
Expect.throws(
.origin,
"origin for uri with empty host should fail");
Expect.throwsStateError(
() => new Uri(
scheme: null,
userInfo: null,
@ -548,10 +546,9 @@ main() {
path: "/a/b/c",
query: "query",
fragment: "fragment")
.origin, (e) {
return e is StateError;
}, "origin for uri with empty scheme should fail");
Expect.throws(
.origin,
"origin for uri with empty scheme should fail");
Expect.throwsStateError(
() => new Uri(
scheme: "http",
userInfo: null,
@ -560,15 +557,12 @@ main() {
path: "/a/b/c",
query: "query",
fragment: "fragment")
.origin, (e) {
return e is StateError;
}, "origin for uri with empty host should fail");
Expect.throws(() => Uri.parse("http://:80").origin, (e) {
return e is StateError;
}, "origin for uri with empty host should fail");
Expect.throws(() => Uri.parse("file://localhost/test.txt").origin, (e) {
return e is StateError;
}, "origin for non-http/https uri should fail");
.origin,
"origin for uri with empty host should fail");
Expect.throwsStateError(() => Uri.parse("http://:80").origin,
"origin for uri with empty host should fail");
Expect.throwsStateError(() => Uri.parse("file://localhost/test.txt").origin,
"origin for non-http/https uri should fail");
// URI encode tests
// Create a string with code point 0x10000 encoded as a surrogate pair.
@ -621,8 +615,8 @@ main() {
testEncodeDecodeComponent(nonAscii, nonAsciiEncoding);
// Invalid URI - : and @ is swapped, port ("host") should be numeric.
Expect.throws(() => Uri.parse("file://user@password:host/path"),
(e) => e is FormatException);
Expect.throwsFormatException(
() => Uri.parse("file://user@password:host/path"));
testValidCharacters();
testInvalidUrls();

View file

@ -8,17 +8,15 @@ import "package:expect/expect.dart";
class Foo {
// Intentionally abstract:
get i; // //# 01: compile-time error
get i; //# 01: compile-time error
}
class Bar {}
noMethod(e) => e is NoSuchMethodError;
checkIt(f) {
Expect.throws(() { f.i = 'hi'; }, noMethod); // //# 01: continued
Expect.throws(() { print(f.i); }, noMethod); // //# 01: continued
Expect.throws(() { print(f.i()); }, noMethod); // //# 01: continued
Expect.throwsNoSuchMethodError(() => f.i = 'hi'); // //# 01: continued
Expect.throwsNoSuchMethodError(() => print(f.i)); // //# 01: continued
Expect.throwsNoSuchMethodError(() => print(f.i())); // //# 01: continued
}
main() {

View file

@ -89,7 +89,7 @@ void test(int x, int y) {
assert(assertionsEnabled = true);
bool Function(C Function()) doTest = (assertionsEnabled && x >= y)
? (f) { Expect.throws(f, (e) => e is AssertionError); }
? (f) { Expect.throwsAssertionError(f); }
: (f) { Expect.equals(x, f().x); };
doTest(() => new C.c01(x, y));

View file

@ -20,7 +20,5 @@ class Class {
}
main() {
Expect.throwsAssertionError(() {
new Class(a: null, b: null).field;
});
Expect.throwsAssertionError(() => new Class(a: null, b: null).field);
}

View file

@ -43,9 +43,7 @@ main() {
Expect.equals("4455", named_arg_tearOff.call(x: 44, y: 55));
}
Expect.throws(() => bar_tearOff.call(), (e) => e is NoSuchMethodError);
Expect.throws(
() => opt_arg_tearOff.call(x: "p"), (e) => e is NoSuchMethodError);
Expect.throws(
() => named_arg_tearOff.call("p", "q"), (e) => e is NoSuchMethodError);
Expect.throws(() => bar_tearOff.call());
Expect.throwsNoSuchMethodError(() => opt_arg_tearOff.call(x: "p"));
Expect.throwsNoSuchMethodError(() => named_arg_tearOff.call("p", "q"));
}

View file

@ -44,12 +44,8 @@ class CallThroughGetterTest {
Expect.equals(87, (a.field)());
a.field = 99;
Expect.throwsNoSuchMethodError(() {
a.field();
});
Expect.throwsNoSuchMethodError(() {
(a.field)();
});
Expect.throwsNoSuchMethodError(() => a.field());
Expect.throwsNoSuchMethodError(() => (a.field)());
}
static void testGetter() {
@ -63,12 +59,8 @@ class CallThroughGetterTest {
Expect.equals(87, (a.getter)());
a.field = 99;
Expect.throwsNoSuchMethodError(() {
a.getter();
});
Expect.throwsNoSuchMethodError(() {
(a.getter)();
});
Expect.throwsNoSuchMethodError(() => a.getter());
Expect.throwsNoSuchMethodError(() => (a.getter)());
}
static void testMethod() {

View file

@ -20,51 +20,33 @@ class CallThroughNullGetterTest {
static void testTopLevel() {
topLevel = null;
Expect.throwsNoSuchMethodError(() {
topLevel();
});
Expect.throwsNoSuchMethodError(() {
(topLevel)();
});
Expect.throwsNoSuchMethodError(() {
TOP_LEVEL_NULL();
});
Expect.throwsNoSuchMethodError(() {
(TOP_LEVEL_NULL)();
});
Expect.throwsNoSuchMethodError(() => topLevel());
Expect.throwsNoSuchMethodError(() => (topLevel)());
Expect.throwsNoSuchMethodError(() => TOP_LEVEL_NULL());
Expect.throwsNoSuchMethodError(() => (TOP_LEVEL_NULL)());
}
static void testField() {
A a = new A();
a.field = null;
Expect.throwsNoSuchMethodError(() {
a.field();
});
Expect.throwsNoSuchMethodError(() {
(a.field)();
});
Expect.throwsNoSuchMethodError(() => a.field());
Expect.throwsNoSuchMethodError(() => (a.field)());
}
static void testGetter() {
A a = new A();
a.field = null;
Expect.throwsNoSuchMethodError(() {
a.getter();
});
Expect.throwsNoSuchMethodError(() {
(a.getter)();
});
Expect.throwsNoSuchMethodError(() => a.getter());
Expect.throwsNoSuchMethodError(() => (a.getter)());
}
static void testMethod() {
A a = new A();
a.field = null;
Expect.throwsNoSuchMethodError(() {
a.method()();
});
Expect.throwsNoSuchMethodError(() => a.method()());
}
}

View file

@ -30,30 +30,30 @@ main() {
//
// Remove the legacy Expect.throws and namespaces around statements that don't
// need it after a careful examination of each case.
Expect.throws(() { Class(); }, (e) => e is NoSuchMethodError); //# 01: compile-time error
Expect.throws(() { Class[0]; }, (e) => e is NoSuchMethodError); //# 02: compile-time error
Expect.throws(() { var x = Class();}, (e) => e is NoSuchMethodError); //# 03: compile-time error
Expect.throws(() { var x = Class[0]; }, (e) => e is NoSuchMethodError); //# 04: compile-time error
Expect.throws(() { var x = Class[0].field; }, (e) => e is NoSuchMethodError); //# 05: compile-time error
Expect.throws(() { var x = Class[0].method(); }, (e) => e is NoSuchMethodError); //# 06: compile-time error
Expect.throws(() { foo(Class()); }, (e) => e is NoSuchMethodError); //# 07: compile-time error
Expect.throws(() { foo(Class[0]); }, (e) => e is NoSuchMethodError); //# 08: compile-time error
Expect.throws(() { foo(Class[0].field); }, (e) => e is NoSuchMethodError); //# 09: compile-time error
Expect.throws(() { foo(Class[0].method()); }, (e) => e is NoSuchMethodError); //# 10: compile-time error
Expect.throws(() { Class[0] = 91; }, (e) => e is NoSuchMethodError); //# 11: compile-time error
Expect.throws(() { Class++; }, (e) => e is NoSuchMethodError); //# 12: compile-time error
Expect.throws(() { ++Class; }, (e) => e is NoSuchMethodError); //# 13: compile-time error
Expect.throws(() { Class[0] += 3; }, (e) => e is NoSuchMethodError); //# 14: compile-time error
Expect.throws(() { ++Class[0]; }, (e) => e is NoSuchMethodError); //# 15: compile-time error
Expect.throws(() { Class[0]++; }, (e) => e is NoSuchMethodError); //# 16: compile-time error
Expect.throws(() { Class.method(); }, (e) => e is NoSuchMethodError); //# 17: compile-time error
Expect.throws(() { Class.field; }, (e) => e is NoSuchMethodError); //# 18: compile-time error
Expect.throws(() { var x = Class.method(); }, (e) => e is NoSuchMethodError); //# 19: compile-time error
Expect.throws(() { var x = Class.field; }, (e) => e is NoSuchMethodError); //# 20: compile-time error
Expect.throws(() { foo(Class.method()); }, (e) => e is NoSuchMethodError); //# 21: compile-time error
Expect.throws(() { foo(Class.field); }, (e) => e is NoSuchMethodError); //# 22: compile-time error
Expect.throws(() { Class / 3; }, (e) => e is NoSuchMethodError); //# 23: compile-time error
Expect.throws(() { Class += 3; }, (e) => e is NoSuchMethodError); //# 24: compile-time error
Expect.throwsNoSuchMethodError(() { Class(); }); //# 01: compile-time error
Expect.throwsNoSuchMethodError(() { Class[0]; }); //# 02: compile-time error
Expect.throwsNoSuchMethodError(() { var x = Class();}); //# 03: compile-time error
Expect.throwsNoSuchMethodError(() { var x = Class[0]; }); //# 04: compile-time error
Expect.throwsNoSuchMethodError(() { var x = Class[0].field; }); //# 05: compile-time error
Expect.throwsNoSuchMethodError(() { var x = Class[0].method(); }); //# 06: compile-time error
Expect.throwsNoSuchMethodError(() { foo(Class()); }); //# 07: compile-time error
Expect.throwsNoSuchMethodError(() { foo(Class[0]); }); //# 08: compile-time error
Expect.throwsNoSuchMethodError(() { foo(Class[0].field); }); //# 09: compile-time error
Expect.throwsNoSuchMethodError(() { foo(Class[0].method()); }); //# 10: compile-time error
Expect.throwsNoSuchMethodError(() { Class[0] = 91; }); //# 11: compile-time error
Expect.throwsNoSuchMethodError(() { Class++; }); //# 12: compile-time error
Expect.throwsNoSuchMethodError(() { ++Class; }); //# 13: compile-time error
Expect.throwsNoSuchMethodError(() { Class[0] += 3; }); //# 14: compile-time error
Expect.throwsNoSuchMethodError(() { ++Class[0]; }); //# 15: compile-time error
Expect.throwsNoSuchMethodError(() { Class[0]++; }); //# 16: compile-time error
Expect.throwsNoSuchMethodError(() { Class.method(); }); //# 17: compile-time error
Expect.throwsNoSuchMethodError(() { Class.field; }); //# 18: compile-time error
Expect.throwsNoSuchMethodError(() { var x = Class.method(); }); //# 19: compile-time error
Expect.throwsNoSuchMethodError(() { var x = Class.field; }); //# 20: compile-time error
Expect.throwsNoSuchMethodError(() { foo(Class.method()); }); //# 21: compile-time error
Expect.throwsNoSuchMethodError(() { foo(Class.field); }); //# 22: compile-time error
Expect.throwsNoSuchMethodError(() { Class / 3; }); //# 23: compile-time error
Expect.throwsNoSuchMethodError(() { Class += 3; }); //# 24: compile-time error
// Verify that a class literal isn't a string literal.
Expect.notEquals(Class, "Class");
@ -63,5 +63,5 @@ main() {
var y = Class;
Expect.isTrue(y.toString() is String);
Expect.throws(() { Class.toString(); }, (e) => e is NoSuchMethodError); //# 25: compile-time error
Expect.throwsNoSuchMethodError(() => Class.toString()); //# 25: compile-time error
}

View file

@ -14,7 +14,5 @@ test(x, y) {
}
main() {
Expect.throws(() {
test(null, 2);
}, (e) => e is NoSuchMethodError);
Expect.throwsNoSuchMethodError(() => test(null, 2));
}

View file

@ -8,9 +8,9 @@
import "package:expect/expect.dart";
void test(A func(String value), String value) {
Expect.throws(() {
B x = func(value);
}, (e) => e is TypeError);
Expect.throwsTypeError(() {
B x = func(value);
});
}
@ -25,9 +25,9 @@ class C {
}
A aclosure(String x) => C.a(x);
A bclosure() => new A();
A bclosure() => new A();
main() {
test(aclosure, "foo");
test((bar) => bclosure(), "baz");
}
}

View file

@ -12,8 +12,6 @@ const m5 = const {'': 499};
const m6 = const {'a': 499};
const m7 = const {};
bool isUnsupportedError(o) => o is UnsupportedError;
main() {
Expect.equals(499, m1['a']);
Expect.equals(null, m1['b']);
@ -34,13 +32,13 @@ main() {
Expect.listEquals([499], seenValues);
Expect.isFalse(m1.isEmpty);
Expect.equals(1, m1.length);
Expect.throws(() => m1.remove('a'), isUnsupportedError);
Expect.throws(() => m1.remove('b'), isUnsupportedError);
Expect.throws(() => m1.clear(), isUnsupportedError);
Expect.throws(() => m1['b'] = 42, isUnsupportedError);
Expect.throws(() => m1['a'] = 499, isUnsupportedError);
Expect.throws(() => m1.putIfAbsent('a', () => 499), isUnsupportedError);
Expect.throws(() => m1.putIfAbsent('z', () => 499), isUnsupportedError);
Expect.throwsUnsupportedError(() => m1.remove('a'));
Expect.throwsUnsupportedError(() => m1.remove('b'));
Expect.throwsUnsupportedError(() => m1.clear());
Expect.throwsUnsupportedError(() => m1['b'] = 42);
Expect.throwsUnsupportedError(() => m1['a'] = 499);
Expect.throwsUnsupportedError(() => m1.putIfAbsent('a', () => 499));
Expect.throwsUnsupportedError(() => m1.putIfAbsent('z', () => 499));
Expect.equals(499, m2['a']);
Expect.equals(42, m2['b']);
@ -64,16 +62,16 @@ main() {
Expect.listEquals([499, 42], seenValues);
Expect.isFalse(m2.isEmpty);
Expect.equals(2, m2.length);
Expect.throws(() => m2.remove('a'), isUnsupportedError);
Expect.throws(() => m2.remove('b'), isUnsupportedError);
Expect.throws(() => m2.remove('c'), isUnsupportedError);
Expect.throws(() => m2.clear(), isUnsupportedError);
Expect.throws(() => m2['a'] = 499, isUnsupportedError);
Expect.throws(() => m2['b'] = 42, isUnsupportedError);
Expect.throws(() => m2['c'] = 499, isUnsupportedError);
Expect.throws(() => m2.putIfAbsent('a', () => 499), isUnsupportedError);
Expect.throws(() => m2.putIfAbsent('z', () => 499), isUnsupportedError);
Expect.throws(() => m2['a'] = 499, isUnsupportedError);
Expect.throwsUnsupportedError(() => m2.remove('a'));
Expect.throwsUnsupportedError(() => m2.remove('b'));
Expect.throwsUnsupportedError(() => m2.remove('c'));
Expect.throwsUnsupportedError(() => m2.clear());
Expect.throwsUnsupportedError(() => m2['a'] = 499);
Expect.throwsUnsupportedError(() => m2['b'] = 42);
Expect.throwsUnsupportedError(() => m2['c'] = 499);
Expect.throwsUnsupportedError(() => m2.putIfAbsent('a', () => 499));
Expect.throwsUnsupportedError(() => m2.putIfAbsent('z', () => 499));
Expect.throwsUnsupportedError(() => m2['a'] = 499);
Expect.identical(m3['m1'], m1);
Expect.identical(m3['m2'], m2);
@ -112,11 +110,11 @@ main() {
});
Expect.listEquals([], seenKeys);
Expect.listEquals([], seenValues);
Expect.throws(() => m7.remove('a'), isUnsupportedError);
Expect.throws(() => m7.remove('b'), isUnsupportedError);
Expect.throws(() => m7.clear(), isUnsupportedError);
Expect.throws(() => m7['b'] = 42, isUnsupportedError);
Expect.throws(() => m7['a'] = 499, isUnsupportedError);
Expect.throws(() => m7.putIfAbsent('a', () => 499), isUnsupportedError);
Expect.throws(() => m7.putIfAbsent('z', () => 499), isUnsupportedError);
Expect.throwsUnsupportedError(() => m7.remove('a'));
Expect.throwsUnsupportedError(() => m7.remove('b'));
Expect.throwsUnsupportedError(() => m7.clear());
Expect.throwsUnsupportedError(() => m7['b'] = 42);
Expect.throwsUnsupportedError(() => m7['a'] = 499);
Expect.throwsUnsupportedError(() => m7.putIfAbsent('a', () => 499));
Expect.throwsUnsupportedError(() => m7.putIfAbsent('z', () => 499));
}

View file

@ -8,8 +8,6 @@ const m1 = const {'__proto__': 400 + 99};
const m2 = const {'a': 499, 'b': 42};
const m3 = const {'__proto__': 499};
bool isUnsupportedError(o) => o is UnsupportedError;
main() {
Expect.equals(499, m1['__proto__']);
Expect.equals(null, m1['b']);
@ -29,14 +27,13 @@ main() {
Expect.listEquals([499], seenValues);
Expect.isFalse(m1.isEmpty);
Expect.equals(1, m1.length);
Expect.throws(() => m1.remove('__proto__'), isUnsupportedError);
Expect.throws(() => m1.remove('b'), isUnsupportedError);
Expect.throws(() => m1.clear(), isUnsupportedError);
Expect.throws(() => m1['b'] = 42, isUnsupportedError);
Expect.throws(() => m1['__proto__'] = 499, isUnsupportedError);
Expect.throws(
() => m1.putIfAbsent('__proto__', () => 499), isUnsupportedError);
Expect.throws(() => m1.putIfAbsent('z', () => 499), isUnsupportedError);
Expect.throwsUnsupportedError(() => m1.remove('__proto__'));
Expect.throwsUnsupportedError(() => m1.remove('b'));
Expect.throwsUnsupportedError(() => m1.clear());
Expect.throwsUnsupportedError(() => m1['b'] = 42);
Expect.throwsUnsupportedError(() => m1['__proto__'] = 499);
Expect.throwsUnsupportedError(() => m1.putIfAbsent('__proto__', () => 499));
Expect.throwsUnsupportedError(() => m1.putIfAbsent('z', () => 499));
Expect.equals(499, m2['a']);
Expect.equals(42, m2['b']);
@ -61,17 +58,16 @@ main() {
Expect.listEquals([499, 42], seenValues);
Expect.isFalse(m2.isEmpty);
Expect.equals(2, m2.length);
Expect.throws(() => m2.remove('a'), isUnsupportedError);
Expect.throws(() => m2.remove('b'), isUnsupportedError);
Expect.throws(() => m2.remove('__proto__'), isUnsupportedError);
Expect.throws(() => m2.clear(), isUnsupportedError);
Expect.throws(() => m2['a'] = 499, isUnsupportedError);
Expect.throws(() => m2['b'] = 42, isUnsupportedError);
Expect.throws(() => m2['__proto__'] = 499, isUnsupportedError);
Expect.throws(() => m2.putIfAbsent('a', () => 499), isUnsupportedError);
Expect.throws(
() => m2.putIfAbsent('__proto__', () => 499), isUnsupportedError);
Expect.throws(() => m2['a'] = 499, isUnsupportedError);
Expect.throwsUnsupportedError(() => m2.remove('a'));
Expect.throwsUnsupportedError(() => m2.remove('b'));
Expect.throwsUnsupportedError(() => m2.remove('__proto__'));
Expect.throwsUnsupportedError(() => m2.clear());
Expect.throwsUnsupportedError(() => m2['a'] = 499);
Expect.throwsUnsupportedError(() => m2['b'] = 42);
Expect.throwsUnsupportedError(() => m2['__proto__'] = 499);
Expect.throwsUnsupportedError(() => m2.putIfAbsent('a', () => 499));
Expect.throwsUnsupportedError(() => m2.putIfAbsent('__proto__', () => 499));
Expect.throwsUnsupportedError(() => m2['a'] = 499);
Expect.isTrue(identical(m1, m3));
}

View file

@ -11,8 +11,6 @@ bad() {
Expect.fail('Should not be executed');
}
noMethod(e) => e is NoSuchMethodError;
class B {}
class C extends B {
@ -59,6 +57,6 @@ main() {
h?.topLevelFunction(); //# 11: compile-time error
// Nor can it be used to access the toString method on the class Type.
Expect.throws(() => C?.toString(), noMethod); //# 12: compile-time error
Expect.throws(() => h.C?.toString(), noMethod); //# 13: compile-time error
Expect.throwsNoSuchMethodError(() => C?.toString()); //# 12: compile-time error
Expect.throwsNoSuchMethodError(() => h.C?.toString()); //# 13: compile-time error
}

View file

@ -8,8 +8,6 @@
import "package:expect/expect.dart";
import "conditional_access_helper.dart" as h;
noMethod(e) => e is NoSuchMethodError;
class B {}
class C extends B {
@ -52,6 +50,6 @@ main() {
var x = h?.topLevelVar; //# 09: compile-time error
// Nor can it be used to access the hashCode getter on the class Type.
Expect.throws(() => C?.hashCode, noMethod); //# 10: compile-time error
Expect.throws(() => h.C?.hashCode, noMethod); //# 11: compile-time error
Expect.throwsNoSuchMethodError(() => C?.hashCode); //# 10: compile-time error
Expect.throwsNoSuchMethodError(() => h.C?.hashCode); //# 11: compile-time error
}

View file

@ -12,8 +12,6 @@ bad() {
Expect.fail('Should not be executed');
}
noMethod(e) => e is NoSuchMethodError;
class B {}
class C extends B {

View file

@ -3,8 +3,6 @@
// BSD-style license that can be found in the LICENSE file.
import 'package:expect/expect.dart';
bool isTypeError(e) => e is TypeError;
class Fields<T> {
T x;
T _y;
@ -21,14 +19,10 @@ class Fields<T> {
testField() {
Fields<Object> c = new Fields<int>();
Expect.throws(() {
c.x = 'hello';
}, isTypeError);
Expect.throwsTypeError(() => c.x = 'hello');
Fields<dynamic> d = new Fields<int>();
Expect.throws(() {
c.x = 'hello';
}, isTypeError);
Expect.throwsTypeError(() => c.x = 'hello');
}
testPrivateFields() {
@ -39,9 +33,7 @@ testPrivateFields() {
Fields<Object> c2 = new Fields<String>()..x = 'hi';
c2.n(c2);
Expect.equals(c2._z, 'hi');
Expect.throws(() {
c.n(c2);
}, isTypeError);
Expect.throwsTypeError(() => c.n(c2));
Expect.equals(c2._z, 'hi');
}
@ -61,9 +53,7 @@ testClassBounds() {
NumBounds<num> d = new MethodTakesNum();
Expect.equals(d.m(-1.1), true);
d = new MethodTakesInt();
Expect.throws(() {
d.m(-1.1);
}, isTypeError);
Expect.throwsTypeError(() => d.m(-1.1));
}
typedef void F<T>(T t);
@ -84,11 +74,11 @@ class FnChecks<T> {
testReturnOfFunctionType() {
FnChecks<int> cInt = new FnChecks<int>();
FnChecks<Object> cObj = cInt;
Expect.throws(() => cObj.setterForT(), isTypeError);
Expect.throws(() => (cObj.setterForT() as F<Object>), isTypeError);
Expect.throwsTypeError(() => cObj.setterForT());
Expect.throwsTypeError(() => (cObj.setterForT() as F<Object>));
FnChecks<dynamic> cDyn = cInt;
cDyn.setterForT(); // allowed fuzzy arrow
Expect.throws(() => cDyn.setterForT()('hi'), isTypeError); // dcall throws
Expect.throwsTypeError(() => cDyn.setterForT()('hi')); // dcall throws
cInt.setterForT()(42);
Expect.equals(cObj.getT(), 42);
}
@ -97,45 +87,41 @@ testTearoffReturningFunctionType() {
FnChecks<int> cInt = new FnChecks<int>();
FnChecks<Object> cObj = cInt;
Expect.throws(
() => cObj.setterForT, isTypeError, 'unsound tear-off throws at runtime');
Expect.throwsTypeError(
() => cObj.setterForT, 'unsound tear-off throws at runtime');
Expect.equals(cInt.setterForT, cInt.setterForT, 'sound tear-off works');
}
testFieldOfFunctionType() {
FnChecks<Object> c = new FnChecks<String>()..f = (String b) {};
Expect.throws(() {
Expect.throwsTypeError(() {
F<Object> f = c.f;
}, isTypeError);
Expect.throws(() {
});
Expect.throwsTypeError(() {
Object f = c.f;
}, isTypeError);
Expect.throws(() => c.f, isTypeError);
Expect.throws(() => c.f(42), isTypeError);
Expect.throws(() => c.f('hi'), isTypeError);
});
Expect.throwsTypeError(() => c.f);
Expect.throwsTypeError(() => c.f(42));
Expect.throwsTypeError(() => c.f('hi'));
FnChecks<String> cStr = c;
cStr.f('hi');
FnChecks<dynamic> cDyn = c;
cDyn.f; // allowed fuzzy arrow
Expect.throws(() => cDyn.f(42), isTypeError); // dcall throws
Expect.throwsTypeError(() => cDyn.f(42)); // dcall throws
}
testFieldOfGenericFunctionType() {
FnChecks<Object> c = new FnChecks<num>()
..g = <S extends num>(S s) => s.isNegative;
Expect.throws(() {
Expect.throwsTypeError(() {
G<Object> g = c.g;
}, isTypeError);
Expect.throws(() {
});
Expect.throwsTypeError(() {
var g = c.g;
}, isTypeError);
Expect.throws(() {
c.g<String>('hi');
}, isTypeError);
Expect.throws(() {
c.g<int>(42);
}, isTypeError);
});
Expect.throwsTypeError(() => c.g<String>('hi'));
Expect.throwsTypeError(() => c.g<int>(42));
FnChecks<num> cNum = c;
cNum.g(42);
}
@ -161,15 +147,9 @@ testMixinApplication() {
I<Object> i = new ExtendsBase();
I<Object> j = new MixinBase();
I<Object> k = new MixinBase2();
Expect.throws(() {
i.add('hi');
}, isTypeError);
Expect.throws(() {
j.add('hi');
}, isTypeError);
Expect.throws(() {
k.add('hi');
}, isTypeError);
Expect.throwsTypeError(() => i.add('hi'));
Expect.throwsTypeError(() => j.add('hi'));
Expect.throwsTypeError(() => k.add('hi'));
}
class GenericMethodBounds<T> {
@ -192,16 +172,16 @@ GenericMethodBounds<E> Function<E extends T>() genericFunctionWithBounds<T>() {
testGenericMethodBounds() {
test(GenericMethodBounds<Object> g) {
Expect.throws(() => g.foo<String>(), isTypeError);
Expect.throws(() => g.foo(), isTypeError);
Expect.throwsTypeError(() => g.foo<String>());
Expect.throwsTypeError(() => g.foo());
Expect.equals(g.foo<Null>().t, Null);
Expect.equals(g.foo<int>().t, int);
Expect.isFalse(g.foo<int>() is GenericMethodBounds<double>);
g.bar<Function(Object)>();
dynamic d = g;
d.bar<Function(num)>();
Expect.throws(() => d.bar<Function(String)>(), isTypeError);
Expect.throws(() => d.bar<Function(Null)>(), isTypeError);
Expect.throwsTypeError(() => d.bar<Function(String)>());
Expect.throwsTypeError(() => d.bar<Function(Null)>());
}
test(new GenericMethodBounds<num>());
@ -222,9 +202,7 @@ testCallMethod() {
ClassF<Object> ca = cc; // An upcast, per covariance.
F<Object> f = ca;
Expect.equals(f.runtimeType.toString(), 'ClassF<int>');
Expect.throws(() {
f(new Object());
}, isTypeError);
Expect.throwsTypeError(() => f(new Object()));
}
class TearOff<T> {

View file

@ -19,8 +19,6 @@ void acceptsObject(Object o) {}
void acceptsNum(num n) {}
bool isTypeError(e) => e is TypeError;
void g(I<F<num>> i) {
i.f(acceptsObject);
// i.f has static type (F<num>)->void, or ((num)->void)->void. Which means we
@ -29,9 +27,7 @@ void g(I<F<num>> i) {
// its argument to be F<Object>. This means that passing acceptsNum to f
// would violate soundness (since acceptsNum has type F<num>, and F<num> is a
// supertype of F<Object>). So we expect a type error here.
Expect.throws(() {
i.f(acceptsNum);
}, isTypeError);
Expect.throwsTypeError(() => i.f(acceptsNum));
}
void main() {

View file

@ -34,15 +34,15 @@ main() {
var g2 = new G2<lib.C>(); //# new_generic2: compile-time error
var g3 = new lib.G<lib.C>(); //# new_generic3: compile-time error
var instance = lib.constantInstance;
Expect.throws(() { //# is_check: compile-time error
Expect.throwsTypeError(() { //# is_check: compile-time error
bool a7 = instance is lib.Const; //# is_check: continued
}, (e) => e is TypeError); //# is_check: continued
Expect.throws(() { //# as_operation: compile-time error
}); //# is_check: continued
Expect.throwsTypeError(() { //# as_operation: compile-time error
instance as lib.Const; //# as_operation: continued
}, (e) => e is TypeError); //# as_operation: continued
Expect.throws(() { //# catch_check: compile-time error
}); //# as_operation: continued
Expect.throwsTypeError(() { //# catch_check: compile-time error
try { throw instance; } on lib.Const {} //# catch_check: continued
}, (e) => e is TypeError); //# catch_check: continued
}); //# catch_check: continued
int i = lib.C.staticMethod(); //# static_method: ok
asyncEnd();
});

View file

@ -11,5 +11,5 @@ import "deferred_super_dependency_lib.dart" deferred as lib; //# 01: compile-tim
main() async {
await lib.loadLibrary(); //# 01: continued
Expect.throws(() => new lib.C().foo(), (e) => e is NoSuchMethodError); //# 01: continued
Expect.throwsNoSuchMethodError(() => new lib.C().foo()); //# 01: continued
}

View file

@ -7,8 +7,8 @@ import "package:expect/expect.dart";
main() {
var v = 1.0;
Expect.throws(() => v.toStringAsExponential(-1), (e) => e is RangeError);
Expect.throws(() => v.toStringAsExponential(21), (e) => e is RangeError);
Expect.throwsRangeError(() => v.toStringAsExponential(-1));
Expect.throwsRangeError(() => v.toStringAsExponential(21));
v.toStringAsExponential(1.5); //# 01: compile-time error
v.toStringAsExponential("string"); //# 02: compile-time error
v.toStringAsExponential("3"); //# 03: compile-time error

View file

@ -7,9 +7,9 @@ import "package:expect/expect.dart";
main() {
var v = 0.0;
Expect.throws(() => v.toStringAsFixed(-1), (e) => e is RangeError);
Expect.throws(() => v.toStringAsFixed(21), (e) => e is RangeError);
Expect.throws(() => v.toStringAsFixed(null), (e) => e is ArgumentError);
Expect.throwsRangeError(() => v.toStringAsFixed(-1));
Expect.throwsRangeError(() => v.toStringAsFixed(21));
Expect.throwsArgumentError(() => v.toStringAsFixed(null));
v.toStringAsFixed(1.5);//# 01: compile-time error
v.toStringAsFixed("string");//# 02: compile-time error
v.toStringAsFixed("3");//# 03: compile-time error

View file

@ -7,9 +7,9 @@ import "package:expect/expect.dart";
main() {
var v = 0.0;
Expect.throws(() => v.toStringAsPrecision(0), (e) => e is RangeError);
Expect.throws(() => v.toStringAsPrecision(22), (e) => e is RangeError);
Expect.throws(() => v.toStringAsPrecision(null), (e) => e is ArgumentError);
Expect.throwsRangeError(() => v.toStringAsPrecision(0));
Expect.throwsRangeError(() => v.toStringAsPrecision(22));
Expect.throwsArgumentError(() => v.toStringAsPrecision(null));
v.toStringAsPrecision(1.5); //# 01: compile-time error
v.toStringAsPrecision("string"); //# 02: compile-time error
v.toStringAsPrecision("3"); //# 03: compile-time error

View file

@ -18,5 +18,5 @@ enum Enum1 {
main() {
Expect.equals('Enum1._A,Enum1._B', Enum1.values.join(','));
Expect.equals('Enum2._A,Enum2._B', Enum2.values.join(',')); //# 01: ok
Expect.throws(() => Enum2._A, (e) => e is NoSuchMethodError); //# 02: compile-time error
Expect.throwsNoSuchMethodError(() => Enum2._A); //# 02: compile-time error
}

View file

@ -22,7 +22,7 @@ void expectIs<T>(T t, bool Function(Object) test) {
Expect.isFalse(obj is _IsNot, '$obj is _IsNot');
// test cast
t = obj as T;
Expect.throws(() => obj as _IsNot, (e) => e is CastError, '$obj as _IsNot');
Expect.throwsCastError(() => obj as _IsNot, '$obj as _IsNot');
}
main() {

View file

@ -48,16 +48,16 @@ main() {
Expect.equals((D).runtimeType, (D).runtimeType.runtimeType);
// Test that operator calls on class literals go to Type.
Expect.throws(() => C = 1, (e) => e is NoSuchMethodError); //# 03: compile-time error
Expect.throws(() => C++, (e) => e is NoSuchMethodError); //# 04: compile-time error
Expect.throws(() => C + 1, (e) => e is NoSuchMethodError); //# 05: compile-time error
Expect.throws(() => C[2], (e) => e is NoSuchMethodError); //# 06: compile-time error
Expect.throws(() => C[2] = 'hest', (e) => e is NoSuchMethodError); //# 07: compile-time error
Expect.throws(() => dynamic = 1, (e) => e is NoSuchMethodError); //# 08: compile-time error
Expect.throws(() => dynamic++, (e) => e is NoSuchMethodError); //# 09: compile-time error
Expect.throws(() => dynamic + 1, (e) => e is NoSuchMethodError); //# 10: compile-time error
Expect.throws(() => dynamic[2], (e) => e is NoSuchMethodError); //# 11: compile-time error
Expect.throws(() => dynamic[2] = 'hest', (e) => e is NoSuchMethodError); //# 12: compile-time error
Expect.throwsNoSuchMethodError(() => C = 1); //# 03: compile-time error
Expect.throwsNoSuchMethodError(() => C++); //# 04: compile-time error
Expect.throwsNoSuchMethodError(() => C + 1); //# 05: compile-time error
Expect.throwsNoSuchMethodError(() => C[2]); //# 06: compile-time error
Expect.throwsNoSuchMethodError(() => C[2] = 'hest'); //# 07: compile-time error
Expect.throwsNoSuchMethodError(() => dynamic = 1); //# 08: compile-time error
Expect.throwsNoSuchMethodError(() => dynamic++); //# 09: compile-time error
Expect.throwsNoSuchMethodError(() => dynamic + 1); //# 10: compile-time error
Expect.throwsNoSuchMethodError(() => dynamic[2]); //# 11: compile-time error
Expect.throwsNoSuchMethodError(() => dynamic[2] = 'hest'); //# 12: compile-time error
Expect.equals((dynamic).toString(), 'dynamic');
}

View file

@ -14,7 +14,7 @@ void bar(int i) {}
void main() {
Expect.isNotNull(bar as Foo);
Expect.throws(() => bar as Foo<bool>, (e) => true);
Expect.throws(() => bar as Foo<bool>);
Expect.isNotNull(bar as Foo<int>);
Expect.isNotNull(bar as Bar);
}

View file

@ -10,5 +10,5 @@ void foo(List<Int2Int> list) {
void main() {
var l = <Function>[];
Expect.throws(() => foo(l), (e) => e is TypeError);
Expect.throwsTypeError(() => foo(l));
}

View file

@ -23,10 +23,6 @@ main() {
new C2();
// type error: 0 is not a string
Expect.throws(() {
new C1<String>();
}, (e) => e is TypeError);
Expect.throws(() {
new C3();
}, (e) => e is TypeError);
Expect.throwsTypeError(() => new C1<String>());
Expect.throws(() => new C3());
}

View file

@ -66,14 +66,6 @@ void check(expectedValue, f(), expectedOperations) {
h.operations = [];
}
void checkThrows(expectedException, f(), expectedOperations) {
Expect.throws(f, expectedException);
Expect.listEquals(expectedOperations, h.operations);
h.operations = [];
}
noMethod(e) => e is NoSuchMethodError;
class C {
final String s;

View file

@ -31,8 +31,6 @@ class C extends A {
B nullB() => null;
C nullC() => null;
noMethod(e) => e is NoSuchMethodError;
main() {
Expect.equals(1, 1 ?? 2);
Expect.equals(1, 1 ?? null);

View file

@ -12,5 +12,5 @@ var list;
main() {
if (new DateTime.now().millisecondsSinceEpoch == 0) list = new List(4);
Expect.throws(() => print(list[5]), (e) => e is NoSuchMethodError);
Expect.throwsNoSuchMethodError(() => print(list[5]));
}

View file

@ -21,6 +21,5 @@ main() {
// Call [A.full] with an int to have the inferrer think [field] is
// always an int.
Expect.equals(84, new A.full(42).field + 42);
Expect.throws(
() => new B.full(null).field + 42, (e) => e is NoSuchMethodError);
Expect.throwsNoSuchMethodError(() => new B.full(null).field + 42,);
}

View file

@ -184,14 +184,14 @@ testInvocationMirrors() {
// Closurizing a method means that calling it badly will not hit the
// original receivers noSuchMethod, only the one inherited from Object
// by the closure object.
Expect.throws(() {
Expect.throwsNoSuchMethodError(() {
var x = n.flif;
x(37, 42);
}, (e) => e is NoSuchMethodError);
Expect.throws(() {
});
Expect.throwsNoSuchMethodError(() {
var x = c.call;
x(37, 42);
}, (e) => e is NoSuchMethodError);
});
}
class M extends N {
@ -284,35 +284,31 @@ class M extends N {
// Closurizing a method means that calling it badly will not hit the
// original receivers noSuchMethod, only the one inherited from Object
// by the closure object.
Expect.throws(() {
Expect.throwsNoSuchMethodError(() {
var x = self.flif;
x(37, 42);
}, (e) => e is NoSuchMethodError);
});
}
}
// Test the NoSuchMethodError thrown by different incorrect calls.
testNoSuchMethodErrors() {
test(block()) {
Expect.throws(block, (e) => e is NoSuchMethodError);
}
dynamic n = new N();
dynamic o = new Object();
test(() => o.bar);
test(() => o.bar = 42);
test(() => o.bar());
test(() => o + 2);
test(() => -o);
test(() => o[0]);
test(() => o[0] = 42);
test(() => o());
test(() => o.toString = 42);
test(() => o.toString(42));
test(() => o.toString(x: 37));
test(() => o.hashCode = 42);
test(() => o.hashCode()); // Thrown by int.noSuchMethod.
test(() => (n.flif)()); // Extracted method has no noSuchMethod.
Expect.throwsNoSuchMethodError(() => o.bar);
Expect.throwsNoSuchMethodError(() => o.bar = 42);
Expect.throwsNoSuchMethodError(() => o.bar());
Expect.throwsNoSuchMethodError(() => o + 2);
Expect.throwsNoSuchMethodError(() => -o);
Expect.throwsNoSuchMethodError(() => o[0]);
Expect.throwsNoSuchMethodError(() => o[0] = 42);
Expect.throwsNoSuchMethodError(() => o());
Expect.throwsNoSuchMethodError(() => o.toString = 42);
Expect.throwsNoSuchMethodError(() => o.toString(42));
Expect.throwsNoSuchMethodError(() => o.toString(x: 37));
Expect.throwsNoSuchMethodError(() => o.hashCode = 42);
Expect.throwsNoSuchMethodError(() => o.hashCode()); // Thrown by int.noSuchMethod.
Expect.throwsNoSuchMethodError(() => (n.flif)()); // Extracted method has no noSuchMethod.
}
main() {

View file

@ -11,7 +11,7 @@ class A {
main() {
Expect.isTrue(foo(double.NAN));
Expect.isFalse(foo(new A()));
Expect.throws(() => foo('bar'), (e) => e is NoSuchMethodError);
Expect.throwsNoSuchMethodError(() => foo('bar'));
}
foo(a) => a.isNaN;

View file

@ -15,10 +15,9 @@ class A<T> {
main() {
Expect.equals(42, new A<int>(42).asTypeVariable());
Expect.throws(
() => new A<String>(42).asTypeVariable(), (e) => e is CastError);
Expect.throwsCastError(() => new A<String>(42).asTypeVariable());
var b = new B<int>();
Expect.equals(b, new A<int>(b).asBOfT());
Expect.throws(() => new A<String>(b).asBOfT(), (e) => e is CastError);
Expect.throwsCastError(() => new A<String>(b).asBOfT());
}

View file

@ -16,6 +16,6 @@ main() {
]) {
var c;
if (b[0]) c = new C();
Expect.throws(() => print(c.foo(b[1])), (e) => e is NoSuchMethodError);
Expect.throwsNoSuchMethodError(() => print(c.foo(b[1])));
}
}

View file

@ -19,5 +19,5 @@ class C extends A {
main() {
C c = new C();
Expect.throws(() => c.test(), (e) => e is NoSuchMethodError); //# 01: continued
Expect.throwsNoSuchMethodError(() => c.test()); //# 01: continued
}

View file

@ -19,5 +19,5 @@ class C extends Object with A {
main() {
C c = new C();
Expect.throws(() => c.test(), (e) => e is NoSuchMethodError); //# 01: continued
Expect.throwsNoSuchMethodError(() => c.test()); //# 01: continued
}

Some files were not shown because too many files have changed in this diff Show more