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

Unified Diff: tests/corelib/json_map_test.dart

Issue 367683002: Use JsonMap even for JSON.decode with custom reviver. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix long line in test. Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/_internal/lib/convert_patch.dart ('k') | tests/corelib/map_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/corelib/json_map_test.dart
diff --git a/tests/corelib/json_map_test.dart b/tests/corelib/json_map_test.dart
index faffb7c9304406c9d81c4616c1db9307390e2d5a..e34e9744a4d40115efe048f7c72511a7863fe0f0 100644
--- a/tests/corelib/json_map_test.dart
+++ b/tests/corelib/json_map_test.dart
@@ -8,7 +8,13 @@ import "package:expect/expect.dart";
import 'dart:convert' show JSON;
import 'dart:collection' show LinkedHashMap, HashMap;
-Map jsonify(Map map) => JSON.decode(JSON.encode(map));
+bool useReviver = false;
+Map jsonify(Map map) {
+ String encoded = JSON.encode(map);
+ return useReviver
+ ? JSON.decode(encoded, reviver: (key, value) => value)
+ : JSON.decode(encoded);
+}
List listEach(Map map) {
var result = [];
@@ -20,6 +26,12 @@ List listEach(Map map) {
}
void main() {
+ test(false);
+ test(true);
+}
+
+void test(bool revive) {
+ useReviver = revive;
testEmpty(jsonify({}));
testAtoB(jsonify({'a': 'b'}));
@@ -45,6 +57,7 @@ void main() {
testClear();
testListEntry();
+ testMutation();
}
void testEmpty(Map map) {
@@ -322,3 +335,12 @@ void testListEntry() {
Expect.equals(8, list[1]);
Expect.equals(9, list[2]['b']);
}
+
+void testMutation() {
+ Map map = jsonify({'a': 0});
+ Expect.listEquals(['a', 0], listEach(map));
+ map['a'] = 1;
+ Expect.listEquals(['a', 1], listEach(map));
+ map['a']++;
+ Expect.listEquals(['a', 2], listEach(map));
+}
« no previous file with comments | « sdk/lib/_internal/lib/convert_patch.dart ('k') | tests/corelib/map_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698