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

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

Issue 2879153005: Add support to dart2js for option --enable-asserts. (Closed)
Patch Set: Formatting Created 3 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
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 final bool isCheckedMode = (() {
9 try {
10 var i = 42;
11 String s = i;
12 } on TypeError catch (e) {
13 return true;
14 }
15 return false;
16 })();
sra1 2017/05/24 01:30:46 delete
eernst 2017/07/07 08:50:29 Done.
17
8 void main() { 18 void main() {
9 bool checkedMode = false;
10 assert((checkedMode = true));
11 const String oneByteWhiteSpace = "\x09\x0a\x0b\x0c\x0d\x20" 19 const String oneByteWhiteSpace = "\x09\x0a\x0b\x0c\x0d\x20"
12 "\x85" // //# 01: ok 20 "\x85" // //# 01: ok
13 "\xa0"; 21 "\xa0";
14 const String whiteSpace = "$oneByteWhiteSpace\u1680" 22 const String whiteSpace = "$oneByteWhiteSpace\u1680"
15 "\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a" 23 "\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a"
16 "\u2028\u2029\u202f\u205f\u3000\ufeff"; 24 "\u2028\u2029\u202f\u205f\u3000\ufeff";
17 25
18 var digits = "0123456789abcdefghijklmnopqrstuvwxyz"; 26 var digits = "0123456789abcdefghijklmnopqrstuvwxyz";
19 var zeros = "0" * 64; 27 var zeros = "0" * 64;
20 28
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 testFails("+ 1", 2); // No space between sign and digits. 117 testFails("+ 1", 2); // No space between sign and digits.
110 testFails("- 1", 2); // No space between sign and digits. 118 testFails("- 1", 2); // No space between sign and digits.
111 testFails("0x", null); 119 testFails("0x", null);
112 for (int i = 2; i <= 33; i++) { 120 for (int i = 2; i <= 33; i++) {
113 // No 0x specially allowed. 121 // No 0x specially allowed.
114 // At radix 34 and above, "x" is a valid digit. 122 // At radix 34 and above, "x" is a valid digit.
115 testFails("0x10", i); 123 testFails("0x10", i);
116 } 124 }
117 125
118 testBadTypes(var source, var radix) { 126 testBadTypes(var source, var radix) {
119 if (!checkedMode) { 127 if (!typeAssertionsEnabled) {
120 // No promises on what error is thrown if the type doesn't match. 128 // No promises on what error is thrown if the type doesn't match.
121 // Likely either ArgumentError or NoSuchMethodError. 129 // Likely either ArgumentError or NoSuchMethodError.
122 Expect.throws(() => int.parse(source, radix: radix, onError: (s) => 0)); 130 Expect.throws(() => int.parse(source, radix: radix, onError: (s) => 0));
123 return; 131 return;
124 } 132 }
125 // In checked mode, it's always a TypeError. 133 // With type assertions enabled we can be more precise.
126 Expect.throws(() => int.parse(source, radix: radix, onError: (s) => 0), 134 Expect.throws(() => int.parse(source, radix: radix, onError: (s) => 0),
127 (e) => e is TypeError || e is CastError); 135 (e) => e is TypeError || e is CastError);
128 } 136 }
129 137
130 testBadTypes(9, 10); 138 testBadTypes(9, 10);
131 testBadTypes(true, 10); 139 testBadTypes(true, 10);
132 testBadTypes("0", true); 140 testBadTypes("0", true);
133 testBadTypes("0", "10"); 141 testBadTypes("0", "10");
134 142
135 testBadArguments(String source, int radix) { 143 testBadArguments(String source, int radix) {
136 // If the types match, it should be an ArgumentError of some sort. 144 // If the types match, it should be an ArgumentError of some sort.
137 Expect.throws(() => int.parse(source, radix: radix, onError: (s) => 0), 145 Expect.throws(() => int.parse(source, radix: radix, onError: (s) => 0),
138 (e) => e is ArgumentError); 146 (e) => e is ArgumentError);
139 } 147 }
140 148
141 testBadArguments("0", -1); 149 testBadArguments("0", -1);
142 testBadArguments("0", 0); 150 testBadArguments("0", 0);
143 testBadArguments("0", 1); 151 testBadArguments("0", 1);
144 testBadArguments("0", 37); 152 testBadArguments("0", 37);
145 153
146 // See also int_parse_radix_bad_handler_test.dart 154 // See also int_parse_radix_bad_handler_test.dart
147 } 155 }
148 156
149 bool isFail(e) => e == "FAIL"; 157 bool isFail(e) => e == "FAIL";
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698