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

Side by Side Diff: pkg/analysis_server/test/integration/edit/format_test.dart

Issue 2695253002: Add an integration test for edit.format. (Closed)
Patch Set: rename setup to formatTestSetup Created 3 years, 10 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
OLDNEW
(Empty)
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
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.
4
5 import 'package:analysis_server/plugin/protocol/protocol.dart';
6 import 'package:test/test.dart';
7 import 'package:test_reflective_loader/test_reflective_loader.dart';
8
9 import '../integration_tests.dart';
10
11 main() {
12 defineReflectiveSuite(() {
13 defineReflectiveTests(FormatTest);
14 });
15 }
16
17 @reflectiveTest
18 class FormatTest extends AbstractAnalysisServerIntegrationTest {
19 String formatTestSetup({bool withErrors: false}) {
20 String pathname = sourcePath('test.dart');
21
22 if (withErrors) {
23 String text = r'''
24 class Class1 {
25 int field
26 void foo() {
27 }
28 }
29 ''';
30 writeFile(pathname, text);
31 } else {
32 String text = r'''
33 class Class1 {
34 int field;
35
36 void foo() {
37 }
38
39 void bar() {
40 }
41 }
42 ''';
43 writeFile(pathname, text);
44 }
45 standardAnalysisSetup();
46 return pathname;
47 }
48
49 test_format() async {
50 String pathname = formatTestSetup();
51
52 EditFormatResult result = await sendEditFormat(pathname, 0, 0);
53 expect(result.edits, isNotEmpty);
54 expect(result.selectionOffset, 0);
55 expect(result.selectionLength, 0);
56 }
57
58 test_format_preserve_selection() async {
59 String pathname = formatTestSetup();
60
61 // format with 'bar' selected
62 int initialPosition = readFile(pathname).indexOf('bar()');
63 EditFormatResult result =
64 await sendEditFormat(pathname, initialPosition, 'bar'.length);
65 expect(result.edits, isNotEmpty);
66 expect(result.selectionOffset, initialPosition - 3);
67 expect(result.selectionLength, 'bar'.length);
68 }
69
70 test_format_with_errors() async {
71 String pathname = formatTestSetup(withErrors: true);
72
73 try {
74 await sendEditFormat(pathname, 0, 0);
75 fail('expected FORMAT_WITH_ERRORS');
76 } on ServerErrorMessage catch (message) {
77 expect(message.error['code'], 'FORMAT_WITH_ERRORS');
78 }
79 }
80
81 @override
82 bool get enableNewAnalysisDriver => true;
83 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/integration/coverage.md ('k') | pkg/analysis_server/test/integration/edit/test_all.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698