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

Unified Diff: tests/lib/convert/line_splitter_test.dart

Issue 1240623002: Add split function to LineSplitter class in dart:convert. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Addto changelog Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
« sdk/lib/convert/line_splitter.dart ('K') | « sdk/lib/convert/line_splitter.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/lib/convert/line_splitter_test.dart
diff --git a/tests/lib/convert/line_splitter_test.dart b/tests/lib/convert/line_splitter_test.dart
index 2d8f5e09f9c8cb1647cbdb59da7d0f1e1487106e..d9956e0693badb5dd5e624d2dd40f0e6255213af 100644
--- a/tests/lib/convert/line_splitter_test.dart
+++ b/tests/lib/convert/line_splitter_test.dart
@@ -11,9 +11,12 @@ import 'dart:math' as MATH;
void main() {
testSimpleConvert();
+ testSplit();
+ testSplitWithOffsets();
testManyLines();
testReadLine1();
testReadLine2();
+ testChunkedConversion();
}
void testManyLines() {
@@ -136,3 +139,90 @@ void testReadLine2() {
controller.close();
Expect.equals(expectedLines.length, index);
}
+
+
+void testSplit() {
+ var test = """line1
+line2
+line3""";
+
+
+ var result = LineSplitter.split(test).toList();
+
+ Expect.listEquals(['line1', 'line2', 'line3'], result);
+
+ test = "Line1\nLine2\r\nLine3\rLi"
+ "ne4\n"
+ "\n\n\r\n\r\n\r\r";
+
+ result = LineSplitter.split(test).toList();
+
+ Expect.listEquals(
+ ['Line1', 'Line2', 'Line3', 'Line4', '', '', '', '', '', ''],
+ result);
+}
+
+void testSplitWithOffsets() {
+ var test = """line1
+line2
+line3""";
+
+ var result = LineSplitter.split(test, 4).toList();
+ Expect.listEquals(['1', 'line2', 'line3'], result);
+
+ result = LineSplitter.split(test, 5).toList();
+ Expect.listEquals(['', 'line2', 'line3'], result);
+
+ result = LineSplitter.split(test, 6).toList();
+ Expect.listEquals(['line2', 'line3'], result);
+
+ result = LineSplitter.split(test, 0, 8).toList();
+ Expect.listEquals(['line1', 'li'], result);
+
+ result = LineSplitter.split(test, 6, 11).toList();
+ Expect.listEquals(['line2'], result);
+
+ test = "Line1\nLine2\r\nLine3\rLi"
+ "ne4\n"
+ "\n\n\r\n\r\n\r\r";
+
+ result = LineSplitter.split(test).toList();
+
+ Expect.listEquals(
+ ['Line1', 'Line2', 'Line3', 'Line4', '', '', '', '', '', ''],
+ result);
+
+ test = "a\n\nb\r\nc\n\rd\r\re\r\n\nf\r\n";
+ result = LineSplitter.split(test).toList();
+ Expect.listEquals(["a", "", "b", "c", "", "d", "", "e", "", "f"], result);
+}
+
+void testChunkedConversion() {
+ // Test any split of this complex string.
+ var test = "a\n\nb\r\nc\n\rd\r\re\r\n\nf\rg\nh\r\n";
+ var result = ["a", "", "b","c", "", "d", "", "e", "", "f", "g", "h"];
+ for (int i = 0; i < test.length; i++) {
+ var output = [];
+ var splitter = new LineSplitter();
+ var outSink = new ChunkedConversionSink.withCallback(output.addAll);
+ var sink = splitter.startChunkedConversion(outSink);
+ sink.addSlice(test, 0, i, false);
+ sink.addSlice(test, i, test.length, false);
+ sink.close();
+ Expect.listEquals(result, output);
+ }
+
+ // Test the string split into three parts in any way.
+ for (int i = 0; i < test.length; i++) {
+ for (int j = i; j < test.length; j++) {
+ var output = [];
+ var splitter = new LineSplitter();
+ var outSink = new ChunkedConversionSink.withCallback(output.addAll);
+ var sink = splitter.startChunkedConversion(outSink);
+ sink.addSlice(test, 0, i, false);
+ sink.addSlice(test, i, j, false);
+ sink.addSlice(test, j, test.length, true);
+ Expect.listEquals(result, output);
+ }
+ }
+}
« 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