OLD | NEW |
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 'dart:convert'; | 5 import 'dart:convert'; |
6 | 6 |
7 import 'package:expect/expect.dart'; | 7 import 'package:expect/expect.dart'; |
8 | 8 |
9 // This test implements a new special interface that can be used to | 9 // This test implements a new special interface that can be used to |
10 // send data more efficiently between two converters. | 10 // send data more efficiently between two converters. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 } | 47 } |
48 | 48 |
49 class BoolAdapterSink extends MyChunkedBoolSink { | 49 class BoolAdapterSink extends MyChunkedBoolSink { |
50 final _sink; | 50 final _sink; |
51 BoolAdapterSink(this._sink); | 51 BoolAdapterSink(this._sink); |
52 add(o) => _sink.add(o); | 52 add(o) => _sink.add(o); |
53 close() => _sink.close(); | 53 close() => _sink.close(); |
54 specialB(o) => add(o); | 54 specialB(o) => add(o); |
55 } | 55 } |
56 | 56 |
57 class IntBoolConverter1 extends | 57 class IntBoolConverter1 extends Converter<List<int>, List<bool>> { |
58 ChunkedConverter<List<int>, List<bool>, int, bool> { | |
59 List<bool> convert(List<int> input) => input.map((x) => x > 0).toList(); | 58 List<bool> convert(List<int> input) => input.map((x) => x > 0).toList(); |
60 | 59 |
61 startChunkedConversion(sink) { | 60 startChunkedConversion(sink) { |
62 if (sink is! MyChunkedBoolSink) sink = new MyChunkedBoolSink.from(sink); | 61 if (sink is! MyChunkedBoolSink) sink = new MyChunkedBoolSink.from(sink); |
63 return new IntBoolConverter1Sink(sink); | 62 return new IntBoolConverter1Sink(sink); |
64 } | 63 } |
65 } | 64 } |
66 | 65 |
67 class BoolIntConverter1 extends | 66 class BoolIntConverter1 extends Converter<List<bool>, List<int>> { |
68 ChunkedConverter<List<bool>, List<int>, bool, int> { | |
69 List<int> convert(List<bool> input) => input.map((x) => x ? 1 : 0).toList(); | 67 List<int> convert(List<bool> input) => input.map((x) => x ? 1 : 0).toList(); |
70 | 68 |
71 startChunkedConversion(sink) { | 69 startChunkedConversion(sink) { |
72 if (sink is! MyChunkedIntSink) sink = new MyChunkedIntSink.from(sink); | 70 if (sink is! MyChunkedIntSink) sink = new MyChunkedIntSink.from(sink); |
73 return new BoolIntConverter1Sink(sink); | 71 return new BoolIntConverter1Sink(sink); |
74 } | 72 } |
75 } | 73 } |
76 | 74 |
77 int specialICounter = 0; | 75 int specialICounter = 0; |
78 int specialBCounter = 0; | 76 int specialBCounter = 0; |
(...skipping 20 matching lines...) Expand all Loading... |
99 outSink.specialI(b ? 1 : 0); | 97 outSink.specialI(b ? 1 : 0); |
100 } | 98 } |
101 | 99 |
102 specialB(bool b) { | 100 specialB(bool b) { |
103 specialBCounter++; | 101 specialBCounter++; |
104 add(b); | 102 add(b); |
105 } | 103 } |
106 close() => outSink.close(); | 104 close() => outSink.close(); |
107 } | 105 } |
108 | 106 |
109 class IdentityConverter extends ChunkedConverter { | 107 class IdentityConverter extends Converter { |
110 convert(x) => x; | 108 convert(x) => x; |
111 | 109 |
112 startChunkedConversion(sink) { | 110 startChunkedConversion(sink) { |
113 return new IdentitySink(sink); | 111 return new IdentitySink(sink); |
114 } | 112 } |
115 } | 113 } |
116 | 114 |
117 class IdentitySink extends ChunkedConversionSink { | 115 class IdentitySink extends ChunkedConversionSink { |
118 final _sink; | 116 final _sink; |
119 IdentitySink(this._sink); | 117 IdentitySink(this._sink); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 intSink.add(-3); | 245 intSink.add(-3); |
248 intSink.add(3); | 246 intSink.add(3); |
249 intSink.close(); | 247 intSink.close(); |
250 Expect.isTrue(hasExecuted); | 248 Expect.isTrue(hasExecuted); |
251 Expect.equals(0, specialBCounter); | 249 Expect.equals(0, specialBCounter); |
252 specialBCounter = 0; | 250 specialBCounter = 0; |
253 Expect.equals(1, specialICounter); | 251 Expect.equals(1, specialICounter); |
254 specialICounter = 0; | 252 specialICounter = 0; |
255 hasExecuted = false; | 253 hasExecuted = false; |
256 } | 254 } |
OLD | NEW |