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

Side by Side Diff: tests/lib/convert/json_test.dart

Issue 136373002: Fix JSON encoder accepting NaN and Infinity. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 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/lib/convert/json_lib_test.dart ('k') | tests/lib/convert/json_util_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 library json_test; 5 library json_test;
6 6
7 import "package:expect/expect.dart"; 7 import "package:expect/expect.dart";
8 import "dart:convert"; 8 import "dart:convert";
9 9
10 bool badFormat(e) => e is FormatException; 10 bool badFormat(e) => e is FormatException;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 // No whitespace inside numbers. 128 // No whitespace inside numbers.
129 // Additional case "- 2.2e+2" in json_strict_test.dart. 129 // Additional case "- 2.2e+2" in json_strict_test.dart.
130 testThrows("-2 .2e+2"); 130 testThrows("-2 .2e+2");
131 testThrows("-2. 2e+2"); 131 testThrows("-2. 2e+2");
132 testThrows("-2.2 e+2"); 132 testThrows("-2.2 e+2");
133 testThrows("-2.2e +2"); 133 testThrows("-2.2e +2");
134 testThrows("-2.2e+ 2"); 134 testThrows("-2.2e+ 2");
135 135
136 testThrows("[2.,2]"); 136 testThrows("[2.,2]");
137 testThrows("{2.:2}"); 137 testThrows("{2.:2}");
138
139 testThrows("NaN");
140 testThrows("Infinity");
141 testThrows("-Infinity");
142 Expect.throws(() => JSON.encode(double.NAN));
143 Expect.throws(() => JSON.encode(double.INFINITY));
144 Expect.throws(() => JSON.encode(double.NEGATIVE_INFINITY));
138 } 145 }
139 146
140 testStrings() { 147 testStrings() {
141 // String parser accepts and understands escapes. 148 // String parser accepts and understands escapes.
142 var input = r'"\u0000\uffff\n\r\f\t\b\/\\\"' '\x20\ufffd\uffff"'; 149 var input = r'"\u0000\uffff\n\r\f\t\b\/\\\"' '\x20\ufffd\uffff"';
143 var expected = "\u0000\uffff\n\r\f\t\b\/\\\"\x20\ufffd\uffff"; 150 var expected = "\u0000\uffff\n\r\f\t\b\/\\\"\x20\ufffd\uffff";
144 testJson(input, expected); 151 testJson(input, expected);
145 // Empty string. 152 // Empty string.
146 testJson(r'""', ""); 153 testJson(r'""', "");
147 // Escape first. 154 // Escape first.
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 } 267 }
261 268
262 main() { 269 main() {
263 testNumbers(); 270 testNumbers();
264 testStrings(); 271 testStrings();
265 testWords(); 272 testWords();
266 testObjects(); 273 testObjects();
267 testArrays(); 274 testArrays();
268 testWhitespace(); 275 testWhitespace();
269 } 276 }
OLDNEW
« no previous file with comments | « tests/lib/convert/json_lib_test.dart ('k') | tests/lib/convert/json_util_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698