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

Side by Side Diff: tests/utils/src/JsonTest.dart

Issue 10170040: test rename overhaul: step 11 - tests/utils (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/utils/src/DummyCompilerTest.dart ('k') | tests/utils/src/MarkdownTest.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 #library('jsonTest');
6
7 #import('dart:json');
8
9 main() {
10 testEscaping();
11 testParse();
12 testParseInvalid();
13 }
14
15 void testParse() {
16 // Scalars.
17 Expect.equals(5, JSON.parse(' 5 '));
18 Expect.equals(-42, JSON.parse(' -42 '));
19 Expect.equals(3, JSON.parse(' 3e0 '));
20 Expect.equals(3.14, JSON.parse(' 3.14 '));
21 Expect.equals(true, JSON.parse(' true '));
22 Expect.equals(false, JSON.parse(' false'));
23 Expect.equals(null, JSON.parse(' null '));
24 Expect.equals(null, JSON.parse('\n\rnull\t'));
25 Expect.equals('hi there" bob', JSON.parse(' "hi there\\" bob" '));
26 Expect.equals('', JSON.parse(' "" '));
27
28 // Lists.
29 Expect.listEquals([], JSON.parse(' [] '));
30 Expect.listEquals(["entry"], JSON.parse(' ["entry"] '));
31 Expect.listEquals([true, false], JSON.parse(' [true, false] '));
32 Expect.listEquals([1, 2, 3], JSON.parse(' [ 1 , 2 , 3 ] '));
33
34 // Maps.
35 Expect.mapEquals({}, JSON.parse(' {} '));
36 Expect.mapEquals({"key": "value"}, JSON.parse(' {"key": "value" } '));
37 Expect.mapEquals({"key1": 1, "key2": 2},
38 JSON.parse(' {"key1": 1, "key2": 2} '));
39 Expect.mapEquals({"key1": 1},
40 JSON.parse(' { "key1" : 1 } '));
41 }
42
43 void testParseInvalid() {
44 void testString(String s) {
45 // TODO(ajohnsen): Require JSONParseException exception once all JSON libs
46 // have been updated.
47 Expect.throws(() => JSON.parse(s));
48 }
49 testString("");
50 testString("-");
51 testString("-.");
52 testString("3.a");
53 testString("{ key: value }");
54 testString("tru");
55
56 // Lists
57 testString('[, ]');
58 testString('["", ]');
59 testString('["", "]');
60 testString('["" ""]');
61
62 // Maps
63 testString('{"" ""}');
64 testString('{"": "",}');
65 }
66
67 void testEscaping() {
68 Expect.stringEquals('""', JSON.stringify(''));
69 Expect.stringEquals('"\\u0000"', JSON.stringify('\u0000'));
70 Expect.stringEquals('"\\u0001"', JSON.stringify('\u0001'));
71 Expect.stringEquals('"\\u0002"', JSON.stringify('\u0002'));
72 Expect.stringEquals('"\\u0003"', JSON.stringify('\u0003'));
73 Expect.stringEquals('"\\u0004"', JSON.stringify('\u0004'));
74 Expect.stringEquals('"\\u0005"', JSON.stringify('\u0005'));
75 Expect.stringEquals('"\\u0006"', JSON.stringify('\u0006'));
76 Expect.stringEquals('"\\u0007"', JSON.stringify('\u0007'));
77 Expect.stringEquals('"\\b"', JSON.stringify('\u0008'));
78 Expect.stringEquals('"\\t"', JSON.stringify('\u0009'));
79 Expect.stringEquals('"\\n"', JSON.stringify('\u000a'));
80 Expect.stringEquals('"\\u000b"', JSON.stringify('\u000b'));
81 Expect.stringEquals('"\\f"', JSON.stringify('\u000c'));
82 Expect.stringEquals('"\\r"', JSON.stringify('\u000d'));
83 Expect.stringEquals('"\\u000e"', JSON.stringify('\u000e'));
84 Expect.stringEquals('"\\u000f"', JSON.stringify('\u000f'));
85 Expect.stringEquals('"\\u0010"', JSON.stringify('\u0010'));
86 Expect.stringEquals('"\\u0011"', JSON.stringify('\u0011'));
87 Expect.stringEquals('"\\u0012"', JSON.stringify('\u0012'));
88 Expect.stringEquals('"\\u0013"', JSON.stringify('\u0013'));
89 Expect.stringEquals('"\\u0014"', JSON.stringify('\u0014'));
90 Expect.stringEquals('"\\u0015"', JSON.stringify('\u0015'));
91 Expect.stringEquals('"\\u0016"', JSON.stringify('\u0016'));
92 Expect.stringEquals('"\\u0017"', JSON.stringify('\u0017'));
93 Expect.stringEquals('"\\u0018"', JSON.stringify('\u0018'));
94 Expect.stringEquals('"\\u0019"', JSON.stringify('\u0019'));
95 Expect.stringEquals('"\\u001a"', JSON.stringify('\u001a'));
96 Expect.stringEquals('"\\u001b"', JSON.stringify('\u001b'));
97 Expect.stringEquals('"\\u001c"', JSON.stringify('\u001c'));
98 Expect.stringEquals('"\\u001d"', JSON.stringify('\u001d'));
99 Expect.stringEquals('"\\u001e"', JSON.stringify('\u001e'));
100 Expect.stringEquals('"\\u001f"', JSON.stringify('\u001f'));
101 Expect.stringEquals('"\\\""', JSON.stringify('"'));
102 Expect.stringEquals('"\\\\"', JSON.stringify('\\'));
103 Expect.stringEquals('"Got \\b, \\f, \\n, \\r, \\t, \\u0000, \\\\, and \\"."',
104 JSON.stringify('Got \b, \f, \n, \r, \t, \u0000, \\, and ".'));
105 Expect.stringEquals('"Got \\b\\f\\n\\r\\t\\u0000\\\\\\"."',
106 JSON.stringify('Got \b\f\n\r\t\u0000\\".'));
107 }
OLDNEW
« no previous file with comments | « tests/utils/src/DummyCompilerTest.dart ('k') | tests/utils/src/MarkdownTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698