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

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

Issue 22860004: nits from cr 22070003 (Closed) Base URL: http://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 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(new Utf8Decoder())
118 .transform(new LineSplitter()); 118 .transform(new LineSplitter());
119 119
120 var done = false; 120 var lines = ['Line1', 'Line2','Line3', 'Line4',
121 '', '', '', '', '', '',
122 'Line5', 'Line6'];
121 123
122 var stage = 0;
123 var subStage = 0;
124 stream.listen((line) { 124 stream.listen((line) {
125 if (stage == 0) { 125 Expect.equals(lines.removeAt(0), line);
Lasse Reichstein Nielsen 2013/08/13 09:05:55 Tricky. I don't like modifying my expectations. If
kevmoo-old 2013/08/13 18:47:16 Done.
126 if (subStage == 0) { 126 });
127 Expect.equals("Line1", line);
128 subStage++;
129 } else if (subStage == 1) {
130 Expect.equals("Line2", line);
131 subStage++;
132 } else if (subStage == 2) {
133 Expect.equals("Line3", line);
134 subStage = 0;
135 stage++;
136 } else {
137 Expect.fail("Stage 0 failed");
138 }
139 } else if (stage == 1) {
140 if (subStage == 0) {
141 Expect.equals("Line4", line);
142 subStage = 0;
143 stage++;
144 } else {
145 Expect.fail("Stage 1 failed");
146 }
147 } else if (stage == 2) {
148 if (subStage < 4) {
149 // Expect 5 empty lines. As long as the stream is not closed the
150 // final \r cannot be interpreted as a end of line.
151 Expect.equals("", line);
152 subStage++;
153 } else if (subStage == 4) {
154 Expect.equals("", line);
155 subStage = 0;
156 stage++;
157 } else {
158 Expect.fail("Stage 2 failed");
159 }
160 } else if (stage == 3) {
161 if (subStage == 0) {
162 Expect.equals("", line);
163 stage++;
164 } else {
165 Expect.fail("Stage 3 failed");
166 }
167 }
168 }, onDone: () {
169 Expect.equals(4, stage);
170 Expect.equals(0, subStage);
171 done = true;
172 });
173 127
174 // Note: codeUnits is fine. Text is ASCII. 128 // Note: codeUnits is fine. Text is ASCII.
175 controller.add("Line1\nLine2\r\nLine3\rLi".codeUnits); 129 controller.add("Line1\nLine2\r\nLine3\rLi".codeUnits);
176 controller.add("ne4\n".codeUnits); 130 controller.add("ne4\n".codeUnits);
177 controller.add("\n\n\r\n\r\n\r\r".codeUnits); 131 controller.add("\n\n\r\n\r\n\r\r".codeUnits);
132 controller.add("Line5\r".codeUnits);
133 controller.add("\nLine6\n".codeUnits);
178 controller.close(); 134 controller.close();
179 Expect.isTrue(done, 'should be done here...'); 135 Expect.isTrue(lines.isEmpty, 'should be done here...');
Lasse Reichstein Nielsen 2013/08/13 09:05:55 Expect.equals(expectedLines.length, index, "Should
kevmoo-old 2013/08/13 18:47:16 Done.
180 } 136 }
OLDNEW
« sdk/lib/convert/line_splitter.dart ('K') | « sdk/lib/convert/line_splitter.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698