| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 // This is a trimmed-down version of json_test to isolate a difference between | |
| 6 // IE and other runtimes. | |
| 7 | |
| 8 library json_test; | |
| 9 | |
| 10 import "dart:json"; | |
| 11 | |
| 12 bool badFormat(e) => e is FormatException; | |
| 13 | |
| 14 void testThrows(json) { | |
| 15 Expect.throws(() => parse(json), badFormat); | |
| 16 } | |
| 17 | |
| 18 testNumbers() { | |
| 19 // Positive tests for number formats. | |
| 20 var integerList = ["0","9","9999"]; | |
| 21 var signList = ["", "-"]; | |
| 22 var fractionList = ["", ".0", ".1", ".99999"]; | |
| 23 var exponentList = [""]; | |
| 24 for (var exphead in ["e", "E", "e-", "E-", "e+", "E+"]) { | |
| 25 for (var expval in ["0", "1", "200"]) { | |
| 26 exponentList.add("$exphead$expval"); | |
| 27 } | |
| 28 } | |
| 29 | |
| 30 // Negative tests (syntax error). | |
| 31 // testError thoroughly tests the given parts with a lot of valid | |
| 32 // values for the other parts. | |
| 33 testError({signs, integers, fractions, exponents}) { | |
| 34 def(value, defaultValue) { | |
| 35 if (value == null) return defaultValue; | |
| 36 if (value is List) return value; | |
| 37 return [value]; | |
| 38 } | |
| 39 signs = def(signs, signList); | |
| 40 integers = def(integers, integerList); | |
| 41 fractions = def(fractions, fractionList); | |
| 42 exponents = def(exponents, exponentList); | |
| 43 for (var integer in integers) { | |
| 44 for (var sign in signs) { | |
| 45 for (var fraction in fractions) { | |
| 46 for (var exponent in exponents) { | |
| 47 var literal = "$sign$integer$fraction$exponent"; | |
| 48 testThrows(literal); | |
| 49 } | |
| 50 } | |
| 51 } | |
| 52 } | |
| 53 } | |
| 54 // Initial zero only allowed for zero integer part. | |
| 55 testError(integers: ["00", "01"]); | |
| 56 } | |
| 57 | |
| 58 main() { | |
| 59 testNumbers(); | |
| 60 } | |
| OLD | NEW |