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

Side by Side Diff: tests/lib/convert/streamed_conversion_json_utf8_decode_test.dart

Issue 23056002: Convert HashMap and LinkedHashMap to closed addressing hash tables. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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
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:async'; 6 import 'dart:async';
7 import 'dart:convert'; 7 import 'dart:convert';
8 import 'json_unicode_tests.dart'; 8 import 'json_unicode_tests.dart';
9 import '../../async_helper.dart'; 9 import '../../async_helper.dart';
10 10
11 final JSON_UTF8 = JSON.fuse(UTF8); 11 final JSON_UTF8 = JSON.fuse(UTF8);
12 12
13 bool isJsonEqual(o1, o2) { 13 void expectJsonEquals(o1, o2, [path = "result"]) {
14 if (o1 == o2) return true; 14 if (o1 == o2) return;
15 if (o1 is List && o2 is List) { 15 if (o1 is List && o2 is List) {
16 if (o1.length != o2.length) return false; 16 Expect.equals(o1.length, o2.length, "$path.length");
17 for (int i = 0; i < o1.length; i++) { 17 for (int i = 0; i < o1.length; i++) {
18 if (!isJsonEqual(o1[i], o2[i])) return false; 18 expectJsonEquals(o1[i], o2[i], "$path[$i]");
19 } 19 }
20 return true; 20 return;
21 } 21 }
22 if (o1 is Map && o2 is Map) { 22 if (o1 is Map && o2 is Map) {
23 if (o1.length != o2.length) return false; 23 Expect.equals(o1.length, o2.length, "$path.length");
24 for (var key in o1.keys) { 24 for (var key in o1.keys) {
25 Expect.isTrue(key is String); 25 Expect.isTrue(key is String, "$path:key = $key");
26 if (!o2.containsKey(key)) return false; 26 Expect.isTrue(o2.containsKey(key), "$path[$key] missing in $o2");
27 if (!isJsonEqual(o1[key], o2[key])) return false; 27 expectJsonEquals(o1[key], o2[key], "$path[$key]");
28 } 28 }
29 return true; 29 return;
30 } 30 }
31 return false; 31 Expect.equals(o1, o2);
32 } 32 }
33 33
34 Stream<Object> createStream(List<List<int>> chunks) { 34 Stream<Object> createStream(List<List<int>> chunks) {
35 var controller; 35 var controller;
36 controller = new StreamController(onListen: () { 36 controller = new StreamController(onListen: () {
37 chunks.forEach(controller.add); 37 chunks.forEach(controller.add);
38 controller.close(); 38 controller.close();
39 }); 39 });
40 return controller.stream.transform(JSON_UTF8.decoder); 40 return controller.stream.transform(JSON_UTF8.decoder);
41 } 41 }
(...skipping 12 matching lines...) Expand all
54 chunked.add(bytes.sublist(i)); 54 chunked.add(bytes.sublist(i));
55 } 55 }
56 i += chunkSize; 56 i += chunkSize;
57 } 57 }
58 return createStream(chunked); 58 return createStream(chunked);
59 } 59 }
60 60
61 void checkIsJsonEqual(expected, stream) { 61 void checkIsJsonEqual(expected, stream) {
62 asyncStart(); 62 asyncStart();
63 stream.single.then((o) { 63 stream.single.then((o) {
64 Expect.isTrue(isJsonEqual(expected, o)); 64 expectJsonEquals(expected, o);
65 asyncEnd(); 65 asyncEnd();
66 }); 66 });
67 } 67 }
68 68
69 main() { 69 main() {
70 for (var test in JSON_UNICODE_TESTS) { 70 for (var test in JSON_UNICODE_TESTS) {
71 var bytes = test[0]; 71 var bytes = test[0];
72 var o = test[1]; 72 var o = test[1];
73 checkIsJsonEqual(o, decode(bytes)); 73 checkIsJsonEqual(o, decode(bytes));
74 checkIsJsonEqual(o, decodeChunked(bytes, 1)); 74 checkIsJsonEqual(o, decodeChunked(bytes, 1));
75 checkIsJsonEqual(o, decodeChunked(bytes, 2)); 75 checkIsJsonEqual(o, decodeChunked(bytes, 2));
76 checkIsJsonEqual(o, decodeChunked(bytes, 3)); 76 checkIsJsonEqual(o, decodeChunked(bytes, 3));
77 checkIsJsonEqual(o, decodeChunked(bytes, 4)); 77 checkIsJsonEqual(o, decodeChunked(bytes, 4));
78 checkIsJsonEqual(o, decodeChunked(bytes, 5)); 78 checkIsJsonEqual(o, decodeChunked(bytes, 5));
79 } 79 }
80 } 80 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698