| 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 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 1205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1216 }); | 1216 }); |
| 1217 | 1217 |
| 1218 | 1218 |
| 1219 | 1219 |
| 1220 /// Line breaker tests | 1220 /// Line breaker tests |
| 1221 group('linebreaker', () { | 1221 group('linebreaker', () { |
| 1222 | 1222 |
| 1223 List<Chunk> breakLine(Line line, int maxLength) => | 1223 List<Chunk> breakLine(Line line, int maxLength) => |
| 1224 new SimpleLineBreaker(maxLength).breakLine(line); | 1224 new SimpleLineBreaker(maxLength).breakLine(line); |
| 1225 | 1225 |
| 1226 String printLine(Line line, int maxLength) => |
| 1227 new SimpleLineBreaker(maxLength).printLine(line); |
| 1228 |
| 1226 Line line(List tokens) { | 1229 Line line(List tokens) { |
| 1227 var line = new Line(); | 1230 var line = new Line(); |
| 1228 tokens.forEach((t) => | 1231 tokens.forEach((t) => |
| 1229 line.addToken(t is LineToken ? t : new LineToken(t))); | 1232 line.addToken(t is LineToken ? t : new LineToken(t))); |
| 1230 return line; | 1233 return line; |
| 1231 } | 1234 } |
| 1232 | 1235 |
| 1233 expectTextsEqual(List<Chunk> chunks, List<String> texts) { | 1236 expectTextsEqual(List<Chunk> chunks, List<String> texts) { |
| 1234 expect(chunks.map((chunk) => chunk.toString()), orderedEquals(texts)); | 1237 expect(chunks.map((chunk) => chunk.toString()), orderedEquals(texts)); |
| 1235 } | 1238 } |
| 1236 | 1239 |
| 1237 final SP_1 = new SpaceToken(1, breakWeight: 1); | 1240 final SP_1 = new SpaceToken(1, breakWeight: 1); |
| 1238 | 1241 |
| 1239 // 'foo|1|bar|1|baz|1|foo|1|bar|1|baz' | 1242 // '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, | 1243 final LINE_1 = line(['foo', SP_1, 'bar', SP_1, 'baz', SP_1, |
| 1241 'foo', SP_1, 'bar', SP_1, 'baz']); | 1244 'foo', SP_1, 'bar', SP_1, 'baz']); |
| 1242 | 1245 |
| 1246 // ' foo|1|bar|1|baz|1|foo|1|bar|1|baz' |
| 1247 final LINE_2 = line([' foo', SP_1, 'bar', SP_1, 'baz', SP_1, |
| 1248 'foo', SP_1, 'bar', SP_1, 'baz']); |
| 1249 |
| 1250 test('breakLine - 0', () { |
| 1251 var chunks = breakLine(line([' foo']), 8); |
| 1252 expectTextsEqual(chunks, [' foo']); |
| 1253 }); |
| 1254 |
| 1243 test('breakLine - 1', () { | 1255 test('breakLine - 1', () { |
| 1244 var chunks = breakLine(LINE_1, 1); | 1256 var chunks = breakLine(LINE_1, 1); |
| 1245 expectTextsEqual(chunks, ['foo', 'bar', 'baz', 'foo', 'bar', 'baz']); | 1257 expectTextsEqual(chunks, ['foo', 'bar', 'baz', 'foo', 'bar', 'baz']); |
| 1246 }); | 1258 }); |
| 1247 | 1259 |
| 1248 test('breakLine - 2', () { | 1260 test('breakLine - 2', () { |
| 1249 var chunks = breakLine(LINE_1, 4); | 1261 var chunks = breakLine(LINE_1, 4); |
| 1250 expectTextsEqual(chunks, ['foo', 'bar', 'baz', 'foo', 'bar', 'baz']); | 1262 expectTextsEqual(chunks, ['foo', 'bar', 'baz', 'foo', 'bar', 'baz']); |
| 1251 }); | 1263 }); |
| 1252 | 1264 |
| 1253 test('breakLine - 3', () { | 1265 test('breakLine - 3', () { |
| 1254 var chunks = breakLine(LINE_1, 8); | 1266 var chunks = breakLine(LINE_1, 8); |
| 1255 expectTextsEqual(chunks, ['foo bar', 'baz foo', 'bar baz']); | 1267 expectTextsEqual(chunks, ['foo bar', 'baz foo', 'bar baz']); |
| 1256 }); | 1268 }); |
| 1257 | 1269 |
| 1258 test('breakLine - 4', () { | 1270 test('breakLine - 4', () { |
| 1259 var chunks = breakLine(LINE_1, 12); | 1271 var chunks = breakLine(LINE_1, 12); |
| 1260 expectTextsEqual(chunks, ['foo bar baz', 'foo bar baz']); | 1272 expectTextsEqual(chunks, ['foo bar baz', 'foo bar baz']); |
| 1261 }); | 1273 }); |
| 1262 | 1274 |
| 1275 test('breakLine - 5', () { |
| 1276 var chunks = breakLine(LINE_2, 16); |
| 1277 expectTextsEqual(chunks, [' foo bar baz', 'foo bar baz']); |
| 1278 }); |
| 1279 |
| 1280 test('printLine - 1', () { |
| 1281 var line = printLine(LINE_1, 1); |
| 1282 expect(line, 'foo\nbar\nbaz\nfoo\nbar\nbaz'); |
| 1283 }); |
| 1284 |
| 1285 test('printLine - 2', () { |
| 1286 var line = printLine(LINE_1, 4); |
| 1287 expect(line, 'foo\nbar\nbaz\nfoo\nbar\nbaz'); |
| 1288 }); |
| 1289 |
| 1290 test('printLine - 3', () { |
| 1291 var line = printLine(LINE_1, 8); |
| 1292 expect(line, 'foo bar\nbaz foo\nbar baz'); |
| 1293 }); |
| 1294 |
| 1295 test('printLine - 4', () { |
| 1296 var line = printLine(LINE_1, 12); |
| 1297 expect(line, 'foo bar baz\nfoo bar baz'); |
| 1298 }); |
| 1299 |
| 1263 }); | 1300 }); |
| 1264 | 1301 |
| 1265 /// Helper method tests | 1302 /// Helper method tests |
| 1266 group('helpers', () { | 1303 group('helpers', () { |
| 1267 | 1304 |
| 1268 test('indentString', () { | 1305 test('indentString', () { |
| 1269 expect(getIndentString(0), ''); | 1306 expect(getIndentString(0), ''); |
| 1270 expect(getIndentString(1), ' '); | 1307 expect(getIndentString(1), ' '); |
| 1271 expect(getIndentString(4), ' '); | 1308 expect(getIndentString(4), ' '); |
| 1272 }); | 1309 }); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1375 input += lines[i++] + '\n'; | 1412 input += lines[i++] + '\n'; |
| 1376 } | 1413 } |
| 1377 while(++i < lines.length && !lines[i].startsWith('>>>')) { | 1414 while(++i < lines.length && !lines[i].startsWith('>>>')) { |
| 1378 expectedOutput += lines[i] + '\n'; | 1415 expectedOutput += lines[i] + '\n'; |
| 1379 } | 1416 } |
| 1380 test('test - (${testIndex++})', () { | 1417 test('test - (${testIndex++})', () { |
| 1381 expectClause(input, expectedOutput); | 1418 expectClause(input, expectedOutput); |
| 1382 }); | 1419 }); |
| 1383 } | 1420 } |
| 1384 } | 1421 } |
| OLD | NEW |