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

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

Issue 16562012: Dart formatter babysteps. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 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 0)
+++ pkg/analyzer_experimental/test/services/formatter_test.dart (revision 0)
@@ -0,0 +1,62 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'package:analyzer_experimental/src/generated/ast.dart';
+import 'package:analyzer_experimental/src/services/formatter.dart';
+import 'package:analyzer_experimental/src/services/formatter_impl.dart';
+import 'package:unittest/unittest.dart';
+
+main() {
+
+ /// Edit recorder tests
+ group('edit recorder', () {
messick 2013/06/07 13:51:36 I'd add a few tests that are expected to fail.
pquitslund 2013/06/07 19:45:01 Will do. Thanks!
+
+ test('countWhitespace', (){
+ expect(newRecorder(' ').countWhitespace(), equals(3));
+ expect(newRecorder('').countWhitespace(), equals(0));
+ expect(newRecorder(' foo').countWhitespace(), equals(2));
+ });
+
+ test('indent', (){
+ var recorder = newRecorder('');
+ expect(recorder.indentationLevel, equals(0));
+ expect(recorder.options.indentPerLevel, equals(2));
+ recorder.indent();
+ expect(recorder.indentationLevel, equals(2));
+ expect(recorder.numberOfIndentations, equals(1));
+ });
+
+ test('isNewlineAt', (){
+ expect(newRecorder('012\n').isNewlineAt(3), isTrue);
+ expect(newRecorder('012\n3456').isNewlineAt(3), isTrue);
+ expect(newRecorder('\n').isNewlineAt(0), isTrue);
+ });
+
+ });
+
+
+ /// Formatter tests
+ group('formatter', () {
+
+ test('failedParse', () {
+ var formatter = new CodeFormatter();
+ expect(() => formatter.format(CodeKind.COMPILATION_UNIT, "~"),
+ throwsA(new isInstanceOf<FormatterException>('FE')));
+ });
+
+// test('initialIndent', () {
+// var formatter = new CodeFormatter(new Options(initialIndentationLevel:2));
+// var formattedSource = formatter.format(CodeKind.STATEMENT, 'var x;');
+// expect(formattedSource, startsWith(' '));
+// });
+
+ });
+
+}
+
+EditRecorder newRecorder(String source) {
+ var recorder = new EditRecorder(new FormatterOptions());
+ recorder.source = source;
+ return recorder;
+}

Powered by Google App Engine
This is Rietveld 408576698