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

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

Issue 385163002: Make VM JSON parser parse doubles without doing substring. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix bad whitespace edit. Created 6 years, 5 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 | « runtime/vm/object.cc ('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..2d3e084e139b80f3e5560675ed142e1f2bb4b76a 100644
--- a/tests/lib/convert/json_test.dart
+++ b/tests/lib/convert/json_test.dart
@@ -10,7 +10,6 @@ import "dart:convert";
bool badFormat(e) => e is FormatException;
void testJson(json, expected) {
- var value = JSON.decode(json);
compare(expected, actual, path) {
if (expected is List) {
Expect.isTrue(actual is List);
@@ -34,7 +33,16 @@ void testJson(json, expected) {
Expect.equals(expected, actual, path);
}
}
- compare(expected, value, "value");
+ for (var reviver in [null, (k, v) => v]) {
+ var value = JSON.decode(json, reviver: reviver);
+ compare(expected, value, "$value");
+ value = JSON.decode(" $json ", reviver: reviver);
+ compare(expected, value, "-$value-");
+ value = JSON.decode("[$json]", reviver: reviver);
+ compare([expected], value, "[$value]");
+ value = JSON.decode('{"x":$json}', reviver: reviver);
+ compare({"x":expected}, value, "{x:$value}");
+ }
}
String escape(String s) {
@@ -152,11 +160,23 @@ testStrings() {
// Empty string.
testJson(r'""', "");
// Escape first.
- testJson(r'"\"........"', "\"........");
- // Escape last.
- testJson(r'"........\""', "........\"");
- // Escape middle.
- testJson(r'"....\"...."', "....\"....");
+ var escapes = {
+ "f": "\f",
+ "b": "\b",
+ "n": "\n",
+ "r": "\r",
+ "t": "\t",
+ r"\": r"\",
+ '"': '"',
+ "/": "/",
+ };
+ escapes.forEach((esc, lit) {
+ testJson('"\\$esc........"', "$lit........");
+ // Escape last.
+ testJson('"........\\$esc"', "........$lit");
+ // Escape middle.
+ testJson('"....\\$esc...."', "....$lit....");
+ });
// Does not accept single quotes.
testThrows(r"''");
« no previous file with comments | « runtime/vm/object.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698