| 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 1219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1230 var line = new Line(); | 1230 var line = new Line(); |
| 1231 tokens.forEach((t) => | 1231 tokens.forEach((t) => |
| 1232 line.addToken(t is LineToken ? t : new LineToken(t))); | 1232 line.addToken(t is LineToken ? t : new LineToken(t))); |
| 1233 return line; | 1233 return line; |
| 1234 } | 1234 } |
| 1235 | 1235 |
| 1236 expectTextsEqual(List<Chunk> chunks, List<String> texts) { | 1236 expectTextsEqual(List<Chunk> chunks, List<String> texts) { |
| 1237 expect(chunks.map((chunk) => chunk.toString()), orderedEquals(texts)); | 1237 expect(chunks.map((chunk) => chunk.toString()), orderedEquals(texts)); |
| 1238 } | 1238 } |
| 1239 | 1239 |
| 1240 expectTokensEqual(List<LineToken> tokens, List<String> texts) { |
| 1241 expect(tokens.map((token) => token.toString()), orderedEquals(texts)); |
| 1242 } |
| 1243 |
| 1244 |
| 1240 final SP_1 = new SpaceToken(1, breakWeight: 1); | 1245 final SP_1 = new SpaceToken(1, breakWeight: 1); |
| 1241 | 1246 |
| 1242 // 'foo|1|bar|1|baz|1|foo|1|bar|1|baz' | 1247 // 'foo|1|bar|1|baz|1|foo|1|bar|1|baz' |
| 1243 final LINE_1 = line(['foo', SP_1, 'bar', SP_1, 'baz', SP_1, | 1248 final LINE_1 = line(['foo', SP_1, 'bar', SP_1, 'baz', SP_1, |
| 1244 'foo', SP_1, 'bar', SP_1, 'baz']); | 1249 'foo', SP_1, 'bar', SP_1, 'baz']); |
| 1245 | 1250 |
| 1246 // ' foo|1|bar|1|baz|1|foo|1|bar|1|baz' | 1251 // ' 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, | 1252 final LINE_2 = line([' foo', SP_1, 'bar', SP_1, 'baz', SP_1, |
| 1248 'foo', SP_1, 'bar', SP_1, 'baz']); | 1253 'foo', SP_1, 'bar', SP_1, 'baz']); |
| 1249 | 1254 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1303 expect(isWhitespace('foo '), false); | 1308 expect(isWhitespace('foo '), false); |
| 1304 expect(isWhitespace(' foo '), false); | 1309 expect(isWhitespace(' foo '), false); |
| 1305 expect(isWhitespace(' '), true); | 1310 expect(isWhitespace(' '), true); |
| 1306 expect(isWhitespace(' '), true); | 1311 expect(isWhitespace(' '), true); |
| 1307 expect(isWhitespace('\t'), true); | 1312 expect(isWhitespace('\t'), true); |
| 1308 expect(isWhitespace('\t\t'), true); | 1313 expect(isWhitespace('\t\t'), true); |
| 1309 expect(isWhitespace('\n'), true); | 1314 expect(isWhitespace('\n'), true); |
| 1310 expect(isWhitespace('\r'), true); | 1315 expect(isWhitespace('\r'), true); |
| 1311 }); | 1316 }); |
| 1312 | 1317 |
| 1318 test('preprocess - 1', () { |
| 1319 var tokens = line(['f', 'o', 'o', SP_1, 'b', 'a', 'r']).tokens; |
| 1320 var processed = SimpleLineBreaker.preprocess(tokens); |
| 1321 expectTokensEqual(processed, ['foo', ' ', 'bar']); |
| 1322 }); |
| 1323 |
| 1324 test('preprocess - 2', () { |
| 1325 var tokens = line(['f', 'o', 'o', SP_1, SP_1, 'b', 'a', 'r']).tokens; |
| 1326 var processed = SimpleLineBreaker.preprocess(tokens); |
| 1327 expectTokensEqual(processed, ['foo', ' ', ' ', 'bar']); |
| 1328 }); |
| 1329 |
| 1330 test('preprocess - 3', () { |
| 1331 var tokens = line(['f', 'o', 'o', SP_1, 'b', 'a', 'r', SP_1]).tokens; |
| 1332 var processed = SimpleLineBreaker.preprocess(tokens); |
| 1333 expectTokensEqual(processed, ['foo', ' ', 'bar', ' ']); |
| 1334 }); |
| 1335 |
| 1313 }); | 1336 }); |
| 1314 | 1337 |
| 1315 /// Helper method tests | 1338 /// Helper method tests |
| 1316 group('helpers', () { | 1339 group('helpers', () { |
| 1317 | 1340 |
| 1318 test('indentString', () { | 1341 test('indentString', () { |
| 1319 expect(getIndentString(0), ''); | 1342 expect(getIndentString(0), ''); |
| 1320 expect(getIndentString(1), ' '); | 1343 expect(getIndentString(1), ' '); |
| 1321 expect(getIndentString(4), ' '); | 1344 expect(getIndentString(4), ' '); |
| 1322 }); | 1345 }); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1425 input += lines[i++] + '\n'; | 1448 input += lines[i++] + '\n'; |
| 1426 } | 1449 } |
| 1427 while(++i < lines.length && !lines[i].startsWith('>>>')) { | 1450 while(++i < lines.length && !lines[i].startsWith('>>>')) { |
| 1428 expectedOutput += lines[i] + '\n'; | 1451 expectedOutput += lines[i] + '\n'; |
| 1429 } | 1452 } |
| 1430 test('test - (${testIndex++})', () { | 1453 test('test - (${testIndex++})', () { |
| 1431 expectClause(input, expectedOutput); | 1454 expectClause(input, expectedOutput); |
| 1432 }); | 1455 }); |
| 1433 } | 1456 } |
| 1434 } | 1457 } |
| OLD | NEW |