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 'dart:json' as json; | 7 import 'package:json/json.dart' as json; |
8 | 8 |
9 main() { | 9 main() { |
10 test('Parse', () { | 10 test('Parse', () { |
11 // Scalars. | 11 // Scalars. |
12 expect(json.parse(' 5 '), equals(5)); | 12 expect(json.parse(' 5 '), equals(5)); |
13 expect(json.parse(' -42 '), equals(-42)); | 13 expect(json.parse(' -42 '), equals(-42)); |
14 expect(json.parse(' 3e0 '), equals(3)); | 14 expect(json.parse(' 3e0 '), equals(3)); |
15 expect(json.parse(' 3.14 '), equals(3.14)); | 15 expect(json.parse(' 3.14 '), equals(3.14)); |
16 expect(json.parse('true '), isTrue); | 16 expect(json.parse('true '), isTrue); |
17 expect(json.parse(' false'), isFalse); | 17 expect(json.parse(' false'), isFalse); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 var throwsJsonError = | 180 var throwsJsonError = |
181 throwsA(new isInstanceOf<json.JsonUnsupportedObjectError>()); | 181 throwsA(new isInstanceOf<json.JsonUnsupportedObjectError>()); |
182 | 182 |
183 /** | 183 /** |
184 * Checks that the argument can be converted to a JSON string and | 184 * Checks that the argument can be converted to a JSON string and |
185 * back, and produce something equivalent to the argument. | 185 * back, and produce something equivalent to the argument. |
186 */ | 186 */ |
187 validateRoundTrip(expected) { | 187 validateRoundTrip(expected) { |
188 expect(json.parse(json.stringify(expected)), equals(expected)); | 188 expect(json.parse(json.stringify(expected)), equals(expected)); |
189 } | 189 } |
OLD | NEW |