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

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

Issue 87953002: Change Expect.identical(NaN, x) to not assume NaNs are identical. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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 | « runtime/lib/double_patch.dart ('k') | tests/lib/math/double_pow_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) 2013 the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013 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 6
7 const whiteSpace = const [ 7 const whiteSpace = const [
8 "", 8 "",
9 "\x09", 9 "\x09",
10 "\x0a", 10 "\x0a",
(...skipping 16 matching lines...) Expand all
27 "\u2009", 27 "\u2009",
28 "\u200a", 28 "\u200a",
29 "\u2028", 29 "\u2028",
30 "\u2029", 30 "\u2029",
31 "\u202f", 31 "\u202f",
32 "\u205f", 32 "\u205f",
33 "\u3000", 33 "\u3000",
34 "\uFEFF" 34 "\uFEFF"
35 ]; 35 ];
36 36
37 void expectNumEquals(num expect, num actual, String message) {
38 if (expect is double && expect.isNaN) {
39 Expect.isTrue(actual is double && actual.isNaN, "isNaN: $message");
40 } else {
41 Expect.identical(expect, actual, message);
42 }
43 }
44
37 void testParse(String source, num result) { 45 void testParse(String source, num result) {
38 for (String ws1 in whiteSpace) { 46 for (String ws1 in whiteSpace) {
39 for (String ws2 in whiteSpace) { 47 for (String ws2 in whiteSpace) {
40 String padded = "$ws1$source$ws2"; 48 String padded = "$ws1$source$ws2";
41 // Use Expect.identical because it also handles NaN and 0.0/-0.0. 49 // Use Expect.identical because it also handles NaN and 0.0/-0.0.
42 // Except on dart2js: http://dartbug.com/11551 50 // Except on dart2js: http://dartbug.com/11551
43 Expect.identical(result, num.parse(padded), "parse '$padded'"); 51 expectNumEquals(result, num.parse(padded), "parse '$padded'");
44 padded = "$ws1$ws2$source"; 52 padded = "$ws1$ws2$source";
45 Expect.identical(result, num.parse(padded), "parse '$padded'"); 53 expectNumEquals(result, num.parse(padded), "parse '$padded'");
46 padded = "$source$ws1$ws2"; 54 padded = "$source$ws1$ws2";
47 Expect.identical(result, num.parse(padded), "parse '$padded'"); 55 expectNumEquals(result, num.parse(padded), "parse '$padded'");
48 } 56 }
49 } 57 }
50 } 58 }
51 59
52 void testInt(int value) { 60 void testInt(int value) {
53 testParse("$value", value); 61 testParse("$value", value);
54 testParse("+$value", value); 62 testParse("+$value", value);
55 testParse("-$value", -value); 63 testParse("-$value", -value);
56 var hex = "0x${value.toRadixString(16)}"; 64 var hex = "0x${value.toRadixString(16)}";
57 var lchex = hex.toLowerCase(); 65 var lchex = hex.toLowerCase();
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 testFail("-e-1"); 194 testFail("-e-1");
187 // Incorrect ways to write NaN/Infinity. 195 // Incorrect ways to write NaN/Infinity.
188 testFail("infinity"); 196 testFail("infinity");
189 testFail("INFINITY"); 197 testFail("INFINITY");
190 testFail("inf"); 198 testFail("inf");
191 testFail("nan"); 199 testFail("nan");
192 testFail("NAN"); 200 testFail("NAN");
193 testFail("qnan"); 201 testFail("qnan");
194 testFail("snan"); 202 testFail("snan");
195 } 203 }
OLDNEW
« no previous file with comments | « runtime/lib/double_patch.dart ('k') | tests/lib/math/double_pow_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698