| 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 Converter<List<int>, List<bool>> { | 57 class IntBoolConverter1 extends |
| 58 ChunkedConverter<List<int>, List<bool>, int, bool> { |
| 58 List<bool> convert(List<int> input) => input.map((x) => x > 0).toList(); | 59 List<bool> convert(List<int> input) => input.map((x) => x > 0).toList(); |
| 59 | 60 |
| 60 startChunkedConversion(sink) { | 61 startChunkedConversion(sink) { |
| 61 if (sink is! MyChunkedBoolSink) sink = new MyChunkedBoolSink.from(sink); | 62 if (sink is! MyChunkedBoolSink) sink = new MyChunkedBoolSink.from(sink); |
| 62 return new IntBoolConverter1Sink(sink); | 63 return new IntBoolConverter1Sink(sink); |
| 63 } | 64 } |
| 64 } | 65 } |
| 65 | 66 |
| 66 class BoolIntConverter1 extends Converter<List<bool>, List<int>> { | 67 class BoolIntConverter1 extends |
| 68 ChunkedConverter<List<bool>, List<int>, bool, int> { |
| 67 List<int> convert(List<bool> input) => input.map((x) => x ? 1 : 0).toList(); | 69 List<int> convert(List<bool> input) => input.map((x) => x ? 1 : 0).toList(); |
| 68 | 70 |
| 69 startChunkedConversion(sink) { | 71 startChunkedConversion(sink) { |
| 70 if (sink is! MyChunkedIntSink) sink = new MyChunkedIntSink.from(sink); | 72 if (sink is! MyChunkedIntSink) sink = new MyChunkedIntSink.from(sink); |
| 71 return new BoolIntConverter1Sink(sink); | 73 return new BoolIntConverter1Sink(sink); |
| 72 } | 74 } |
| 73 } | 75 } |
| 74 | 76 |
| 75 int specialICounter = 0; | 77 int specialICounter = 0; |
| 76 int specialBCounter = 0; | 78 int specialBCounter = 0; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 97 outSink.specialI(b ? 1 : 0); | 99 outSink.specialI(b ? 1 : 0); |
| 98 } | 100 } |
| 99 | 101 |
| 100 specialB(bool b) { | 102 specialB(bool b) { |
| 101 specialBCounter++; | 103 specialBCounter++; |
| 102 add(b); | 104 add(b); |
| 103 } | 105 } |
| 104 close() => outSink.close(); | 106 close() => outSink.close(); |
| 105 } | 107 } |
| 106 | 108 |
| 107 class IdentityConverter extends Converter { | 109 class IdentityConverter extends ChunkedConverter { |
| 108 convert(x) => x; | 110 convert(x) => x; |
| 109 | 111 |
| 110 startChunkedConversion(sink) { | 112 startChunkedConversion(sink) { |
| 111 return new IdentitySink(sink); | 113 return new IdentitySink(sink); |
| 112 } | 114 } |
| 113 } | 115 } |
| 114 | 116 |
| 115 class IdentitySink extends ChunkedConversionSink { | 117 class IdentitySink extends ChunkedConversionSink { |
| 116 final _sink; | 118 final _sink; |
| 117 IdentitySink(this._sink); | 119 IdentitySink(this._sink); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 intSink.add(-3); | 247 intSink.add(-3); |
| 246 intSink.add(3); | 248 intSink.add(3); |
| 247 intSink.close(); | 249 intSink.close(); |
| 248 Expect.isTrue(hasExecuted); | 250 Expect.isTrue(hasExecuted); |
| 249 Expect.equals(0, specialBCounter); | 251 Expect.equals(0, specialBCounter); |
| 250 specialBCounter = 0; | 252 specialBCounter = 0; |
| 251 Expect.equals(1, specialICounter); | 253 Expect.equals(1, specialICounter); |
| 252 specialICounter = 0; | 254 specialICounter = 0; |
| 253 hasExecuted = false; | 255 hasExecuted = false; |
| 254 } | 256 } |
| OLD | NEW |