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

Side by Side 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 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 import 'dart:io'; 5 import 'dart:io';
6 6
7 import 'package:path/path.dart'; 7 import 'package:path/path.dart';
8 import 'package:unittest/unittest.dart'; 8 import 'package:unittest/unittest.dart';
9 9
10 import 'package:analyzer/src/generated/java_core.dart' show CharSequence; 10 import 'package:analyzer/src/generated/java_core.dart' show CharSequence;
(...skipping 1159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 expect(line.toString(), equals(' foo')); 1170 expect(line.toString(), equals(' foo'));
1171 }); 1171 });
1172 1172
1173 test('isWhitespace', () { 1173 test('isWhitespace', () {
1174 var line = new Line(indent: 1); 1174 var line = new Line(indent: 1);
1175 expect(line.isWhitespace(), isTrue); 1175 expect(line.isWhitespace(), isTrue);
1176 }); 1176 });
1177 1177
1178 }); 1178 });
1179 1179
1180
1181 /// Writer tests 1180 /// Writer tests
1182 group('writer', () { 1181 group('writer', () {
1183 1182
1184 test('basic print', () { 1183 test('basic print', () {
1185 var writer = new SourceWriter(); 1184 var writer = new SourceWriter();
1186 writer.print('foo'); 1185 writer.print('foo');
1187 writer.print(' '); 1186 writer.print(' ');
1188 writer.print('bar'); 1187 writer.print('bar');
1189 expect(writer.toString(), equals('foo bar')); 1188 expect(writer.toString(), equals('foo bar'));
1190 }); 1189 });
(...skipping 19 matching lines...) Expand all
1210 writer.print('bar'); 1209 writer.print('bar');
1211 writer.unindent(); 1210 writer.unindent();
1212 writer.newline(); 1211 writer.newline();
1213 writer.print('baz'); 1212 writer.print('baz');
1214 expect(writer.toString(), equals('foo\n bar\nbaz')); 1213 expect(writer.toString(), equals('foo\n bar\nbaz'));
1215 }); 1214 });
1216 1215
1217 }); 1216 });
1218 1217
1219 1218
1219
1220 /// Line breaker tests
1221 group('linebreaker', () {
1222
1223 List<Chunk> breakLine(Line line, int maxLength) =>
1224 new SimpleLineBreaker(maxLength).breakLine(line);
1225
1226 Line line(List tokens) {
1227 var line = new Line();
1228 tokens.forEach((t) =>
1229 line.addToken(t is LineToken ? t : new LineToken(t)));
1230 return line;
1231 }
1232
1233 expectTextsEqual(List<Chunk> chunks, List<String> texts) {
1234 expect(chunks.map((chunk) => chunk.toString()), orderedEquals(texts));
1235 }
1236
1237 final SP_1 = new SpaceToken(1, breakWeight: 1);
1238
1239 // 'foo|1|bar|1|baz|1|foo|1|bar|1|baz'
1240 final LINE_1 = line(['foo', SP_1, 'bar', SP_1, 'baz', SP_1,
1241 'foo', SP_1, 'bar', SP_1, 'baz']);
1242
1243 test('breakLine - 1', () {
1244 var chunks = breakLine(LINE_1, 1);
1245 expectTextsEqual(chunks, ['foo', 'bar', 'baz', 'foo', 'bar', 'baz']);
1246 });
1247
1248 test('breakLine - 2', () {
1249 var chunks = breakLine(LINE_1, 4);
1250 expectTextsEqual(chunks, ['foo', 'bar', 'baz', 'foo', 'bar', 'baz']);
1251 });
1252
1253 test('breakLine - 3', () {
1254 var chunks = breakLine(LINE_1, 8);
1255 expectTextsEqual(chunks, ['foo bar', 'baz foo', 'bar baz']);
1256 });
1257
1258 test('breakLine - 4', () {
1259 var chunks = breakLine(LINE_1, 12);
1260 expectTextsEqual(chunks, ['foo bar baz', 'foo bar baz']);
1261 });
1262
1263 });
1264
1220 /// Helper method tests 1265 /// Helper method tests
1221 group('helpers', () { 1266 group('helpers', () {
1222 1267
1223 test('indentString', () { 1268 test('indentString', () {
1224 expect(getIndentString(0), ''); 1269 expect(getIndentString(0), '');
1225 expect(getIndentString(1), ' '); 1270 expect(getIndentString(1), ' ');
1226 expect(getIndentString(4), ' '); 1271 expect(getIndentString(4), ' ');
1227 }); 1272 });
1228 1273
1229 test('indentString (tabbed)', () { 1274 test('indentString (tabbed)', () {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1330 input += lines[i++] + '\n'; 1375 input += lines[i++] + '\n';
1331 } 1376 }
1332 while(++i < lines.length && !lines[i].startsWith('>>>')) { 1377 while(++i < lines.length && !lines[i].startsWith('>>>')) {
1333 expectedOutput += lines[i] + '\n'; 1378 expectedOutput += lines[i] + '\n';
1334 } 1379 }
1335 test('test - (${testIndex++})', () { 1380 test('test - (${testIndex++})', () {
1336 expectClause(input, expectedOutput); 1381 expectClause(input, expectedOutput);
1337 }); 1382 });
1338 } 1383 }
1339 } 1384 }
OLDNEW
« 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