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

Unified Diff: pkg/analyzer/test/services/formatter_test.dart

Issue 132383002: Line-breaking plumbing and bits and pieces. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 11 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
Index: pkg/analyzer/test/services/formatter_test.dart
===================================================================
--- pkg/analyzer/test/services/formatter_test.dart (revision 31664)
+++ pkg/analyzer/test/services/formatter_test.dart (working copy)
@@ -1177,7 +1177,6 @@
});
-
/// Writer tests
group('writer', () {
@@ -1217,6 +1216,52 @@
});
+
+ /// Line breaker tests
+ group('linebreaker', () {
+
+ List<Chunk> breakLine(Line line, int maxLength) =>
+ new SimpleLineBreaker(maxLength).breakLine(line);
+
+ Line line(List tokens) {
+ var line = new Line();
+ tokens.forEach((t) =>
+ line.addToken(t is LineToken ? t : new LineToken(t)));
+ return line;
+ }
+
+ expectTextsEqual(List<Chunk> chunks, List<String> texts) {
+ expect(chunks.map((chunk) => chunk.toString()), orderedEquals(texts));
+ }
+
+ final SP_1 = new SpaceToken(1, breakWeight: 1);
+
+ // 'foo|1|bar|1|baz|1|foo|1|bar|1|baz'
+ final LINE_1 = line(['foo', SP_1, 'bar', SP_1, 'baz', SP_1,
+ 'foo', SP_1, 'bar', SP_1, 'baz']);
+
+ test('breakLine - 1', () {
+ var chunks = breakLine(LINE_1, 1);
+ expectTextsEqual(chunks, ['foo', 'bar', 'baz', 'foo', 'bar', 'baz']);
+ });
+
+ test('breakLine - 2', () {
+ var chunks = breakLine(LINE_1, 4);
+ expectTextsEqual(chunks, ['foo', 'bar', 'baz', 'foo', 'bar', 'baz']);
+ });
+
+ test('breakLine - 3', () {
+ var chunks = breakLine(LINE_1, 8);
+ expectTextsEqual(chunks, ['foo bar', 'baz foo', 'bar baz']);
+ });
+
+ test('breakLine - 4', () {
+ var chunks = breakLine(LINE_1, 12);
+ expectTextsEqual(chunks, ['foo bar baz', 'foo bar baz']);
+ });
+
+ });
+
/// Helper method tests
group('helpers', () {
« pkg/analyzer/lib/src/services/writer.dart ('K') | « pkg/analyzer/lib/src/services/writer.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698