OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS d.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 import 'dart:convert'; |
| 6 |
| 7 import 'package:charcode/ascii.dart'; |
| 8 import 'package:pub/src/cr_lf_remover.dart'; |
| 9 import 'package:test/test.dart'; |
| 10 |
| 11 final _remover = const CRLFRemover(); |
| 12 |
| 13 void main() { |
| 14 group("convert()", () { |
| 15 test("removes CRs before LFs", () { |
| 16 expect(_remover.convert([ |
| 17 $f, $o, $o, $cr, $lf, |
| 18 $b, $a, $r, $cr, $lf, |
| 19 $b, $a, $z, $cr, $lf |
| 20 ]), equals([ |
| 21 $f, $o, $o, $lf, |
| 22 $b, $a, $r, $lf, |
| 23 $b, $a, $z, $lf |
| 24 ])); |
| 25 }); |
| 26 |
| 27 test("doesn't remove CRs that aren't before LFs", () { |
| 28 expect(_remover.convert([ |
| 29 $f, $o, $o, $cr, $space, $lf, |
| 30 $b, $a, $r, $cr, |
| 31 $b, $a, $z, $cr |
| 32 ]), equals([ |
| 33 $f, $o, $o, $cr, $space, $lf, |
| 34 $b, $a, $r, $cr, |
| 35 $b, $a, $z, $cr |
| 36 ])); |
| 37 }); |
| 38 }); |
| 39 |
| 40 group("startChunkedConversion()", () { |
| 41 var result; |
| 42 var sink; |
| 43 setUp(() { |
| 44 sink = _remover.startChunkedConversion( |
| 45 new ByteConversionSink.withCallback((result_) => result = result_)); |
| 46 }); |
| 47 |
| 48 test("removes CRs before LFs", () { |
| 49 sink.add([ |
| 50 $f, $o, $o, $cr, $lf, |
| 51 $b, $a, $r, $cr, $lf, |
| 52 $b, $a, $z, $cr, $lf |
| 53 ]); |
| 54 |
| 55 sink.close(); |
| 56 expect(result, equals([ |
| 57 $f, $o, $o, $lf, |
| 58 $b, $a, $r, $lf, |
| 59 $b, $a, $z, $lf |
| 60 ])); |
| 61 }); |
| 62 |
| 63 test("doesn't remove CRs that aren't before LFs", () { |
| 64 sink.add([ |
| 65 $f, $o, $o, $cr, $space, $lf, |
| 66 $b, $a, $r, $cr, |
| 67 $b, $a, $z, $cr |
| 68 ]); |
| 69 |
| 70 sink.close(); |
| 71 expect(result, equals([ |
| 72 $f, $o, $o, $cr, $space, $lf, |
| 73 $b, $a, $r, $cr, |
| 74 $b, $a, $z, $cr |
| 75 ])); |
| 76 }); |
| 77 |
| 78 test("concatenates chunks", () { |
| 79 sink.add([$f, $o, $o]); |
| 80 sink.add([$b, $a, $r]); |
| 81 |
| 82 sink.close(); |
| 83 expect(result, equals([$f, $o, $o, $b, $a, $r])); |
| 84 }); |
| 85 |
| 86 test("remembers CRs between chunks", () { |
| 87 sink.add([$f, $o, $o, $cr]); |
| 88 sink.add([$lf, $b, $a, $r]); |
| 89 |
| 90 sink.close(); |
| 91 expect(result, equals([$f, $o, $o, $lf, $b, $a, $r])); |
| 92 }); |
| 93 |
| 94 test("emits unpaired CRs between chunks", () { |
| 95 sink.add([$f, $o, $o, $cr]); |
| 96 sink.add([$b, $a, $r]); |
| 97 |
| 98 sink.close(); |
| 99 expect(result, equals([$f, $o, $o, $cr, $b, $a, $r])); |
| 100 }); |
| 101 }); |
| 102 } |
OLD | NEW |