| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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_tests; | 5 library json_tests; |
| 6 import 'package:unittest/unittest.dart'; | 6 import 'package:unittest/unittest.dart'; |
| 7 import 'package:json/json.dart' as json; | 7 import 'package:json/json.dart' as json; |
| 8 | 8 |
| 9 main() { | 9 main() { |
| 10 test('Parse', () { | 10 test('Parse', () { |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 '[4,{"x":42}]'); | 116 '[4,{"x":42}]'); |
| 117 | 117 |
| 118 expect(() { | 118 expect(() { |
| 119 json.stringify([new ToJson(new ToJson(4))]); | 119 json.stringify([new ToJson(new ToJson(4))]); |
| 120 }, throwsJsonError); | 120 }, throwsJsonError); |
| 121 | 121 |
| 122 expect(() { | 122 expect(() { |
| 123 json.stringify([new Object()]); | 123 json.stringify([new Object()]); |
| 124 }, throwsJsonError); | 124 }, throwsJsonError); |
| 125 | 125 |
| 126 expect(() { |
| 127 json.stringify([double.NAN]); |
| 128 }, throwsJsonError); |
| 129 |
| 130 expect(() { |
| 131 json.stringify([double.INFINITY]); |
| 132 }, throwsJsonError); |
| 133 |
| 134 expect(() { |
| 135 json.stringify([-double.INFINITY]); |
| 136 }, throwsJsonError); |
| 126 }); | 137 }); |
| 127 | 138 |
| 128 test('stringify throws if argument cannot be converted', () { | 139 test('stringify throws if argument cannot be converted', () { |
| 129 /** | 140 /** |
| 130 * Checks that we get an exception (rather than silently returning null) if | 141 * Checks that we get an exception (rather than silently returning null) if |
| 131 * we try to stringify something that cannot be converted to json. | 142 * we try to stringify something that cannot be converted to json. |
| 132 */ | 143 */ |
| 133 expect(() => json.stringify(new TestClass()), throwsJsonError); | 144 expect(() => json.stringify(new TestClass()), throwsJsonError); |
| 134 }); | 145 }); |
| 135 | 146 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 var throwsJsonError = | 191 var throwsJsonError = |
| 181 throwsA(new isInstanceOf<json.JsonUnsupportedObjectError>()); | 192 throwsA(new isInstanceOf<json.JsonUnsupportedObjectError>()); |
| 182 | 193 |
| 183 /** | 194 /** |
| 184 * Checks that the argument can be converted to a JSON string and | 195 * Checks that the argument can be converted to a JSON string and |
| 185 * back, and produce something equivalent to the argument. | 196 * back, and produce something equivalent to the argument. |
| 186 */ | 197 */ |
| 187 validateRoundTrip(expected) { | 198 validateRoundTrip(expected) { |
| 188 expect(json.parse(json.stringify(expected)), equals(expected)); | 199 expect(json.parse(json.stringify(expected)), equals(expected)); |
| 189 } | 200 } |
| OLD | NEW |