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

Side by Side Diff: pkg/analyzer/test/services/formatter_test.dart

Issue 477373002: Improve formatting of variable declarations/assignments. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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
« no previous file with comments | « pkg/analyzer/test/services/data/wrap_tests.data ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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 1344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1355 } 1355 }
1356 1356
1357 expectTokensEqual(List<LineToken> tokens, List<String> texts) { 1357 expectTokensEqual(List<LineToken> tokens, List<String> texts) {
1358 expect(tokens.map((token) => token.toString()), orderedEquals(texts)); 1358 expect(tokens.map((token) => token.toString()), orderedEquals(texts));
1359 } 1359 }
1360 1360
1361 1361
1362 final SP_1 = new SpaceToken(1, breakWeight: DEFAULT_SPACE_WEIGHT); 1362 final SP_1 = new SpaceToken(1, breakWeight: DEFAULT_SPACE_WEIGHT);
1363 final SP_w1 = new SpaceToken(1, breakWeight: 1); 1363 final SP_w1 = new SpaceToken(1, breakWeight: 1);
1364 final SP_w2 = new SpaceToken(1, breakWeight: 2); 1364 final SP_w2 = new SpaceToken(1, breakWeight: 2);
1365 final SP_i = new SpaceToken(1, breakWeight: SINGLE_SPACE_WEIGHT);
1365 1366
1366 // 'foo|1|bar|1|baz|1|foo|1|bar|1|baz' 1367 // 'foo|1|bar|1|baz|1|foo|1|bar|1|baz'
1367 final LINE_1 = line(['foo', SP_1, 'bar', SP_1, 'baz', SP_1, 1368 final LINE_1 = line(['foo', SP_1, 'bar', SP_1, 'baz', SP_1,
1368 'foo', SP_1, 'bar', SP_1, 'baz']); 1369 'foo', SP_1, 'bar', SP_1, 'baz']);
1369 1370
1370 // ' foo|1|bar|1|baz|1|foo|1|bar|1|baz' 1371 // ' foo|1|bar|1|baz|1|foo|1|bar|1|baz'
1371 final LINE_2 = line([' foo', SP_1, 'bar', SP_1, 'baz', SP_1, 1372 final LINE_2 = line([' foo', SP_1, 'bar', SP_1, 'baz', SP_1,
1372 'foo', SP_1, 'bar', SP_1, 'baz']); 1373 'foo', SP_1, 'bar', SP_1, 'baz']);
1373 1374
1374 test('breakLine - 0', () { 1375 test('breakLine - 0', () {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1430 1431
1431 test('printLine - use weight - 1', () { 1432 test('printLine - use weight - 1', () {
1432 var source = line( 1433 var source = line(
1433 ['111111', SP_w2, '222222', SP_w1, 1434 ['111111', SP_w2, '222222', SP_w1,
1434 '333333', SP_w2, '444444', SP_w1, 1435 '333333', SP_w2, '444444', SP_w1,
1435 '555555', SP_w2, '666666']); 1436 '555555', SP_w2, '666666']);
1436 var result = printLine(source, 20); 1437 var result = printLine(source, 20);
1437 expect(result, '111111 222222\n 333333 444444\n 555555 666666'); 1438 expect(result, '111111 222222\n 333333 444444\n 555555 666666');
1438 }); 1439 });
1439 1440
1441 test('printLine - use weight - initializer - success', () {
1442 var source = line(
1443 ['111111', SP_i, '2222', SP_w1,
1444 '3333', SP_w1, '4444']);
1445 var result = printLine(source, 20);
1446 expect(result, '111111\n 2222 3333 4444');
1447 });
1448
1449 test('printLine - use weight - initializer - rest too long', () {
1450 var source = line(
1451 ['111', SP_i, '222', SP_w1,
1452 '333', SP_w1, '444', SP_w1, '555', SP_w1, '666']);
1453 var result = printLine(source, 15);
1454 expect(result, '111 222\n 333\n 444\n 555\n 666');
1455 });
1456
1457 test('printLine - use weight - initializer - decl/rest too long', () {
1458 var source = line(
1459 ['111', SP_i, '2222222222222', SP_w1,
1460 '333', SP_w1, '444', SP_w1, '555', SP_w1, '666']);
1461 var result = printLine(source, 15);
1462 expect(result, '111\n 2222222222222\n'
1463 ' 333\n 444\n 555\n 666');
1464 });
1465
1440 test('isWhitespace', () { 1466 test('isWhitespace', () {
1441 expect(isWhitespace('foo'), false); 1467 expect(isWhitespace('foo'), false);
1442 expect(isWhitespace(' foo'), false); 1468 expect(isWhitespace(' foo'), false);
1443 expect(isWhitespace('foo '), false); 1469 expect(isWhitespace('foo '), false);
1444 expect(isWhitespace(' foo '), false); 1470 expect(isWhitespace(' foo '), false);
1445 expect(isWhitespace(' '), true); 1471 expect(isWhitespace(' '), true);
1446 expect(isWhitespace(' '), true); 1472 expect(isWhitespace(' '), true);
1447 expect(isWhitespace('\t'), true); 1473 expect(isWhitespace('\t'), true);
1448 expect(isWhitespace('\t\t'), true); 1474 expect(isWhitespace('\t\t'), true);
1449 expect(isWhitespace('\n'), true); 1475 expect(isWhitespace('\n'), true);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1572 spacesPerIndent: spacesPerIndent, 1598 spacesPerIndent: spacesPerIndent,
1573 tabsForIndent: tabsForIndent 1599 tabsForIndent: tabsForIndent
1574 )).source, 1600 )).source,
1575 equals(expected)); 1601 equals(expected));
1576 1602
1577 expectStmtFormatsTo(src, expected, {transforms: true}) => 1603 expectStmtFormatsTo(src, expected, {transforms: true}) =>
1578 expect(formatStatement(src, options: 1604 expect(formatStatement(src, options:
1579 new FormatterOptions(codeTransforms: transforms)), equals(expected)); 1605 new FormatterOptions(codeTransforms: transforms)), equals(expected));
1580 1606
1581 1607
1582 runTests(testFileName, expectClause(input, output)) { 1608 runTests(testFileName, expectClause(String input, String output)) {
1583
1584 var testIndex = 1; 1609 var testIndex = 1;
1585 var testFile = new File(join(TEST_DATA_DIR, testFileName)); 1610 var testFile = new File(join(TEST_DATA_DIR, testFileName));
1586 var lines = testFile.readAsLinesSync(); 1611 var lines = testFile.readAsLinesSync();
1587 for (var i = 1; i < lines.length; ++i) { 1612 for (var i = 1; i < lines.length; ++i) {
1588 var input = '', expectedOutput = ''; 1613 var input = '', expectedOutput = '';
1589 while(!lines[i].startsWith('<<<')) { 1614 while(!lines[i].startsWith('<<<')) {
1590 input += lines[i++] + '\n'; 1615 input += lines[i++] + '\n';
1591 } 1616 }
1592 while(++i < lines.length && !lines[i].startsWith('>>>')) { 1617 while(++i < lines.length && !lines[i].startsWith('>>>')) {
1593 expectedOutput += lines[i] + '\n'; 1618 expectedOutput += lines[i] + '\n';
1594 } 1619 }
1595 test('test - (${testIndex++})', () { 1620 test('test - (${testIndex++})', () {
1596 expectClause(input, expectedOutput); 1621 expectClause(input, expectedOutput);
1597 }); 1622 });
1598 } 1623 }
1599 } 1624 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/services/data/wrap_tests.data ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698