OLD | NEW |
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 /** | 5 /** |
6 * A test of simple runtime behavior on numbers, strings and lists with | 6 * A test of simple runtime behavior on numbers, strings and lists with |
7 * a focus on both correct behavior and runtime errors. | 7 * a focus on both correct behavior and runtime errors. |
8 * | 8 * |
9 * This file is written to use minimal type declarations to match a | 9 * This file is written to use minimal type declarations to match a |
10 * typical dynamic language coding style. | 10 * typical dynamic language coding style. |
(...skipping 29 matching lines...) Expand all Loading... |
40 | 40 |
41 static assertListContains(List<Comparable> a, List<Comparable> b) { | 41 static assertListContains(List<Comparable> a, List<Comparable> b) { |
42 a.sort((x, y) => x.compareTo(y)); | 42 a.sort((x, y) => x.compareTo(y)); |
43 b.sort((x, y) => x.compareTo(y)); | 43 b.sort((x, y) => x.compareTo(y)); |
44 assertListEquals(a, b); | 44 assertListEquals(a, b); |
45 } | 45 } |
46 | 46 |
47 static assertTypeError(void f()) { | 47 static assertTypeError(void f()) { |
48 try { | 48 try { |
49 f(); | 49 f(); |
50 } catch (var exception) { | 50 } catch (exception) { |
51 Expect.equals(true, (exception is TypeError) || | 51 Expect.equals(true, (exception is TypeError) || |
52 (exception is NoSuchMethodException) || | 52 (exception is NoSuchMethodException) || |
53 (exception is NullPointerException) || | 53 (exception is NullPointerException) || |
54 (exception is IllegalArgumentException)); | 54 (exception is IllegalArgumentException)); |
55 return; | 55 return; |
56 } | 56 } |
57 Expect.equals(true, false); | 57 Expect.equals(true, false); |
58 } | 58 } |
59 | 59 |
60 static testBooleanOperators() { | 60 static testBooleanOperators() { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 var y = 9; | 143 var y = 9; |
144 assertEquals(y.isEven(), false); | 144 assertEquals(y.isEven(), false); |
145 assertEquals(y.isOdd(), true); | 145 assertEquals(y.isOdd(), true); |
146 assertEquals(y.toRadixString(2), '1001'); | 146 assertEquals(y.toRadixString(2), '1001'); |
147 assertEquals(y.toRadixString(3), '100'); | 147 assertEquals(y.toRadixString(3), '100'); |
148 assertEquals(y.toRadixString(16), '9'); | 148 assertEquals(y.toRadixString(16), '9'); |
149 assertEquals((0).toRadixString(16), '0'); | 149 assertEquals((0).toRadixString(16), '0'); |
150 try { | 150 try { |
151 y.toRadixString(0); | 151 y.toRadixString(0); |
152 Expect.fail("Illegal radix 0 accepted."); | 152 Expect.fail("Illegal radix 0 accepted."); |
153 } catch (var e) { } | 153 } catch (e) { } |
154 try { | 154 try { |
155 y.toRadixString(-1); | 155 y.toRadixString(-1); |
156 Expect.fail("Illegal radix -1 accepted."); | 156 Expect.fail("Illegal radix -1 accepted."); |
157 } catch (var e) { } | 157 } catch (e) { } |
158 } | 158 } |
159 | 159 |
160 static testStringOperators() { | 160 static testStringOperators() { |
161 var s = "abcdef"; | 161 var s = "abcdef"; |
162 assertEquals(s, "abcdef"); | 162 assertEquals(s, "abcdef"); |
163 assertEquals(s.charCodeAt(0), 97); | 163 assertEquals(s.charCodeAt(0), 97); |
164 assertEquals(s[0], 'a'); | 164 assertEquals(s[0], 'a'); |
165 assertEquals(s.length, 6); | 165 assertEquals(s.length, 6); |
166 assertTypeError(() { s[null]; }); | 166 assertTypeError(() { s[null]; }); |
167 assertTypeError(() { s['hello']; }); | 167 assertTypeError(() { s['hello']; }); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 '${true}'.toString(); | 281 '${true}'.toString(); |
282 '${false}'.toString(); | 282 '${false}'.toString(); |
283 ''.toString(); | 283 ''.toString(); |
284 ''.endsWith(''); | 284 ''.endsWith(''); |
285 } | 285 } |
286 } | 286 } |
287 | 287 |
288 main() { | 288 main() { |
289 CoreRuntimeTypesTest.testMain(); | 289 CoreRuntimeTypesTest.testMain(); |
290 } | 290 } |
OLD | NEW |