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

Side by Side Diff: tests/lib_strong/convert/chunked_conversion_json_decode1_test.dart

Issue 2771453003: Format all tests. (Closed)
Patch Set: Format files Created 3 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 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 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 import "package:expect/expect.dart"; 5 import "package:expect/expect.dart";
6 import 'dart:convert'; 6 import 'dart:convert';
7 7
8 final TESTS = [ 8 final TESTS = [
9 [ 5, '5' ], 9 [5, '5'],
10 [ -42, '-42' ], 10 [-42, '-42'],
11 [ 3.14, '3.14' ], 11 [3.14, '3.14'],
12 [ true, 'true' ], 12 [true, 'true'],
13 [ false, 'false' ], 13 [false, 'false'],
14 [ null, 'null' ], 14 [null, 'null'],
15 [ 'quote"or\'', '"quote\\"or\'"' ], 15 ['quote"or\'', '"quote\\"or\'"'],
16 [ '', '""' ], 16 ['', '""'],
17 [ [], "[]" ], 17 [[], "[]"],
18 [ [3, -4.5, true, "hi", false], '[3,-4.5,true,"hi",false]' ], 18 [
19 [ [null], "[null]" ], 19 [3, -4.5, true, "hi", false],
20 [ [[null]], "[[null]]" ], 20 '[3,-4.5,true,"hi",false]'
21 [ [[3]], "[[3]]" ], 21 ],
22 [ {}, "{}" ], 22 [
23 [ { "x": 3, "y": 4.5, "z": "hi", "u": true, "v": false }, 23 [null],
24 '{"x":3,"y":4.5,"z":"hi","u":true,"v":false}' ], 24 "[null]"
25 [ { "x": null }, '{"x":null}' ], 25 ],
26 [ { "x": {} }, '{"x":{}}' ], 26 [
27 // Note that -0.0 won't be treated the same in JS. The Json spec seems to 27 [
28 // allow it, though. 28 [null]
29 [ { "hi there": 499, "'":-0.0 }, '{"hi there":499,"\'":-0.0}' ], 29 ],
30 [ r'\foo', r'"\\foo"' ], 30 "[[null]]"
31 ]; 31 ],
32 [
33 [
34 [3]
35 ],
36 "[[3]]"
37 ],
38 [{}, "{}"],
39 [
40 {"x": 3, "y": 4.5, "z": "hi", "u": true, "v": false},
41 '{"x":3,"y":4.5,"z":"hi","u":true,"v":false}'
42 ],
43 [
44 {"x": null},
45 '{"x":null}'
46 ],
47 [
48 {"x": {}},
49 '{"x":{}}'
50 ],
51 // Note that -0.0 won't be treated the same in JS. The Json spec seems to
52 // allow it, though.
53 [
54 {"hi there": 499, "'": -0.0},
55 '{"hi there":499,"\'":-0.0}'
56 ],
57 [r'\foo', r'"\\foo"'],
58 ];
32 59
33 bool isJsonEqual(o1, o2) { 60 bool isJsonEqual(o1, o2) {
34 if (o1 == o2) return true; 61 if (o1 == o2) return true;
35 if (o1 is List && o2 is List) { 62 if (o1 is List && o2 is List) {
36 if (o1.length != o2.length) return false; 63 if (o1.length != o2.length) return false;
37 for (int i = 0; i < o1.length; i++) { 64 for (int i = 0; i < o1.length; i++) {
38 if (!isJsonEqual(o1[i], o2[i])) return false; 65 if (!isJsonEqual(o1[i], o2[i])) return false;
39 } 66 }
40 return true; 67 return true;
41 } 68 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 Object result; 155 Object result;
129 var decoder = new JsonDecoder(null); 156 var decoder = new JsonDecoder(null);
130 ChunkedConversionSink objectSink = 157 ChunkedConversionSink objectSink =
131 new ChunkedConversionSink.withCallback((x) => result = x.single); 158 new ChunkedConversionSink.withCallback((x) => result = x.single);
132 var stringConversionSink = decoder.startChunkedConversion(objectSink); 159 var stringConversionSink = decoder.startChunkedConversion(objectSink);
133 stringConversionSink.addSlice("1" + str + "2", 1, str.length + 1, false); 160 stringConversionSink.addSlice("1" + str + "2", 1, str.length + 1, false);
134 stringConversionSink.close(); 161 stringConversionSink.close();
135 return result; 162 return result;
136 } 163 }
137 164
138
139 main() { 165 main() {
140 var tests = TESTS.expand((test) { 166 var tests = TESTS.expand((test) {
141 var object = test[0]; 167 var object = test[0];
142 var string = test[1]; 168 var string = test[1];
143 var longString = " " 169 var longString = " "
144 " " 170 " "
145 "$string" 171 "$string"
146 " " 172 " "
147 " "; 173 " ";
148 return [test, [object, longString]]; 174 return [
175 test,
176 [object, longString]
177 ];
149 }); 178 });
150 for (var test in TESTS) { 179 for (var test in TESTS) {
151 var o = test[0]; 180 var o = test[0];
152 var string = test[1]; 181 var string = test[1];
153 Expect.isTrue(isJsonEqual(o, decode(string))); 182 Expect.isTrue(isJsonEqual(o, decode(string)));
154 Expect.isTrue(isJsonEqual(o, decode2(string))); 183 Expect.isTrue(isJsonEqual(o, decode2(string)));
155 Expect.isTrue(isJsonEqual(o, decode3(string))); 184 Expect.isTrue(isJsonEqual(o, decode3(string)));
156 Expect.isTrue(isJsonEqual(o, decode4(string))); 185 Expect.isTrue(isJsonEqual(o, decode4(string)));
157 Expect.isTrue(isJsonEqual(o, decode5(string))); 186 Expect.isTrue(isJsonEqual(o, decode5(string)));
158 Expect.isTrue(isJsonEqual(o, decode6(string))); 187 Expect.isTrue(isJsonEqual(o, decode6(string)));
159 Expect.isTrue(isJsonEqual(o, decode7(string))); 188 Expect.isTrue(isJsonEqual(o, decode7(string)));
160 } 189 }
161 } 190 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698