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

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

Issue 1153893004: In JsonEncoder, test if map has only string keys, and use toEncodable if not. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Address comment. Created 5 years, 6 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
« no previous file with comments | « sdk/lib/convert/json.dart ('k') | no next file » | 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) 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
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 }
OLDNEW
« no previous file with comments | « sdk/lib/convert/json.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698