OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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:expect/expect.dart'; | 6 import 'package:expect/expect.dart'; |
7 import 'dart:convert'; | 7 import 'dart:convert'; |
8 | 8 |
9 class A { | 9 class A { |
10 final x; | 10 final x; |
(...skipping 20 matching lines...) Expand all Loading... |
31 Expect.isTrue(decoded[0] is A); | 31 Expect.isTrue(decoded[0] is A); |
32 Expect.equals(0, decoded[0].x); | 32 Expect.equals(0, decoded[0].x); |
33 Expect.isTrue(decoded[1] is Map); | 33 Expect.isTrue(decoded[1] is Map); |
34 Expect.isNotNull(decoded[1]["2"]); | 34 Expect.isNotNull(decoded[1]["2"]); |
35 Expect.isTrue(decoded[1]["2"] is A); | 35 Expect.isTrue(decoded[1]["2"] is A); |
36 Expect.equals(1, decoded[1]["2"].x); | 36 Expect.equals(1, decoded[1]["2"].x); |
37 | 37 |
38 var a = extendedJson.decode(extendedJson.encode(new A(499))); | 38 var a = extendedJson.decode(extendedJson.encode(new A(499))); |
39 Expect.isTrue(a is A); | 39 Expect.isTrue(a is A); |
40 Expect.equals(499, a.x); | 40 Expect.equals(499, a.x); |
| 41 |
| 42 testInvalidMap(); |
41 } | 43 } |
| 44 |
| 45 |
| 46 void testInvalidMap() { |
| 47 var map = {"a" : 42, "b": 42, 37: 42}; // Non-string key. |
| 48 var enc = new JsonEncoder((_) => "fixed"); |
| 49 var res = enc.convert(map); |
| 50 Expect.equals('"fixed"', res); |
| 51 |
| 52 enc = new JsonEncoder.withIndent(" ", (_) => "fixed"); |
| 53 res = enc.convert(map); |
| 54 Expect.equals('"fixed"', res); |
| 55 } |
OLD | NEW |