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

Side by Side Diff: tests/corelib/range_error_test.dart

Issue 879893002: Make RangeError.toString use the name field that it inherits from ArgumentError. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add tests. Created 5 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/core/errors.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import "package:expect/expect.dart"; 5 import "package:expect/expect.dart";
6 6
7 // Dart test for testing out of range exceptions on arrays. 7 // Dart test for testing out of range exceptions on arrays, and the content
8 // of range_error toString().
8 9
9 class RangeErrorTest { 10 void main() {
10 static testRead() { 11 testRead();
11 testListRead([], 0); 12 testWrite();
12 testListRead([], -1); 13 testToString();
13 testListRead([], 1); 14 }
14 15
15 var list = [1]; 16 void testRead() {
16 testListRead(list, -1); 17 testListRead([], 0);
17 testListRead(list, 1); 18 testListRead([], -1);
19 testListRead([], 1);
18 20
19 list = new List(1); 21 var list = [1];
20 testListRead(list, -1); 22 testListRead(list, -1);
21 testListRead(list, 1); 23 testListRead(list, 1);
22 24
23 list = new List(); 25 list = new List(1);
24 testListRead(list, -1); 26 testListRead(list, -1);
25 testListRead(list, 0); 27 testListRead(list, 1);
26 testListRead(list, 1);
27 }
28 28
29 static testWrite() { 29 list = new List();
30 testListWrite([], 0); 30 testListRead(list, -1);
31 testListWrite([], -1); 31 testListRead(list, 0);
32 testListWrite([], 1); 32 testListRead(list, 1);
33 }
33 34
34 var list = [1]; 35 void testWrite() {
35 testListWrite(list, -1); 36 testListWrite([], 0);
36 testListWrite(list, 1); 37 testListWrite([], -1);
38 testListWrite([], 1);
37 39
38 list = new List(1); 40 var list = [1];
39 testListWrite(list, -1); 41 testListWrite(list, -1);
40 testListWrite(list, 1); 42 testListWrite(list, 1);
41 43
42 list = new List(); 44 list = new List(1);
43 testListWrite(list, -1); 45 testListWrite(list, -1);
44 testListWrite(list, 0); 46 testListWrite(list, 1);
45 testListWrite(list, 1);
46 }
47 47
48 static testMain() { 48 list = new List();
49 testRead(); 49 testListWrite(list, -1);
50 testWrite(); 50 testListWrite(list, 0);
51 } 51 testListWrite(list, 1);
52 }
52 53
53 static testListRead(list, index) { 54 void testToString() {
54 var exception = null; 55 for (var name in [null, "THENAME"]) {
55 try { 56 for (var message in [null, "THEMESSAGE"]) {
56 var e = list[index]; 57 var value = 37;
57 } on RangeError catch (e) { 58 for (var re in [
58 exception = e; 59 new ArgumentError.value(value, name, message),
60 new RangeError.value(value, name, message),
61 new RangeError.index(value, [], name, message),
62 new RangeError.range(value, 0, 24, name, message)
63 ]) {
64 var str = re.toString();
65 if (name != null) Expect.isTrue(str.contains(name), "$name in $str");
66 if (message != null) Expect.isTrue(str.contains(message),
67 "$message in $str");
68 Expect.isTrue(str.contains("$value"), "$value in $str");
69 // No empty ':' separated parts - in that case the colon is omitted too.
70 Expect.isFalse(str.contains(new RegExp(":\s*:")));
71 }
59 } 72 }
60 Expect.equals(true, exception != null);
61 }
62
63 static testListWrite(list, index) {
64 var exception = null;
65 try {
66 list[index] = null;
67 } on RangeError catch (e) {
68 exception = e;
69 }
70 Expect.equals(true, exception != null);
71 } 73 }
72 } 74 }
73 75
74 main() { 76 void testListRead(list, index) {
75 RangeErrorTest.testMain(); 77 var exception = null;
78 try {
79 var e = list[index];
80 } on RangeError catch (e) {
81 exception = e;
82 }
83 Expect.equals(true, exception != null);
76 } 84 }
85
86 void testListWrite(list, index) {
87 var exception = null;
88 try {
89 list[index] = null;
90 } on RangeError catch (e) {
91 exception = e;
92 }
93 Expect.equals(true, exception != null);
94 }
OLDNEW
« no previous file with comments | « sdk/lib/core/errors.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698