| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library jsonTest; | 5 library jsonTest; |
| 6 | 6 |
| 7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 | 9 |
| 10 main() { | 10 main() { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 75 |
| 76 // Lists. | 76 // Lists. |
| 77 Expect.listEquals([], JSON.decode(' [] ')); | 77 Expect.listEquals([], JSON.decode(' [] ')); |
| 78 Expect.listEquals(["entry"], JSON.decode(' ["entry"] ')); | 78 Expect.listEquals(["entry"], JSON.decode(' ["entry"] ')); |
| 79 Expect.listEquals([true, false], JSON.decode(' [true, false] ')); | 79 Expect.listEquals([true, false], JSON.decode(' [true, false] ')); |
| 80 Expect.listEquals([1, 2, 3], JSON.decode(' [ 1 , 2 , 3 ] ')); | 80 Expect.listEquals([1, 2, 3], JSON.decode(' [ 1 , 2 , 3 ] ')); |
| 81 | 81 |
| 82 // Maps. | 82 // Maps. |
| 83 Expect.mapEquals({}, JSON.decode(' {} ')); | 83 Expect.mapEquals({}, JSON.decode(' {} ')); |
| 84 Expect.mapEquals({"key": "value"}, JSON.decode(' {"key": "value" } ')); | 84 Expect.mapEquals({"key": "value"}, JSON.decode(' {"key": "value" } ')); |
| 85 Expect.mapEquals({"key1": 1, "key2": 2}, | 85 Expect.mapEquals( |
| 86 JSON.decode(' {"key1": 1, "key2": 2} ')); | 86 {"key1": 1, "key2": 2}, JSON.decode(' {"key1": 1, "key2": 2} ')); |
| 87 Expect.mapEquals({"key1": 1}, | 87 Expect.mapEquals({"key1": 1}, JSON.decode(' { "key1" : 1 } ')); |
| 88 JSON.decode(' { "key1" : 1 } ')); | |
| 89 } | 88 } |
| 90 | 89 |
| 91 void testParseInvalid() { | 90 void testParseInvalid() { |
| 92 void testString(String s) { | 91 void testString(String s) { |
| 93 Expect.throws(() => JSON.decode(s), (e) => e is FormatException); | 92 Expect.throws(() => JSON.decode(s), (e) => e is FormatException); |
| 94 } | 93 } |
| 94 |
| 95 // Scalars | 95 // Scalars |
| 96 testString(""); | 96 testString(""); |
| 97 testString("-"); | 97 testString("-"); |
| 98 testString("-."); | 98 testString("-."); |
| 99 testString("3.a"); | 99 testString("3.a"); |
| 100 testString("{ key: value }"); | 100 testString("{ key: value }"); |
| 101 testString("tru"); | 101 testString("tru"); |
| 102 testString("1E--6"); | 102 testString("1E--6"); |
| 103 testString("1E-+6"); | 103 testString("1E-+6"); |
| 104 testString("1E+-6"); | 104 testString("1E+-6"); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 Expect.stringEquals('"\\u001b"', JSON.encode('\u001b')); | 167 Expect.stringEquals('"\\u001b"', JSON.encode('\u001b')); |
| 168 Expect.stringEquals('"\\u001c"', JSON.encode('\u001c')); | 168 Expect.stringEquals('"\\u001c"', JSON.encode('\u001c')); |
| 169 Expect.stringEquals('"\\u001d"', JSON.encode('\u001d')); | 169 Expect.stringEquals('"\\u001d"', JSON.encode('\u001d')); |
| 170 Expect.stringEquals('"\\u001e"', JSON.encode('\u001e')); | 170 Expect.stringEquals('"\\u001e"', JSON.encode('\u001e')); |
| 171 Expect.stringEquals('"\\u001f"', JSON.encode('\u001f')); | 171 Expect.stringEquals('"\\u001f"', JSON.encode('\u001f')); |
| 172 Expect.stringEquals('"\\\""', JSON.encode('"')); | 172 Expect.stringEquals('"\\\""', JSON.encode('"')); |
| 173 Expect.stringEquals('"\\\\"', JSON.encode('\\')); | 173 Expect.stringEquals('"\\\\"', JSON.encode('\\')); |
| 174 Expect.stringEquals('"Got \\b, \\f, \\n, \\r, \\t, \\u0000, \\\\, and \\"."', | 174 Expect.stringEquals('"Got \\b, \\f, \\n, \\r, \\t, \\u0000, \\\\, and \\"."', |
| 175 JSON.encode('Got \b, \f, \n, \r, \t, \u0000, \\, and ".')); | 175 JSON.encode('Got \b, \f, \n, \r, \t, \u0000, \\, and ".')); |
| 176 Expect.stringEquals('"Got \\b\\f\\n\\r\\t\\u0000\\\\\\"."', | 176 Expect.stringEquals('"Got \\b\\f\\n\\r\\t\\u0000\\\\\\"."', |
| 177 JSON.encode('Got \b\f\n\r\t\u0000\\".')); | 177 JSON.encode('Got \b\f\n\r\t\u0000\\".')); |
| 178 } | 178 } |
| OLD | NEW |