Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Unified Diff: tests/language/list_test.dart

Issue 10890009: Rewrite language/list_test to use Expect.throws, and to allow a TypeError exception in checked mode. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/language/list_test.dart
diff --git a/tests/language/list_test.dart b/tests/language/list_test.dart
index 5021a00b855cda0ec8be7de82cf3477a83d082fe..628e765224078d376e4a0307fee458b761d12be1 100644
--- a/tests/language/list_test.dart
+++ b/tests/language/list_test.dart
@@ -48,41 +48,21 @@ class ListTest {
a.forEach(f(element) { Expect.equals(null, element); });
a[1] = 1;
Expect.equals(1, a[1]);
- bool exception_caught = false;
- try {
- var x = a[len];
- } catch (IndexOutOfRangeException e) {
- exception_caught = true;
- }
- Expect.equals(true, exception_caught);
+ Expect.throws(() => a[len], (e) => e is IndexOutOfRangeException);
- exception_caught = false;
- try {
+ Expect.throws(() {
List a = new List(4);
a.setRange(1, 1, a, null);
- } catch (Exception e) {
- exception_caught = true;
- }
- Expect.equals(true, exception_caught);
+ }, (e) => true);
ngeoffray 2012/08/28 14:17:07 Do you need to add this closure?
Bill Hesse 2012/08/28 14:31:58 No, I don't. Thanks for pointing that out.
- exception_caught = false;
- try {
+ Expect.throws(() {
List a = new List(4);
a.setRange(10, 1, a, 1);
- } catch (IndexOutOfRangeException e) {
- exception_caught = true;
- }
- Expect.equals(true, exception_caught);
+ }, (e) => e is IndexOutOfRangeException);
- exception_caught = false;
- try {
- List a = new List(4);
- List b = new List(4);
- b.setRange(0, 4, a, 0);
- } catch (var e) {
- exception_caught = true;
- }
- Expect.equals(false, exception_caught);
+ a = new List(4);
+ List b = new List(4);
+ b.setRange(0, 4, a, 0);
List<int> unsorted = [4, 3, 9, 12, -4, 9];
int compare(a, b) {
@@ -111,42 +91,18 @@ class ListTest {
TestIterator();
int element = unsorted[2];
Expect.equals(9, element);
- bool exceptionCaught = false;
- try {
- element = unsorted[2.1];
- } catch (IllegalArgumentException e) {
- exceptionCaught = true;
- } catch (TypeError e) {
- // For type checked mode.
- exceptionCaught = true;
- }
- Expect.equals(true, exceptionCaught);
- exceptionCaught = false;
- try {
- var a = new List(-1);
- } catch (Exception e) { // Must agree which exception to throw.
- exceptionCaught = true;
- }
- Expect.equals(true, exceptionCaught);
+ Expect.throws(() => unsorted[2.1],
+ (e) => e is IllegalArgumentException || e is TypeError);
- exceptionCaught = false;
- try {
- var a = new List(99999999999999999999999); // Non-Smi.
- } catch (Exception e) { // Must agree which exception to throw.
- exceptionCaught = true;
- }
- Expect.equals(true, exceptionCaught);
+ Expect.throws(() => new List(-1), (e) => true);
+ Expect.throws(() => new List(99999999999999999999999), (e) => true);
ngeoffray 2012/08/28 14:17:07 ditto
- exceptionCaught = false;
List list = new List();
- try {
- list.removeLast();
- } catch (IndexOutOfRangeException e) {
- exceptionCaught = true;
- }
+ // We cannot write just 'list.removeLast' due to issue 3769.
+ Expect.throws(() => list.removeLast(),
+ (e) => e is IndexOutOfRangeException);
Expect.equals(0, list.length);
- Expect.equals(true, exceptionCaught);
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698