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 const String oneByteWhiteSpace = "\x09\x0a\x0b\x0c\x0d\x20" | 9 const String oneByteWhiteSpace = "\x09\x0a\x0b\x0c\x0d\x20" |
10 "\x85" // //# 01: ok | 10 "\x85" //# 01: ok |
11 "\xa0"; | 11 "\xa0"; |
12 const String whiteSpace = "$oneByteWhiteSpace\u1680" | 12 const String whiteSpace = "$oneByteWhiteSpace\u1680" |
13 "\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a" | 13 "\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a" |
14 "\u2028\u2029\u202f\u205f\u3000\ufeff"; | 14 "\u2028\u2029\u202f\u205f\u3000\ufeff"; |
15 | 15 |
16 var digits = "0123456789abcdefghijklmnopqrstuvwxyz"; | 16 var digits = "0123456789abcdefghijklmnopqrstuvwxyz"; |
17 var zeros = "0" * 64; | 17 var zeros = "0" * 64; |
18 | 18 |
19 for (int i = 0; i < whiteSpace.length; i++) { | 19 for (int i = 0; i < whiteSpace.length; i++) { |
20 var ws = whiteSpace[i]; | 20 var ws = whiteSpace[i]; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 testFails("+ 1", 2); // No space between sign and digits. | 107 testFails("+ 1", 2); // No space between sign and digits. |
108 testFails("- 1", 2); // No space between sign and digits. | 108 testFails("- 1", 2); // No space between sign and digits. |
109 testFails("0x", null); | 109 testFails("0x", null); |
110 for (int i = 2; i <= 33; i++) { | 110 for (int i = 2; i <= 33; i++) { |
111 // No 0x specially allowed. | 111 // No 0x specially allowed. |
112 // At radix 34 and above, "x" is a valid digit. | 112 // At radix 34 and above, "x" is a valid digit. |
113 testFails("0x10", i); | 113 testFails("0x10", i); |
114 } | 114 } |
115 | 115 |
116 testBadTypes(var source, var radix) { | 116 testBadTypes(var source, var radix) { |
117 if (!typeAssertionsEnabled) { | 117 Expect.throws(() => int.parse(source, radix: radix, onError: (s) => 0), //# badTypes: ok |
bkonyi
2017/08/08 18:03:13
Any reason for these annotations? If it does actua
jcollins
2017/08/08 20:01:58
It throws something, but (I think) not the right e
| |
118 // No promises on what error is thrown if the type doesn't match. | 118 (e) => e is TypeError); //# badTypes: ok |
119 // Likely either ArgumentError or NoSuchMethodError. | |
120 Expect.throws(() => int.parse(source, radix: radix, onError: (s) => 0)); | |
121 return; | |
122 } | |
123 // With type assertions enabled we can be more precise. | |
124 Expect.throws(() => int.parse(source, radix: radix, onError: (s) => 0), | |
125 (e) => e is TypeError || e is CastError); | |
126 } | 119 } |
127 | 120 |
128 testBadTypes(9, 10); | 121 testBadTypes(9, 10); |
129 testBadTypes(true, 10); | 122 testBadTypes(true, 10); |
130 testBadTypes("0", true); | 123 testBadTypes("0", true); |
131 testBadTypes("0", "10"); | 124 testBadTypes("0", "10"); |
132 | 125 |
133 testBadArguments(String source, int radix) { | 126 testBadArguments(String source, int radix) { |
134 // If the types match, it should be an ArgumentError of some sort. | 127 // If the types match, it should be an ArgumentError of some sort. |
135 Expect.throws(() => int.parse(source, radix: radix, onError: (s) => 0), | 128 Expect.throws(() => int.parse(source, radix: radix, onError: (s) => 0), |
136 (e) => e is ArgumentError); | 129 (e) => e is ArgumentError); |
137 } | 130 } |
138 | 131 |
139 testBadArguments("0", -1); | 132 testBadArguments("0", -1); |
140 testBadArguments("0", 0); | 133 testBadArguments("0", 0); |
141 testBadArguments("0", 1); | 134 testBadArguments("0", 1); |
142 testBadArguments("0", 37); | 135 testBadArguments("0", 37); |
143 | 136 |
144 // See also int_parse_radix_bad_handler_test.dart | 137 // See also int_parse_radix_bad_handler_test.dart |
145 } | 138 } |
146 | 139 |
147 bool isFail(e) => e == "FAIL"; | 140 bool isFail(e) => e == "FAIL"; |
OLD | NEW |