| 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 library formatter_test; | 5 library formatter_test; |
| 6 | 6 |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 | 8 |
| 9 import 'package:path/path.dart'; | 9 import 'package:path/path.dart'; |
| 10 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 }); | 35 }); |
| 36 }); | 36 }); |
| 37 | 37 |
| 38 /// Data-driven Style Guide acceptance tests | 38 /// Data-driven Style Guide acceptance tests |
| 39 group('style_guide_tests.data', () { | 39 group('style_guide_tests.data', () { |
| 40 runTests('style_guide_tests.data', (input, expectedOutput) { | 40 runTests('style_guide_tests.data', (input, expectedOutput) { |
| 41 expectCUFormatsTo(input, expectedOutput); | 41 expectCUFormatsTo(input, expectedOutput); |
| 42 }); | 42 }); |
| 43 }); | 43 }); |
| 44 | 44 |
| 45 /// Data-driven wrapping tests |
| 46 group('wrap_tests.data', () { |
| 47 runTests('wrap_tests.data', (input, expectedOutput) { |
| 48 expectCUFormatsTo(input, expectedOutput); |
| 49 }); |
| 50 }); |
| 51 |
| 45 /// Formatter tests | 52 /// Formatter tests |
| 46 group('formatter', () { | 53 group('formatter', () { |
| 47 | 54 |
| 48 test('failed parse', () { | 55 test('failed parse', () { |
| 49 var formatter = new CodeFormatter(); | 56 var formatter = new CodeFormatter(); |
| 50 expect(() => formatter.format(CodeKind.COMPILATION_UNIT, '~'), | 57 expect(() => formatter.format(CodeKind.COMPILATION_UNIT, '~'), |
| 51 throwsA(new isInstanceOf<FormatterException>())); | 58 throwsA(new isInstanceOf<FormatterException>())); |
| 52 }); | 59 }); |
| 53 | 60 |
| 54 test('indent', () { | 61 test('indent', () { |
| (...skipping 1269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1324 | 1331 |
| 1325 | 1332 |
| 1326 | 1333 |
| 1327 /// Line breaker tests | 1334 /// Line breaker tests |
| 1328 group('linebreaker', () { | 1335 group('linebreaker', () { |
| 1329 | 1336 |
| 1330 List<Chunk> breakLine(Line line, int maxLength) => | 1337 List<Chunk> breakLine(Line line, int maxLength) => |
| 1331 new SimpleLineBreaker(maxLength).breakLine(line); | 1338 new SimpleLineBreaker(maxLength).breakLine(line); |
| 1332 | 1339 |
| 1333 String printLine(Line line, int maxLength) => | 1340 String printLine(Line line, int maxLength) => |
| 1334 new SimpleLineBreaker(maxLength).printLine(line); | 1341 new SimpleLineBreaker( |
| 1342 maxLength, |
| 1343 (n) => new List.filled(n, ' ').join() |
| 1344 ).printLine(line); |
| 1335 | 1345 |
| 1336 Line line(List tokens) { | 1346 Line line(List tokens) { |
| 1337 var line = new Line(); | 1347 var line = new Line(); |
| 1338 tokens.forEach((t) => | 1348 tokens.forEach((t) => |
| 1339 line.addToken(t is LineToken ? t : new LineToken(t))); | 1349 line.addToken(t is LineToken ? t : new LineToken(t))); |
| 1340 return line; | 1350 return line; |
| 1341 } | 1351 } |
| 1342 | 1352 |
| 1343 expectTextsEqual(List<Chunk> chunks, List<String> texts) { | 1353 expectTextsEqual(List<Chunk> chunks, List<String> texts) { |
| 1344 expect(chunks.map((chunk) => chunk.toString()), orderedEquals(texts)); | 1354 expect(chunks.map((chunk) => chunk.toString()), orderedEquals(texts)); |
| 1345 } | 1355 } |
| 1346 | 1356 |
| 1347 expectTokensEqual(List<LineToken> tokens, List<String> texts) { | 1357 expectTokensEqual(List<LineToken> tokens, List<String> texts) { |
| 1348 expect(tokens.map((token) => token.toString()), orderedEquals(texts)); | 1358 expect(tokens.map((token) => token.toString()), orderedEquals(texts)); |
| 1349 } | 1359 } |
| 1350 | 1360 |
| 1351 | 1361 |
| 1352 final SP_1 = new SpaceToken(1, breakWeight: 1); | 1362 final SP_1 = new SpaceToken(1, breakWeight: DEFAULT_SPACE_WEIGHT); |
| 1363 final SP_w1 = new SpaceToken(1, breakWeight: 1); |
| 1364 final SP_w2 = new SpaceToken(1, breakWeight: 2); |
| 1353 | 1365 |
| 1354 // 'foo|1|bar|1|baz|1|foo|1|bar|1|baz' | 1366 // 'foo|1|bar|1|baz|1|foo|1|bar|1|baz' |
| 1355 final LINE_1 = line(['foo', SP_1, 'bar', SP_1, 'baz', SP_1, | 1367 final LINE_1 = line(['foo', SP_1, 'bar', SP_1, 'baz', SP_1, |
| 1356 'foo', SP_1, 'bar', SP_1, 'baz']); | 1368 'foo', SP_1, 'bar', SP_1, 'baz']); |
| 1357 | 1369 |
| 1358 // ' foo|1|bar|1|baz|1|foo|1|bar|1|baz' | 1370 // ' foo|1|bar|1|baz|1|foo|1|bar|1|baz' |
| 1359 final LINE_2 = line([' foo', SP_1, 'bar', SP_1, 'baz', SP_1, | 1371 final LINE_2 = line([' foo', SP_1, 'bar', SP_1, 'baz', SP_1, |
| 1360 'foo', SP_1, 'bar', SP_1, 'baz']); | 1372 'foo', SP_1, 'bar', SP_1, 'baz']); |
| 1361 | 1373 |
| 1362 test('breakLine - 0', () { | 1374 test('breakLine - 0', () { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1382 test('breakLine - 4', () { | 1394 test('breakLine - 4', () { |
| 1383 var chunks = breakLine(LINE_1, 12); | 1395 var chunks = breakLine(LINE_1, 12); |
| 1384 expectTextsEqual(chunks, ['foo bar baz', 'foo bar baz']); | 1396 expectTextsEqual(chunks, ['foo bar baz', 'foo bar baz']); |
| 1385 }); | 1397 }); |
| 1386 | 1398 |
| 1387 test('breakLine - 5', () { | 1399 test('breakLine - 5', () { |
| 1388 var chunks = breakLine(LINE_2, 16); | 1400 var chunks = breakLine(LINE_2, 16); |
| 1389 expectTextsEqual(chunks, [' foo bar baz', 'foo bar baz']); | 1401 expectTextsEqual(chunks, [' foo bar baz', 'foo bar baz']); |
| 1390 }); | 1402 }); |
| 1391 | 1403 |
| 1404 test('breakLine - use weights - 1', () { |
| 1405 var source = line(['111', SP_w2, '222', SP_w1, '333', SP_w2, |
| 1406 '444', SP_w1, '555', SP_w2, '666']); |
| 1407 var chunks = breakLine(source, 12); |
| 1408 expectTextsEqual(chunks, ['111 222', '333 444', '555 666']); |
| 1409 }); |
| 1410 |
| 1392 test('printLine - 1', () { | 1411 test('printLine - 1', () { |
| 1393 var line = printLine(LINE_1, 1); | 1412 var line = printLine(LINE_1, 1); |
| 1394 expect(line, 'foo\nbar\nbaz\nfoo\nbar\nbaz'); | 1413 expect(line, 'foo\n bar\n baz\n foo\n bar\n baz'); |
| 1395 }); | 1414 }); |
| 1396 | 1415 |
| 1397 test('printLine - 2', () { | 1416 test('printLine - 2', () { |
| 1398 var line = printLine(LINE_1, 4); | 1417 var line = printLine(LINE_1, 4); |
| 1399 expect(line, 'foo\nbar\nbaz\nfoo\nbar\nbaz'); | 1418 expect(line, 'foo\n bar\n baz\n foo\n bar\n baz'); |
| 1400 }); | 1419 }); |
| 1401 | 1420 |
| 1402 test('printLine - 3', () { | 1421 test('printLine - 3', () { |
| 1403 var line = printLine(LINE_1, 8); | 1422 var line = printLine(LINE_1, 8); |
| 1404 expect(line, 'foo bar\nbaz foo\nbar baz'); | 1423 expect(line, 'foo bar\n baz foo\n bar baz'); |
| 1405 }); | 1424 }); |
| 1406 | 1425 |
| 1407 test('printLine - 4', () { | 1426 test('printLine - 4', () { |
| 1408 var line = printLine(LINE_1, 12); | 1427 var line = printLine(LINE_1, 12); |
| 1409 expect(line, 'foo bar baz\nfoo bar baz'); | 1428 expect(line, 'foo bar baz\n foo bar baz'); |
| 1429 }); |
| 1430 |
| 1431 test('printLine - use weight - 1', () { |
| 1432 var source = line( |
| 1433 ['111111', SP_w2, '222222', SP_w1, |
| 1434 '333333', SP_w2, '444444', SP_w1, |
| 1435 '555555', SP_w2, '666666']); |
| 1436 var result = printLine(source, 20); |
| 1437 expect(result, '111111 222222\n 333333 444444\n 555555 666666'); |
| 1410 }); | 1438 }); |
| 1411 | 1439 |
| 1412 test('isWhitespace', () { | 1440 test('isWhitespace', () { |
| 1413 expect(isWhitespace('foo'), false); | 1441 expect(isWhitespace('foo'), false); |
| 1414 expect(isWhitespace(' foo'), false); | 1442 expect(isWhitespace(' foo'), false); |
| 1415 expect(isWhitespace('foo '), false); | 1443 expect(isWhitespace('foo '), false); |
| 1416 expect(isWhitespace(' foo '), false); | 1444 expect(isWhitespace(' foo '), false); |
| 1417 expect(isWhitespace(' '), true); | 1445 expect(isWhitespace(' '), true); |
| 1418 expect(isWhitespace(' '), true); | 1446 expect(isWhitespace(' '), true); |
| 1419 expect(isWhitespace('\t'), true); | 1447 expect(isWhitespace('\t'), true); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1562 input += lines[i++] + '\n'; | 1590 input += lines[i++] + '\n'; |
| 1563 } | 1591 } |
| 1564 while(++i < lines.length && !lines[i].startsWith('>>>')) { | 1592 while(++i < lines.length && !lines[i].startsWith('>>>')) { |
| 1565 expectedOutput += lines[i] + '\n'; | 1593 expectedOutput += lines[i] + '\n'; |
| 1566 } | 1594 } |
| 1567 test('test - (${testIndex++})', () { | 1595 test('test - (${testIndex++})', () { |
| 1568 expectClause(input, expectedOutput); | 1596 expectClause(input, expectedOutput); |
| 1569 }); | 1597 }); |
| 1570 } | 1598 } |
| 1571 } | 1599 } |
| OLD | NEW |