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

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

Issue 2879153005: Add support to dart2js for option --enable-asserts. (Closed)
Patch Set: Added !$checked to section predicate in co19 status file Created 3 years, 5 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 | « tests/co19/co19-dart2js.status ('k') | tests/corelib/iterable_generate_test.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;
10 assert((checkedMode = true));
11 const String oneByteWhiteSpace = "\x09\x0a\x0b\x0c\x0d\x20" 9 const String oneByteWhiteSpace = "\x09\x0a\x0b\x0c\x0d\x20"
12 "\x85" // //# 01: ok 10 "\x85" // //# 01: ok
13 "\xa0"; 11 "\xa0";
14 const String whiteSpace = "$oneByteWhiteSpace\u1680" 12 const String whiteSpace = "$oneByteWhiteSpace\u1680"
15 "\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a" 13 "\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a"
16 "\u2028\u2029\u202f\u205f\u3000\ufeff"; 14 "\u2028\u2029\u202f\u205f\u3000\ufeff";
17 15
18 var digits = "0123456789abcdefghijklmnopqrstuvwxyz"; 16 var digits = "0123456789abcdefghijklmnopqrstuvwxyz";
19 var zeros = "0" * 64; 17 var zeros = "0" * 64;
20 18
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 testFails("+ 1", 2); // No space between sign and digits. 107 testFails("+ 1", 2); // No space between sign and digits.
110 testFails("- 1", 2); // No space between sign and digits. 108 testFails("- 1", 2); // No space between sign and digits.
111 testFails("0x", null); 109 testFails("0x", null);
112 for (int i = 2; i <= 33; i++) { 110 for (int i = 2; i <= 33; i++) {
113 // No 0x specially allowed. 111 // No 0x specially allowed.
114 // At radix 34 and above, "x" is a valid digit. 112 // At radix 34 and above, "x" is a valid digit.
115 testFails("0x10", i); 113 testFails("0x10", i);
116 } 114 }
117 115
118 testBadTypes(var source, var radix) { 116 testBadTypes(var source, var radix) {
119 if (!checkedMode) { 117 if (!typeAssertionsEnabled) {
120 // No promises on what error is thrown if the type doesn't match. 118 // No promises on what error is thrown if the type doesn't match.
121 // Likely either ArgumentError or NoSuchMethodError. 119 // Likely either ArgumentError or NoSuchMethodError.
122 Expect.throws(() => int.parse(source, radix: radix, onError: (s) => 0)); 120 Expect.throws(() => int.parse(source, radix: radix, onError: (s) => 0));
123 return; 121 return;
124 } 122 }
125 // In checked mode, it's always a TypeError. 123 // With type assertions enabled we can be more precise.
126 Expect.throws(() => int.parse(source, radix: radix, onError: (s) => 0), 124 Expect.throws(() => int.parse(source, radix: radix, onError: (s) => 0),
127 (e) => e is TypeError || e is CastError); 125 (e) => e is TypeError || e is CastError);
128 } 126 }
129 127
130 testBadTypes(9, 10); 128 testBadTypes(9, 10);
131 testBadTypes(true, 10); 129 testBadTypes(true, 10);
132 testBadTypes("0", true); 130 testBadTypes("0", true);
133 testBadTypes("0", "10"); 131 testBadTypes("0", "10");
134 132
135 testBadArguments(String source, int radix) { 133 testBadArguments(String source, int radix) {
136 // If the types match, it should be an ArgumentError of some sort. 134 // If the types match, it should be an ArgumentError of some sort.
137 Expect.throws(() => int.parse(source, radix: radix, onError: (s) => 0), 135 Expect.throws(() => int.parse(source, radix: radix, onError: (s) => 0),
138 (e) => e is ArgumentError); 136 (e) => e is ArgumentError);
139 } 137 }
140 138
141 testBadArguments("0", -1); 139 testBadArguments("0", -1);
142 testBadArguments("0", 0); 140 testBadArguments("0", 0);
143 testBadArguments("0", 1); 141 testBadArguments("0", 1);
144 testBadArguments("0", 37); 142 testBadArguments("0", 37);
145 143
146 // See also int_parse_radix_bad_handler_test.dart 144 // See also int_parse_radix_bad_handler_test.dart
147 } 145 }
148 146
149 bool isFail(e) => e == "FAIL"; 147 bool isFail(e) => e == "FAIL";
OLDNEW
« no previous file with comments | « tests/co19/co19-dart2js.status ('k') | tests/corelib/iterable_generate_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698