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

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

Issue 189063006: add indent option to cmdline formatter (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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/scanner.dart'; 10 import 'package:analyzer/src/generated/scanner.dart';
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 /// Formatter tests 43 /// Formatter tests
44 group('formatter', () { 44 group('formatter', () {
45 45
46 test('failed parse', () { 46 test('failed parse', () {
47 var formatter = new CodeFormatter(); 47 var formatter = new CodeFormatter();
48 expect(() => formatter.format(CodeKind.COMPILATION_UNIT, '~'), 48 expect(() => formatter.format(CodeKind.COMPILATION_UNIT, '~'),
49 throwsA(new isInstanceOf<FormatterException>())); 49 throwsA(new isInstanceOf<FormatterException>()));
50 }); 50 });
51 51
52 test('indent', () {
53 var original =
54 'class A {\n'
55 ' var z;\n'
56 ' inc(int x) => ++x;\n'
57 ' foo(int x) {\n'
58 ' if (x == 0) {\n'
59 ' return true;\n'
60 ' }\n'
61 ' }\n'
62 '}\n';
63 expectCUFormatsTo(
64 original,
65 original
66 );
67 // expectIndentFormatsTo(3, false,
68 // original,
69 // 'class A {\n'
70 // ' var z;\n'
71 // ' inc(int x) => ++x;\n'
72 // ' foo(int x) {\n'
73 // ' if (x == 0) {\n'
74 // ' return true;\n'
75 // ' }\n'
76 // ' }\n'
77 // '}\n'
78 // );
79 // expectIndentFormatsTo(1, true,
80 // original,
81 // 'class A {\n'
82 // '\tvar z;\n'
83 // '\tinc(int x) => ++x;\n'
84 // '\tfoo(int x) {\n'
85 // '\t\tif (x == 0) {\n'
86 // '\t\t\treturn true;\n'
87 // '\t\t}\n'
88 // '\t}\n'
89 // '}\n'
90 // );
91 });
92
52 test('CU (1)', () { 93 test('CU (1)', () {
53 expectCUFormatsTo( 94 expectCUFormatsTo(
54 'class A {\n' 95 'class A {\n'
55 ' var z;\n' 96 ' var z;\n'
56 ' inc(int x) => ++x;\n' 97 ' inc(int x) => ++x;\n'
57 '}\n', 98 '}\n',
58 'class A {\n' 99 'class A {\n'
59 ' var z;\n' 100 ' var z;\n'
60 ' inc(int x) => ++x;\n' 101 ' inc(int x) => ++x;\n'
61 '}\n' 102 '}\n'
(...skipping 1348 matching lines...) Expand 10 before | Expand all | Expand 10 after
1410 new TokenStreamComparator(null, t1, t2).verifyEquals(); 1451 new TokenStreamComparator(null, t1, t2).verifyEquals();
1411 1452
1412 expectStreamsNotEqual(Token t1, Token t2) => 1453 expectStreamsNotEqual(Token t1, Token t2) =>
1413 expect(() => new TokenStreamComparator(null, t1, t2).verifyEquals(), 1454 expect(() => new TokenStreamComparator(null, t1, t2).verifyEquals(),
1414 throwsA(new isInstanceOf<FormatterException>())); 1455 throwsA(new isInstanceOf<FormatterException>()));
1415 1456
1416 expectCUFormatsTo(src, expected, {transforms: true}) => 1457 expectCUFormatsTo(src, expected, {transforms: true}) =>
1417 expect(formatCU(src, options: new FormatterOptions( 1458 expect(formatCU(src, options: new FormatterOptions(
1418 codeTransforms: transforms)).source, equals(expected)); 1459 codeTransforms: transforms)).source, equals(expected));
1419 1460
1461 expectIndentFormatsTo(spacesPerIndent, tabsForIndent, src, expected) =>
1462 expect(
1463 formatCU(src, options: new FormatterOptions(
1464 spacesPerIndent: spacesPerIndent,
1465 tabsForIndent: tabsForIndent
1466 )).source,
1467 equals(expected));
1468
1420 expectStmtFormatsTo(src, expected, {transforms: true}) => 1469 expectStmtFormatsTo(src, expected, {transforms: true}) =>
1421 expect(formatStatement(src, options: 1470 expect(formatStatement(src, options:
1422 new FormatterOptions(codeTransforms: transforms)), equals(expected)); 1471 new FormatterOptions(codeTransforms: transforms)), equals(expected));
1423 1472
1424 1473
1425 runTests(testFileName, expectClause(input, output)) { 1474 runTests(testFileName, expectClause(input, output)) {
1426 1475
1427 var testIndex = 1; 1476 var testIndex = 1;
1428 var testFile = new File(join(TEST_DATA_DIR, testFileName)); 1477 var testFile = new File(join(TEST_DATA_DIR, testFileName));
1429 var lines = testFile.readAsLinesSync(); 1478 var lines = testFile.readAsLinesSync();
1430 1479
1431 for (var i = 1; i < lines.length; ++i) { 1480 for (var i = 1; i < lines.length; ++i) {
1432 var input = '', expectedOutput = ''; 1481 var input = '', expectedOutput = '';
1433 while(!lines[i].startsWith('<<<')) { 1482 while(!lines[i].startsWith('<<<')) {
1434 input += lines[i++] + '\n'; 1483 input += lines[i++] + '\n';
1435 } 1484 }
1436 while(++i < lines.length && !lines[i].startsWith('>>>')) { 1485 while(++i < lines.length && !lines[i].startsWith('>>>')) {
1437 expectedOutput += lines[i] + '\n'; 1486 expectedOutput += lines[i] + '\n';
1438 } 1487 }
1439 test('test - (${testIndex++})', () { 1488 test('test - (${testIndex++})', () {
1440 expectClause(input, expectedOutput); 1489 expectClause(input, expectedOutput);
1441 }); 1490 });
1442 } 1491 }
1443 } 1492 }
OLDNEW
« pkg/analyzer/bin/formatter.dart ('K') | « pkg/analyzer/bin/formatter.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698