| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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 import "dart:math" show pow; | 6 import "dart:math" show pow; |
| 7 | 7 |
| 8 void main() { | 8 void main() { |
| 9 bool checkedMode = false; | 9 bool checkedMode = false; |
| 10 assert(checkedMode = true); | 10 assert((checkedMode = true)); |
| 11 const String oneByteWhiteSpace = "\x09\x0a\x0b\x0c\x0d\x20" | 11 const String oneByteWhiteSpace = "\x09\x0a\x0b\x0c\x0d\x20" |
| 12 "\x85" /// 01: ok | 12 "\x85" /// 01: ok |
| 13 "\xa0"; | 13 "\xa0"; |
| 14 const String whiteSpace = "$oneByteWhiteSpace\u1680\u180e" | 14 const String whiteSpace = "$oneByteWhiteSpace\u1680\u180e" |
| 15 "\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a" | 15 "\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a" |
| 16 "\u2028\u2029\u202f\u205f\u3000\ufeff"; | 16 "\u2028\u2029\u202f\u205f\u3000\ufeff"; |
| 17 | 17 |
| 18 var digits = "0123456789abcdefghijklmnopqrstuvwxyz"; | 18 var digits = "0123456789abcdefghijklmnopqrstuvwxyz"; |
| 19 var zeros = "0" * 64; | 19 var zeros = "0" * 64; |
| 20 | 20 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 109 |
| 110 testBadTypes(var source, var radix) { | 110 testBadTypes(var source, var radix) { |
| 111 if (!checkedMode) { | 111 if (!checkedMode) { |
| 112 // No promises on what error is thrown if the type doesn't match. | 112 // No promises on what error is thrown if the type doesn't match. |
| 113 // Likely either ArgumentError or NoSuchMethodError. | 113 // Likely either ArgumentError or NoSuchMethodError. |
| 114 Expect.throws(() => int.parse(source, radix: radix, onError: (s) => 0)); | 114 Expect.throws(() => int.parse(source, radix: radix, onError: (s) => 0)); |
| 115 return; | 115 return; |
| 116 } | 116 } |
| 117 // In checked mode, it's always a TypeError. | 117 // In checked mode, it's always a TypeError. |
| 118 Expect.throws(() => int.parse(source, radix: radix, onError: (s) => 0), | 118 Expect.throws(() => int.parse(source, radix: radix, onError: (s) => 0), |
| 119 (e) => e is TypeError); | 119 (e) => e is TypeError || e is CastError); |
| 120 } | 120 } |
| 121 | 121 |
| 122 testBadTypes(9, 10); | 122 testBadTypes(9, 10); |
| 123 testBadTypes(true, 10); | 123 testBadTypes(true, 10); |
| 124 testBadTypes("0", true); | 124 testBadTypes("0", true); |
| 125 testBadTypes("0", "10"); | 125 testBadTypes("0", "10"); |
| 126 | 126 |
| 127 testBadArguments(String source, int radix) { | 127 testBadArguments(String source, int radix) { |
| 128 // If the types match, it should be an ArgumentError of some sort. | 128 // If the types match, it should be an ArgumentError of some sort. |
| 129 Expect.throws(() => int.parse(source, radix: radix, onError: (s) => 0), | 129 Expect.throws(() => int.parse(source, radix: radix, onError: (s) => 0), |
| 130 (e) => e is ArgumentError); | 130 (e) => e is ArgumentError); |
| 131 } | 131 } |
| 132 | 132 |
| 133 testBadArguments("0", -1); | 133 testBadArguments("0", -1); |
| 134 testBadArguments("0", 0); | 134 testBadArguments("0", 0); |
| 135 testBadArguments("0", 1); | 135 testBadArguments("0", 1); |
| 136 testBadArguments("0", 37); | 136 testBadArguments("0", 37); |
| 137 | 137 |
| 138 // If handleError isn't an unary function, and it's called, it also throws | 138 // See also int_parse_radix_bad_handler_test.dart |
| 139 // (either TypeError in checked mode, or some failure in unchecked mode). | |
| 140 Expect.throws(() => int.parse("9", radix: 8, onError: "not a function")); | |
| 141 Expect.throws(() => int.parse("9", radix: 8, onError: () => 42)); | |
| 142 Expect.throws(() => int.parse("9", radix: 8, onError: (v1, v2) => 42)); | |
| 143 } | 139 } |
| 144 | 140 |
| 145 bool isFail(e) => e == "FAIL"; | 141 bool isFail(e) => e == "FAIL"; |
| OLD | NEW |