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

Unified Diff: pkg/analyzer_experimental/test/services/formatter_test.dart

Issue 23440011: Improved comment handling (and misc. formatter fixes). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer_experimental/test/services/formatter_test.dart
===================================================================
--- pkg/analyzer_experimental/test/services/formatter_test.dart (revision 26740)
+++ pkg/analyzer_experimental/test/services/formatter_test.dart (working copy)
@@ -68,21 +68,59 @@
);
});
+ test('CU - EOL comments', () {
+ expectCUFormatsTo(
+ '//comment one\n\n'
+ '//comment two\n\n',
+ '//comment one\n\n'
+ '//comment two\n\n'
+ );
+ expectCUFormatsTo(
+ 'library foo;\n'
+ '\n'
+ '//comment one\n'
+ '\n'
+ 'class C {\n'
+ '}\n',
+ 'library foo;\n'
+ '\n'
+ '//comment one\n'
+ '\n'
+ 'class C {\n'
+ '}\n'
+ );
+ expectCUFormatsTo(
+ 'library foo;\n'
+ '\n'
+ '//comment one\n'
+ '\n'
+ '//comment two\n'
+ '\n'
+ 'class C {\n'
+ '}\n',
+ 'library foo;\n'
+ '\n'
+ '//comment one\n'
+ '\n'
+ '//comment two\n'
+ '\n'
+ 'class C {\n'
+ '}\n'
+ );
+ });
-// test('CU - comments', () {
-// expectCUFormatsTo(
-// 'library foo;\n'
-// '\n'
-// '//comment one\n\n'
-// '//comment two\n\n'
-// 'class C {\n}\n',
-// 'library foo;\n'
-// '\n'
-// '//comment one\n\n'
-// '//comment two\n\n'
-// 'class C {\n}\n'
-// );
-// });
+ test('CU - nested functions', () {
+ expectCUFormatsTo(
+ 'x() {\n'
+ ' y() {\n'
+ ' }\n'
+ '}\n',
+ 'x() {\n'
+ ' y() {\n'
+ ' }\n'
+ '}\n'
+ );
+ });
test('CU - top level', () {
expectCUFormatsTo(
@@ -116,6 +154,12 @@
'foo() {\n'
'}\n'
);
+ expectCUFormatsTo(
+ 'library a; class B { }',
+ 'library a;\n'
+ 'class B {\n'
+ '}'
+ );
});
test('CU - method invocations', () {
@@ -277,6 +321,92 @@
);
});
+ test('CU - Block comments', () {
+ expectCUFormatsTo(
+ '/** Old school class comment */\n'
+ 'class C {\n'
+ ' /** Foo! */ int foo() => 42;\n'
+ '}\n',
+ '/** Old school class comment */\n'
+ 'class C {\n'
+ ' /** Foo! */ int foo() => 42;\n'
+ '}\n'
+ );
+ expectCUFormatsTo(
+ 'library foo;\n'
+ 'class C /* is cool */ {\n'
+ ' /* int */ foo() => 42;\n'
+ '}\n',
+ 'library foo;\n'
+ 'class C /* is cool */ {\n'
+ ' /* int */ foo() => 42;\n'
+ '}\n'
+ );
+ expectCUFormatsTo(
+ 'library foo;\n'
+ '/* A long\n'
+ ' * Comment\n'
+ '*/\n'
+ 'class C /* is cool */ {\n'
+ ' /* int */ foo() => 42;\n'
+ '}\n',
+ 'library foo;\n'
+ '/* A long\n'
+ ' * Comment\n'
+ '*/\n'
+ 'class C /* is cool */ {\n'
+ ' /* int */ foo() => 42;\n'
+ '}\n'
+ );
+ expectCUFormatsTo(
Brian Wilkerson 2013/08/27 21:12:45 Related to my earlier questions, what happens if t
pquitslund 2013/08/27 21:55:38 Predictably this breaks. Thanks for the catch. S
+ 'library foo;\n'
+ '/* A long\n'
+ ' * Comment\n'
+ '*/\n'
+ '\n'
+ '/* And\n'
+ ' * another...\n'
+ '*/\n'
+ '\n'
+ '// Mixing it up\n'
+ '\n'
+ 'class C /* is cool */ {\n'
+ ' /* int */ foo() => 42;\n'
+ '}\n',
+ 'library foo;\n'
+ '/* A long\n'
+ ' * Comment\n'
+ '*/\n'
+ '\n'
+ '/* And\n'
+ ' * another...\n'
+ '*/\n'
+ '\n'
+ '// Mixing it up\n'
+ '\n'
+ 'class C /* is cool */ {\n'
+ ' /* int */ foo() => 42;\n'
+ '}\n'
+ );
+ expectCUFormatsTo(
+ '/// Copyright info\n'
+ '\n'
+ 'library foo;\n'
+ '/// Class comment\n'
+ '//TODO: implement\n'
+ 'class C {\n'
+ '}\n',
+ '/// Copyright info\n'
+ '\n'
+ 'library foo;\n'
+ '/// Class comment\n'
+ '//TODO: implement\n'
+ 'class C {\n'
+ '}\n'
+ );
+ });
+
+
test('CU - constructor', () {
expectCUFormatsTo(
'class A {\n'
@@ -354,7 +484,7 @@
test('CU - parts', () {
expectCUFormatsTo(
'part of foo;',
- 'part of foo;'
+ 'part of foo;\n'
);
});
@@ -413,6 +543,13 @@
);
});
+ test('stmt (maps)', () {
+ expectStmtFormatsTo(
+ 'var map = const {"foo": "bar", "fuz": null};',
+ 'var map = const {"foo": "bar", "fuz": null};'
+ );
+ });
+
test('stmt (try/catch)', () {
expectStmtFormatsTo(
'try {\n'

Powered by Google App Engine
This is Rietveld 408576698