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

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

Issue 18487005: Initial indent fix and a few more tests. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 5 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 24818)
+++ pkg/analyzer_experimental/test/services/formatter_test.dart (working copy)
@@ -69,58 +69,87 @@
'}'
);
});
-//
-// test('CU (method indent - 2)', () {
-// expectCUFormatsTo(
-// 'class A {\n'
-// ' static bool x(){ return true; }\n'
-// ' }',
-// 'class A {\n'
-// ' static bool x() {\n'
-// ' return true;\n'
-// ' }\n'
-// '}'
-// );
-// });
-//
-// test('CU (method indent - 3)', () {
-// expectCUFormatsTo(
-// 'class A {\n'
-// ' int x() => 42 + 3 ; \n'
-// ' }',
-// 'class A {\n'
-// ' int x() => 42 + 3;\n'
-// '}'
-// );
-// });
-//
-// test('CU (method indent - 4)', () {
-// expectCUFormatsTo(
-// 'class A {\n'
-// ' int x() { \n'
-// 'if (true) {return 42;\n'
-// '} else { return false; }\n'
-// ' }'
-// '}',
-// 'class A {\n'
-// ' int x() {\n'
-// ' if (true) {\n'
-// ' return 42;\n'
-// ' } else {\n'
-// ' return false;\n'
-// ' }\n'
-// '}'
-// );
-// });
+ test('CU (method indent - 2)', () {
+ expectCUFormatsTo(
+ 'class A {\n'
+ ' static bool x(){ return true; }\n'
+ ' }',
+ 'class A {\n'
+ ' static bool x() {\n'
+ ' return true;\n'
+ ' }\n'
+ '}'
+ );
+ });
-// test('initialIndent', () {
-// var formatter = new CodeFormatter(
-// new FormatterOptions(initialIndentationLevel: 2));
-// var formattedSource = formatter.format(CodeKind.STATEMENT, 'var x;');
-// expect(formattedSource, startsWith(' '));
-// });
+ test('CU (method indent - 3)', () {
+ expectCUFormatsTo(
+ 'class A {\n'
+ ' int x() => 42 + 3 ; \n'
+ ' }',
+ 'class A {\n'
+ ' int x() => 42 + 3;\n'
+ '}'
+ );
+ });
+ test('CU (method indent - 4)', () {
+ expectCUFormatsTo(
+ 'class A {\n'
+ ' int x() { \n'
+ 'if (true) {return 42;\n'
+ '} else { return false; }\n'
+ ' }'
+ '}',
+ 'class A {\n'
+ ' int x() {\n'
+ ' if (true) {\n'
+ ' return 42;\n'
+ ' } else {\n'
+ ' return false;\n'
+ ' }\n'
+ ' }\n'
+ '}'
+ );
+ });
+
+
+ test('stmt', () {
+ expectStmtFormatsTo(
+ 'if (true){\n'
+ 'if (true){\n'
+ 'if (true){\n'
+ 'return true;\n'
+ '} else{\n'
+ 'return false;\n'
+ '}\n'
+ '}\n'
+ '}else{\n'
+ 'return false;\n'
+ '}',
+ 'if (true) {\n'
+ ' if (true) {\n'
+ ' if (true) {\n'
+ ' return true;\n'
+ ' } else {\n'
+ ' return false;\n'
+ ' }\n'
+ ' }\n'
+ '} else {\n'
+ ' return false;\n'
+ '}'
+ );
+ });
+
+
+ test('initialIndent', () {
+ var formatter = new CodeFormatter(
+ new FormatterOptions(initialIndentationLevel: 2));
+ var formattedSource = formatter.format(CodeKind.STATEMENT, 'var x;');
+ expect(formattedSource, startsWith(' '));
+ });
+
});
@@ -238,4 +267,10 @@
String formatCU(src, {options: const FormatterOptions()}) =>
new CodeFormatter(options).format(CodeKind.COMPILATION_UNIT, src);
+String formatStatement(src, {options: const FormatterOptions()}) =>
+ new CodeFormatter(options).format(CodeKind.STATEMENT, src);
+
expectCUFormatsTo(src, expected) => expect(formatCU(src), equals(expected));
+
+expectStmtFormatsTo(src, expected) => expect(formatStatement(src),
+ equals(expected));

Powered by Google App Engine
This is Rietveld 408576698