| 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 library line_splitter_test; | 5 library line_splitter_test; |
| 6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:math' as MATH; | 9 import 'dart:math' as MATH; |
| 10 | 10 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 result = decoder.convert(test); | 76 result = decoder.convert(test); |
| 77 | 77 |
| 78 Expect.listEquals( | 78 Expect.listEquals( |
| 79 ['Line1', 'Line2', 'Line3', 'Line4', '', '', '', '', '', ''], | 79 ['Line1', 'Line2', 'Line3', 'Line4', '', '', '', '', '', ''], |
| 80 result); | 80 result); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void testReadLine1() { | 83 void testReadLine1() { |
| 84 var controller = new StreamController(sync: true); | 84 var controller = new StreamController(sync: true); |
| 85 var stream = controller.stream | 85 var stream = controller.stream |
| 86 .transform(new Utf8Decoder()) | 86 .transform(UTF8.decoder) |
| 87 .transform(new LineSplitter()); | 87 .transform(const LineSplitter()); |
| 88 | 88 |
| 89 var stage = 0; | 89 var stage = 0; |
| 90 var done = false; | 90 var done = false; |
| 91 | 91 |
| 92 void stringData(line) { | 92 void stringData(line) { |
| 93 Expect.equals(stage, 0); | 93 Expect.equals(stage, 0); |
| 94 Expect.equals("Line", line); | 94 Expect.equals("Line", line); |
| 95 stage++; | 95 stage++; |
| 96 } | 96 } |
| 97 | 97 |
| 98 void streamClosed() { | 98 void streamClosed() { |
| 99 Expect.equals(1, stage); | 99 Expect.equals(1, stage); |
| 100 done = true; | 100 done = true; |
| 101 } | 101 } |
| 102 | 102 |
| 103 stream.listen( | 103 stream.listen( |
| 104 stringData, | 104 stringData, |
| 105 onDone: streamClosed); | 105 onDone: streamClosed); |
| 106 | 106 |
| 107 // Note: codeUnits is fine. Text is ASCII. | 107 // Note: codeUnits is fine. Text is ASCII. |
| 108 controller.add("Line".codeUnits); | 108 controller.add("Line".codeUnits); |
| 109 controller.close(); | 109 controller.close(); |
| 110 Expect.isTrue(done, 'should be done by now'); | 110 Expect.isTrue(done, 'should be done by now'); |
| 111 } | 111 } |
| 112 | 112 |
| 113 void testReadLine2() { | 113 void testReadLine2() { |
| 114 var controller = new StreamController(sync: true); | 114 var controller = new StreamController(sync: true); |
| 115 | 115 |
| 116 var stream = controller.stream | 116 var stream = controller.stream |
| 117 .transform(new Utf8Decoder()) | 117 .transform(UTF8.decoder) |
| 118 .transform(new LineSplitter()); | 118 .transform(const LineSplitter()); |
| 119 | 119 |
| 120 var expectedLines = ['Line1', 'Line2','Line3', 'Line4', | 120 var expectedLines = ['Line1', 'Line2','Line3', 'Line4', |
| 121 '', '', '', '', '', '', | 121 '', '', '', '', '', '', |
| 122 'Line5', 'Line6']; | 122 'Line5', 'Line6']; |
| 123 | 123 |
| 124 var index = 0; | 124 var index = 0; |
| 125 | 125 |
| 126 stream.listen((line) { | 126 stream.listen((line) { |
| 127 Expect.equals(expectedLines[index++], line); | 127 Expect.equals(expectedLines[index++], line); |
| 128 }); | 128 }); |
| 129 | 129 |
| 130 // Note: codeUnits is fine. Text is ASCII. | 130 // Note: codeUnits is fine. Text is ASCII. |
| 131 controller.add("Line1\nLine2\r\nLine3\rLi".codeUnits); | 131 controller.add("Line1\nLine2\r\nLine3\rLi".codeUnits); |
| 132 controller.add("ne4\n".codeUnits); | 132 controller.add("ne4\n".codeUnits); |
| 133 controller.add("\n\n\r\n\r\n\r\r".codeUnits); | 133 controller.add("\n\n\r\n\r\n\r\r".codeUnits); |
| 134 controller.add("Line5\r".codeUnits); | 134 controller.add("Line5\r".codeUnits); |
| 135 controller.add("\nLine6\n".codeUnits); | 135 controller.add("\nLine6\n".codeUnits); |
| 136 controller.close(); | 136 controller.close(); |
| 137 Expect.equals(expectedLines.length, index); | 137 Expect.equals(expectedLines.length, index); |
| 138 } | 138 } |
| OLD | NEW |