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

Unified Diff: tests/utils/src/JsonTest.dart

Issue 10230004: Optimize the JSON parser by tokenizing while parsing and using jump-table. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Inline and small fixes. Created 8 years, 8 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
« lib/json/json.dart ('K') | « lib/json/json.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/utils/src/JsonTest.dart
diff --git a/tests/utils/src/JsonTest.dart b/tests/utils/src/JsonTest.dart
index 92febede8b3ba6ec150d39eb682efd020a270fe7..f45d1f4508664c886acb6362e30138d2e3259dc7 100644
--- a/tests/utils/src/JsonTest.dart
+++ b/tests/utils/src/JsonTest.dart
@@ -8,6 +8,56 @@
main() {
testEscaping();
+ testParse();
+ testParseInvalid();
+}
+
+void testParse() {
+ // Scalars.
+ Expect.equals(5, JSON.parse(' 5 '));
+ Expect.equals(-42, JSON.parse(' -42 '));
+ Expect.equals(3, JSON.parse(' 3e0 '));
+ Expect.equals(3.14, JSON.parse(' 3.14 '));
+ Expect.equals(true, JSON.parse(' true '));
+ Expect.equals(false, JSON.parse(' false'));
+ Expect.equals(null, JSON.parse(' null '));
+ Expect.equals(null, JSON.parse('\n\rnull\t'));
+ Expect.equals('hi there" bob', JSON.parse(' "hi there\\" bob" '));
+ Expect.equals('', JSON.parse(' "" '));
+
+ // Lists.
+ Expect.listEquals([], JSON.parse(' [] '));
+ Expect.listEquals(["entry"], JSON.parse(' ["entry"] '));
+ Expect.listEquals([true, false], JSON.parse(' [true, false] '));
+ Expect.listEquals([1, 2, 3], JSON.parse(' [ 1 , 2 , 3 ] '));
+
+ // Maps.
+ Expect.mapEquals({}, JSON.parse(' {} '));
+ Expect.mapEquals({"key": "value"}, JSON.parse(' {"key": "value" } '));
+ Expect.mapEquals({"key1": 1, "key2": 2},
+ JSON.parse(' {"key1": 1, "key2": 2} '));
+ Expect.mapEquals({"key1": 1},
+ JSON.parse(' { "key1" : 1 } '));
+}
+
+void testParseInvalid() {
+ void testString(String s) {
+ Expect.throws(() => JSON.parse(s), (e) => e is JSONParseException);
+ }
+ testString("");
+ testString("3.a");
+ testString("{ key: value }");
+ testString("tru");
+
+ // Lists
+ testString('[, ]');
+ testString('["", ]');
+ testString('["", "]');
+ testString('["" ""]');
+
+ // Maps
+ testString('{"" ""}');
+ testString('{"": "",}');
}
void testEscaping() {
« lib/json/json.dart ('K') | « lib/json/json.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698