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" | 14 const String whiteSpace = "$oneByteWhiteSpace\u1680" |
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 |
21 for (int i = 0; i < whiteSpace.length; i++) { | 21 for (int i = 0; i < whiteSpace.length; i++) { |
22 var ws = whiteSpace[i]; | 22 var ws = whiteSpace[i]; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 Expect.equals(-result, int.parse("-$zeros$radixString", radix: radix), m); | 54 Expect.equals(-result, int.parse("-$zeros$radixString", radix: radix), m); |
55 } | 55 } |
56 | 56 |
57 for (int r = 2; r <= 36; r++) { | 57 for (int r = 2; r <= 36; r++) { |
58 for (int i = 0; i <= r * r; i++) { | 58 for (int i = 0; i <= r * r; i++) { |
59 String radixString = i.toRadixString(r); | 59 String radixString = i.toRadixString(r); |
60 testParse(i, radixString, r); | 60 testParse(i, radixString, r); |
61 } | 61 } |
62 } | 62 } |
63 | 63 |
64 for (int i = 2; i <= 36; i++) { /// 02: ok | 64 for (int i = 2; i <= 36; i++) { // /// 02: ok |
65 // Test with bignums. /// 02: continued | 65 // Test with bignums. // /// 02: continued |
66 var digit = digits[i - 1]; /// 02: continued | 66 var digit = digits[i - 1]; // /// 02: continued |
67 testParse(pow(i, 64) - 1, digit * 64, i); /// 02: continued | 67 testParse(pow(i, 64) - 1, digit * 64, i); // /// 02: continued |
68 testParse(0, zeros, i); /// 02: continued | 68 testParse(0, zeros, i); // /// 02: continued |
69 } /// 02: continued | 69 } // /// 02: continued |
70 | 70 |
71 // Allow both upper- and lower-case letters. | 71 // Allow both upper- and lower-case letters. |
72 Expect.equals(0xABCD, int.parse("ABCD", radix: 16)); | 72 Expect.equals(0xABCD, int.parse("ABCD", radix: 16)); |
73 Expect.equals(0xABCD, int.parse("abcd", radix: 16)); | 73 Expect.equals(0xABCD, int.parse("abcd", radix: 16)); |
74 Expect.equals(15628859, int.parse("09azAZ", radix: 36)); | 74 Expect.equals(15628859, int.parse("09azAZ", radix: 36)); |
75 // Big number. | 75 // Big number. |
76 Expect.equals(0x12345678123456781234567812345678, /// 02: continued | 76 Expect.equals(0x12345678123456781234567812345678, // /// 02: continued |
77 int.parse("0x1234567812345678" /// 02: continued | 77 int.parse("0x1234567812345678" // /// 02: continued |
78 "1234567812345678")); /// 02: continued | 78 "1234567812345678")); // /// 02: continued |
79 // Allow whitespace before and after the number. | 79 // Allow whitespace before and after the number. |
80 Expect.equals(1, int.parse(" 1", radix: 2)); | 80 Expect.equals(1, int.parse(" 1", radix: 2)); |
81 Expect.equals(1, int.parse("1 ", radix: 2)); | 81 Expect.equals(1, int.parse("1 ", radix: 2)); |
82 Expect.equals(1, int.parse(" 1 ", radix: 2)); | 82 Expect.equals(1, int.parse(" 1 ", radix: 2)); |
83 Expect.equals(1, int.parse("\n1", radix: 2)); | 83 Expect.equals(1, int.parse("\n1", radix: 2)); |
84 Expect.equals(1, int.parse("1\n", radix: 2)); | 84 Expect.equals(1, int.parse("1\n", radix: 2)); |
85 Expect.equals(1, int.parse("\n1\n", radix: 2)); | 85 Expect.equals(1, int.parse("\n1\n", radix: 2)); |
86 Expect.equals(1, int.parse("+1", radix: 2)); | 86 Expect.equals(1, int.parse("+1", radix: 2)); |
87 | 87 |
88 void testFails(String source, int radix) { | 88 void testFails(String source, int radix) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 // See also int_parse_radix_bad_handler_test.dart | 138 // See also int_parse_radix_bad_handler_test.dart |
139 } | 139 } |
140 | 140 |
141 bool isFail(e) => e == "FAIL"; | 141 bool isFail(e) => e == "FAIL"; |
OLD | NEW |