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

Side by Side 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 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 'package:unittest/unittest.dart'; 5 import 'package:unittest/unittest.dart';
6 6
7 import 'package:analyzer_experimental/src/generated/ast.dart'; 7 import 'package:analyzer_experimental/src/generated/ast.dart';
8 import 'package:analyzer_experimental/src/generated/scanner.dart'; 8 import 'package:analyzer_experimental/src/generated/scanner.dart';
9 import 'package:analyzer_experimental/src/services/formatter.dart'; 9 import 'package:analyzer_experimental/src/services/formatter.dart';
10 import 'package:analyzer_experimental/src/services/formatter_impl.dart'; 10 import 'package:analyzer_experimental/src/services/formatter_impl.dart';
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 'class A {\n' 62 'class A {\n'
63 'void x(){\n' 63 'void x(){\n'
64 '}\n' 64 '}\n'
65 '}', 65 '}',
66 'class A {\n' 66 'class A {\n'
67 ' void x() {\n' 67 ' void x() {\n'
68 ' }\n' 68 ' }\n'
69 '}' 69 '}'
70 ); 70 );
71 }); 71 });
72 // 72
73 // test('CU (method indent - 2)', () { 73 test('CU (method indent - 2)', () {
74 // expectCUFormatsTo( 74 expectCUFormatsTo(
75 // 'class A {\n' 75 'class A {\n'
76 // ' static bool x(){ return true; }\n' 76 ' static bool x(){ return true; }\n'
77 // ' }', 77 ' }',
78 // 'class A {\n' 78 'class A {\n'
79 // ' static bool x() {\n' 79 ' static bool x() {\n'
80 // ' return true;\n' 80 ' return true;\n'
81 // ' }\n' 81 ' }\n'
82 // '}' 82 '}'
83 // ); 83 );
84 // }); 84 });
85 // 85
86 // test('CU (method indent - 3)', () { 86 test('CU (method indent - 3)', () {
87 // expectCUFormatsTo( 87 expectCUFormatsTo(
88 // 'class A {\n' 88 'class A {\n'
89 // ' int x() => 42 + 3 ; \n' 89 ' int x() => 42 + 3 ; \n'
90 // ' }', 90 ' }',
91 // 'class A {\n' 91 'class A {\n'
92 // ' int x() => 42 + 3;\n' 92 ' int x() => 42 + 3;\n'
93 // '}' 93 '}'
94 // ); 94 );
95 // }); 95 });
96 // 96
97 // test('CU (method indent - 4)', () { 97 test('CU (method indent - 4)', () {
98 // expectCUFormatsTo( 98 expectCUFormatsTo(
99 // 'class A {\n' 99 'class A {\n'
100 // ' int x() { \n' 100 ' int x() { \n'
101 // 'if (true) {return 42;\n' 101 'if (true) {return 42;\n'
102 // '} else { return false; }\n' 102 '} else { return false; }\n'
103 // ' }' 103 ' }'
104 // '}', 104 '}',
105 // 'class A {\n' 105 'class A {\n'
106 // ' int x() {\n' 106 ' int x() {\n'
107 // ' if (true) {\n' 107 ' if (true) {\n'
108 // ' return 42;\n' 108 ' return 42;\n'
109 // ' } else {\n' 109 ' } else {\n'
110 // ' return false;\n' 110 ' return false;\n'
111 // ' }\n' 111 ' }\n'
112 // '}' 112 ' }\n'
113 // ); 113 '}'
114 // }); 114 );
115 });
115 116
116 117
117 // test('initialIndent', () { 118 test('stmt', () {
118 // var formatter = new CodeFormatter( 119 expectStmtFormatsTo(
119 // new FormatterOptions(initialIndentationLevel: 2)); 120 'if (true){\n'
120 // var formattedSource = formatter.format(CodeKind.STATEMENT, 'var x;'); 121 'if (true){\n'
121 // expect(formattedSource, startsWith(' ')); 122 'if (true){\n'
122 // }); 123 'return true;\n'
124 '} else{\n'
125 'return false;\n'
126 '}\n'
127 '}\n'
128 '}else{\n'
129 'return false;\n'
130 '}',
131 'if (true) {\n'
132 ' if (true) {\n'
133 ' if (true) {\n'
134 ' return true;\n'
135 ' } else {\n'
136 ' return false;\n'
137 ' }\n'
138 ' }\n'
139 '} else {\n'
140 ' return false;\n'
141 '}'
142 );
143 });
144
145
146 test('initialIndent', () {
147 var formatter = new CodeFormatter(
148 new FormatterOptions(initialIndentationLevel: 2));
149 var formattedSource = formatter.format(CodeKind.STATEMENT, 'var x;');
150 expect(formattedSource, startsWith(' '));
151 });
123 152
124 }); 153 });
125 154
126 155
127 /// Line tests 156 /// Line tests
128 group('line', () { 157 group('line', () {
129 158
130 test('space', () { 159 test('space', () {
131 var line = new Line(indent: 0); 160 var line = new Line(indent: 0);
132 line.addSpaces(2); 161 line.addSpaces(2);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 Token chain(List<Token> tokens) { 260 Token chain(List<Token> tokens) {
232 for (var i = 0; i < tokens.length - 1; ++i) { 261 for (var i = 0; i < tokens.length - 1; ++i) {
233 tokens[i].setNext(tokens[i + 1]); 262 tokens[i].setNext(tokens[i + 1]);
234 } 263 }
235 return tokens[0]; 264 return tokens[0];
236 } 265 }
237 266
238 String formatCU(src, {options: const FormatterOptions()}) => 267 String formatCU(src, {options: const FormatterOptions()}) =>
239 new CodeFormatter(options).format(CodeKind.COMPILATION_UNIT, src); 268 new CodeFormatter(options).format(CodeKind.COMPILATION_UNIT, src);
240 269
270 String formatStatement(src, {options: const FormatterOptions()}) =>
271 new CodeFormatter(options).format(CodeKind.STATEMENT, src);
272
241 expectCUFormatsTo(src, expected) => expect(formatCU(src), equals(expected)); 273 expectCUFormatsTo(src, expected) => expect(formatCU(src), equals(expected));
274
275 expectStmtFormatsTo(src, expected) => expect(formatStatement(src),
276 equals(expected));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698