OLD | NEW |
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 Loading... |
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 Loading... |
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 } |
OLD | NEW |