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

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

Issue 24371003: Formatter selection preservation support. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 3 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
« no previous file with comments | « pkg/analyzer_experimental/lib/src/services/formatter_impl.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer_experimental/test/services/formatter_test.dart
===================================================================
--- pkg/analyzer_experimental/test/services/formatter_test.dart (revision 27780)
+++ pkg/analyzer_experimental/test/services/formatter_test.dart (working copy)
@@ -772,6 +772,14 @@
expect(formattedSource, startsWith(' '));
});
+ test('selections', () {
+ expectSelectedPostFormat('class X {}', '}');
+ expectSelectedPostFormat('class X{}', '{');
+ expectSelectedPostFormat('class X{int y;}', ';');
+ expectSelectedPostFormat('class X{int y;}', '}');
+ expectSelectedPostFormat('class X {}', ' {');
+ });
+
});
@@ -955,14 +963,23 @@
return tokens[0];
}
-String formatCU(src, {options: const FormatterOptions()}) =>
- new CodeFormatter(options).format(CodeKind.COMPILATION_UNIT, src).source;
+FormattedSource formatCU(src, {options: const FormatterOptions(), selection}) =>
+ new CodeFormatter(options).format(
+ CodeKind.COMPILATION_UNIT, src, selection: selection);
String formatStatement(src, {options: const FormatterOptions()}) =>
new CodeFormatter(options).format(CodeKind.STATEMENT, src).source;
Token tokenize(String str) => new StringScanner(null, str, null).tokenize();
+expectSelectedPostFormat(src, token) {
+ var preOffset = src.indexOf(token);
+ var length = token.length;
+ var formatted = formatCU(src, selection: new Selection(preOffset, length));
+ var postOffset = formatted.selection.offset;
+ expect(formatted.source.substring(postOffset, postOffset + length),
+ equals(src.substring(preOffset, preOffset + length)));
+}
expectTokenizedEqual(String s1, String s2) =>
expectStreamsEqual(tokenize(s1), tokenize(s2));
@@ -978,7 +995,8 @@
expect(() => new TokenStreamComparator(null, t1, t2).verifyEquals(),
throwsA(new isInstanceOf<FormatterException>()));
-expectCUFormatsTo(src, expected) => expect(formatCU(src), equals(expected));
+expectCUFormatsTo(src, expected) =>
+ expect(formatCU(src).source, equals(expected));
-expectStmtFormatsTo(src, expected) => expect(formatStatement(src),
- equals(expected));
+expectStmtFormatsTo(src, expected) =>
+ expect(formatStatement(src), equals(expected));
« no previous file with comments | « pkg/analyzer_experimental/lib/src/services/formatter_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698