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

Unified Diff: tests/corelib/json_leading_zeros_test.dart

Issue 12314055: Use browsers JSON.parse for parsing JSON (#3) (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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
« no previous file with comments | « tests/corelib/corelib.status ('k') | tests/corelib/json_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/corelib/json_leading_zeros_test.dart
diff --git a/tests/corelib/json_leading_zeros_test.dart b/tests/corelib/json_leading_zeros_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..9ab9b3510633006162b73c54bf088307c882b7a8
--- /dev/null
+++ b/tests/corelib/json_leading_zeros_test.dart
@@ -0,0 +1,60 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// This is a trimmed-down version of json_test to isolate a difference between
+// IE and other runtimes.
+
+library json_test;
+
+import "dart:json";
+
+bool badFormat(e) => e is FormatException;
+
+void testThrows(json) {
+ Expect.throws(() => parse(json), badFormat);
+}
+
+testNumbers() {
+ // Positive tests for number formats.
+ var integerList = ["0","9","9999"];
+ var signList = ["", "-"];
+ var fractionList = ["", ".0", ".1", ".99999"];
+ var exponentList = [""];
+ for (var exphead in ["e", "E", "e-", "E-", "e+", "E+"]) {
+ for (var expval in ["0", "1", "200"]) {
+ exponentList.add("$exphead$expval");
+ }
+ }
+
+ // Negative tests (syntax error).
+ // testError thoroughly tests the given parts with a lot of valid
+ // values for the other parts.
+ testError({signs, integers, fractions, exponents}) {
+ def(value, defaultValue) {
+ if (value == null) return defaultValue;
+ if (value is List) return value;
+ return [value];
+ }
+ signs = def(signs, signList);
+ integers = def(integers, integerList);
+ fractions = def(fractions, fractionList);
+ exponents = def(exponents, exponentList);
+ for (var integer in integers) {
+ for (var sign in signs) {
+ for (var fraction in fractions) {
+ for (var exponent in exponents) {
+ var literal = "$sign$integer$fraction$exponent";
+ testThrows(literal);
+ }
+ }
+ }
+ }
+ }
+ // Initial zero only allowed for zero integer part.
+ testError(integers: ["00", "01"]);
+}
+
+main() {
+ testNumbers();
+}
« no previous file with comments | « tests/corelib/corelib.status ('k') | tests/corelib/json_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698