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

Side by Side Diff: test/codegen/corelib/int_parse_radix_test.dart

Issue 1950133008: Update number parsing. (Closed) Base URL: https://github.com/dart-lang/dev_compiler@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « test/browser/language_tests.js ('k') | tool/input_sdk/lib/core/list.dart » ('j') | 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));
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
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";
OLDNEW
« no previous file with comments | « test/browser/language_tests.js ('k') | tool/input_sdk/lib/core/list.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698