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

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

Issue 988523002: Fix int.parse bug (dart2js version) (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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 | « tests/corelib/double_parse_test.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) 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);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 Expect.equals(1, int.parse("+1", radix: 2)); 87 Expect.equals(1, int.parse("+1", radix: 2));
88 88
89 void testFails(String source, int radix) { 89 void testFails(String source, int radix) {
90 Expect.throws(() { throw int.parse(source, radix: radix, 90 Expect.throws(() { throw int.parse(source, radix: radix,
91 onError: (s) { throw "FAIL"; }); }, 91 onError: (s) { throw "FAIL"; }); },
92 (e) => e == "FAIL", 92 (e) => e == "FAIL",
93 "$source/$radix"); 93 "$source/$radix");
94 Expect.equals(-999, int.parse(source, radix: radix, onError: (s) => -999)); 94 Expect.equals(-999, int.parse(source, radix: radix, onError: (s) => -999));
95 } 95 }
96 for (int i = 2; i < 36; i++) { 96 for (int i = 2; i < 36; i++) {
97 testFails(i.toRadixString(36), i); 97 testFails(i.toRadixString(36).toLowerCase(), i);
98 testFails(i.toRadixString(36).toUpperCase(), i);
98 } 99 }
99 testFails("", 2); 100 testFails("", 2);
100 testFails("+ 1", 2); // No space between sign and digits. 101 testFails("+ 1", 2); // No space between sign and digits.
101 testFails("- 1", 2); // No space between sign and digits. 102 testFails("- 1", 2); // No space between sign and digits.
102 testFails("0x", null); 103 testFails("0x", null);
103 for (int i = 2; i <= 33; i++) { 104 for (int i = 2; i <= 33; i++) {
104 // No 0x specially allowed. 105 // No 0x specially allowed.
105 // At radix 34 and above, "x" is a valid digit. 106 // At radix 34 and above, "x" is a valid digit.
106 testFails("0x10", i); 107 testFails("0x10", i);
107 } 108 }
(...skipping 25 matching lines...) Expand all
133 testBadArguments("0", 0); 134 testBadArguments("0", 0);
134 testBadArguments("0", 1); 135 testBadArguments("0", 1);
135 testBadArguments("0", 37); 136 testBadArguments("0", 37);
136 137
137 // If handleError isn't an unary function, and it's called, it also throws 138 // If handleError isn't an unary function, and it's called, it also throws
138 // (either TypeError in checked mode, or some failure in unchecked mode). 139 // (either TypeError in checked mode, or some failure in unchecked mode).
139 Expect.throws(() => int.parse("9", radix: 8, onError: "not a function")); 140 Expect.throws(() => int.parse("9", radix: 8, onError: "not a function"));
140 Expect.throws(() => int.parse("9", radix: 8, onError: () => 42)); 141 Expect.throws(() => int.parse("9", radix: 8, onError: () => 42));
141 Expect.throws(() => int.parse("9", radix: 8, onError: (v1, v2) => 42)); 142 Expect.throws(() => int.parse("9", radix: 8, onError: (v1, v2) => 42));
142 } 143 }
OLDNEW
« no previous file with comments | « tests/corelib/double_parse_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698