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

Unified Diff: tests/lib/convert/json_test.dart

Issue 181543004: Optimize VM JSON parser for memory use. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add more tests. Created 6 years, 10 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
« runtime/lib/convert_patch.dart ('K') | « sdk/lib/core/iterable.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/lib/convert/json_test.dart
diff --git a/tests/lib/convert/json_test.dart b/tests/lib/convert/json_test.dart
index 4470535578aced1a25d1298013c4a70609ffd69d..f044f070c3b598964a5bef2884c3d5e33ecfe151 100644
--- a/tests/lib/convert/json_test.dart
+++ b/tests/lib/convert/json_test.dart
@@ -266,6 +266,90 @@ testWhitespace() {
}
}
+void testOutput() {
+ var nonJsonValue = new Object();
+ // Test that results are integers or doubles as appropriate.
+ var res = JSON.decode("0");
+ Expect.equals(0, res);
+ Expect.isTrue(res is int);
+ res = JSON.decode("999999999");
+ Expect.equals(999999999, res);
+ Expect.isTrue(res is int);
+ res = JSON.decode("0.5");
+ Expect.equals(0.5, res);
+ Expect.isTrue(res is double);
+ res = JSON.decode("5e5");
+ Expect.equals(500000, res);
+ Expect.isTrue(res is double);
+
+ // Test that lists are extensible and untyped.
+ res = JSON.decode("[42]");
+ Expect.isTrue(res is List);
+ Expect.listEquals([42], res);
+ res.add(37);
+ Expect.listEquals([42, 37], res);
+ res.add(nonJsonValue);
+ Expect.listEquals([42, 37, nonJsonValue], res);
+ // List handles concurrent modification correctly.
+ res = JSON.decode("[1, 2, 3]");
+ res.forEach((v) { res[0] = 42; }); // Not a modification, does not throw.
+ Expect.throws(() { res.forEach((v) { res.add(37); }); },
+ (e) => e is ConcurrentModificationError);
+
+ // Test that maps are untyped, modifiable and ordered.
+ res = JSON.decode('{"x": 42}');
+ Expect.isTrue(res is Map);
+ Expect.equals(1, res.length);
+ Expect.equals(42, res["x"]);
+ res["y"] = nonJsonValue;
+ Expect.equals(2, res.length);
+ Expect.equals(nonJsonValue, res["y"]);
+ // TODO(lrn): Can we avoid this? It would be great for optimizations
+ // if maps must be string keyed.
+ res[nonJsonValue] = 37;
+ Expect.equals(3, res.length);
+ Expect.equals(37, res[nonJsonValue]);
+ // Concurrent modifications.
+ res = JSON.decode('{"x": 42, "y": 37}');
+ res.forEach((k, v) { res["x"] = 99; }); // Not a modification, doesn't throw.
+
+ res = JSON.decode('{"x": 42, "y": 37}');
+ Expect.throws(() { res.forEach((k, v) { res["z"] = 12; }); },
+ (e) => e is ConcurrentModificationError);
+ res = JSON.decode('{"x": 42, "y": 37}');
+ Expect.throws(() { res.keys.forEach((k) { res["z"] = 12; }); },
+ (e) => e is ConcurrentModificationError);
+
+ res = JSON.decode('{"x": 42, "y": 37}');
+ res.forEach((k, v) { res.remove("z"); });
+
+ res = JSON.decode('{"x": 42, "y": 37}');
+ Expect.throws(() { res.forEach((k, v) { res.remove("x"); }); },
+ (e) => e is ConcurrentModificationError);
+ res = JSON.decode('{"x": 42, "y": 37}');
+ Expect.throws(() { res.keys.forEach((k) { res.remove("x"); }); },
+ (e) => e is ConcurrentModificationError);
+
+ res = JSON.decode('{"x": 42, "y": 37}');
+ Expect.throws(() { res.forEach((k, v) { res.clear(); }); },
+ (e) => e is ConcurrentModificationError);
+
+ res = JSON.decode('{"x": 42, "y": 37}');
+ Expect.throws(() { res.keys.forEach((k) { res.clear(); }); },
+ (e) => e is ConcurrentModificationError);
+
+ res = JSON.decode('{"x": 42, "y": 37}');
+ Expect.throws(() { res.forEach((k, v) { res.putIfAbsent("z", () => 99); }); },
+ (e) => e is ConcurrentModificationError);
+
+ res = JSON.decode('{"x": 42, "y": 37}');
+ Expect.throws(() {
+ res.keys.forEach((k) { res.putIfAbsent("z", () => 99); });
+ },
+ (e) => e is ConcurrentModificationError);
+}
+
+
main() {
testNumbers();
testStrings();
@@ -273,4 +357,5 @@ main() {
testObjects();
testArrays();
testWhitespace();
+ testOutput();
}
« runtime/lib/convert_patch.dart ('K') | « sdk/lib/core/iterable.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698