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

Side by Side Diff: pkg/analysis_server/test/services/correction/assist_test.dart

Issue 2551023005: Prepare for decoupling analyzer ASTs from element model. (Closed)
Patch Set: Created 4 years 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
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library test.services.correction.assist; 5 library test.services.correction.assist;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/plugin/edit/assist/assist_core.dart'; 9 import 'package:analysis_server/plugin/edit/assist/assist_core.dart';
10 import 'package:analysis_server/plugin/protocol/protocol.dart'; 10 import 'package:analysis_server/plugin/protocol/protocol.dart';
11 import 'package:analysis_server/src/plugin/server_plugin.dart'; 11 import 'package:analysis_server/src/plugin/server_plugin.dart';
12 import 'package:analysis_server/src/services/correction/assist.dart'; 12 import 'package:analysis_server/src/services/correction/assist.dart';
13 import 'package:analyzer/dart/ast/resolution_accessors.dart';
13 import 'package:analyzer/src/generated/engine.dart'; 14 import 'package:analyzer/src/generated/engine.dart';
14 import 'package:analyzer/src/generated/source.dart'; 15 import 'package:analyzer/src/generated/source.dart';
15 import 'package:plugin/manager.dart'; 16 import 'package:plugin/manager.dart';
16 import 'package:plugin/plugin.dart'; 17 import 'package:plugin/plugin.dart';
17 import 'package:test/test.dart'; 18 import 'package:test/test.dart';
18 import 'package:test_reflective_loader/test_reflective_loader.dart'; 19 import 'package:test_reflective_loader/test_reflective_loader.dart';
19 20
20 import '../../abstract_single_unit.dart'; 21 import '../../abstract_single_unit.dart';
21 22
22 main() { 23 main() {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 assertHasAssistAt( 58 assertHasAssistAt(
58 String offsetSearch, AssistKind kind, String expected) async { 59 String offsetSearch, AssistKind kind, String expected) async {
59 offset = findOffset(offsetSearch); 60 offset = findOffset(offsetSearch);
60 await assertHasAssist(kind, expected); 61 await assertHasAssist(kind, expected);
61 } 62 }
62 63
63 /** 64 /**
64 * Asserts that there is no [Assist] of the given [kind] at [offset]. 65 * Asserts that there is no [Assist] of the given [kind] at [offset].
65 */ 66 */
66 assertNoAssist(AssistKind kind) async { 67 assertNoAssist(AssistKind kind) async {
67 List<Assist> assists = await computeAssists( 68 List<Assist> assists = await computeAssists(plugin, context,
68 plugin, context, testUnit.element.source, offset, length); 69 elementForCompilationUnit(testUnit).source, offset, length);
69 for (Assist assist in assists) { 70 for (Assist assist in assists) {
70 if (assist.kind == kind) { 71 if (assist.kind == kind) {
71 throw fail('Unexpected assist $kind in\n${assists.join('\n')}'); 72 throw fail('Unexpected assist $kind in\n${assists.join('\n')}');
72 } 73 }
73 } 74 }
74 } 75 }
75 76
76 /** 77 /**
77 * Calls [assertNoAssist] at the offset of [offsetSearch] in [testCode]. 78 * Calls [assertNoAssist] at the offset of [offsetSearch] in [testCode].
78 */ 79 */
(...skipping 2597 matching lines...) Expand 10 before | Expand all | Expand 10 after
2676 } 2677 }
2677 '''; 2678 ''';
2678 await assertHasAssistAt( 2679 await assertHasAssistAt(
2679 'is String', DartAssistKind.INTRODUCE_LOCAL_CAST_TYPE, expected); 2680 'is String', DartAssistKind.INTRODUCE_LOCAL_CAST_TYPE, expected);
2680 await assertHasAssistAt( 2681 await assertHasAssistAt(
2681 'while (p', DartAssistKind.INTRODUCE_LOCAL_CAST_TYPE, expected); 2682 'while (p', DartAssistKind.INTRODUCE_LOCAL_CAST_TYPE, expected);
2682 } 2683 }
2683 2684
2684 test_invalidSelection() async { 2685 test_invalidSelection() async {
2685 resolveTestUnit(''); 2686 resolveTestUnit('');
2686 List<Assist> assists = 2687 List<Assist> assists = await computeAssists(
2687 await computeAssists(plugin, context, testUnit.element.source, -1, 0); 2688 plugin, context, elementForCompilationUnit(testUnit).source, -1, 0);
2688 expect(assists, isEmpty); 2689 expect(assists, isEmpty);
2689 } 2690 }
2690 2691
2691 test_invertIfStatement_blocks() async { 2692 test_invertIfStatement_blocks() async {
2692 resolveTestUnit(''' 2693 resolveTestUnit('''
2693 main() { 2694 main() {
2694 if (true) { 2695 if (true) {
2695 0; 2696 0;
2696 } else { 2697 } else {
2697 1; 2698 1;
(...skipping 1452 matching lines...) Expand 10 before | Expand all | Expand 10 after
4150 } 4151 }
4151 // end 4152 // end
4152 } 4153 }
4153 '''); 4154 ''');
4154 } 4155 }
4155 4156
4156 /** 4157 /**
4157 * Computes assists and verifies that there is an assist of the given kind. 4158 * Computes assists and verifies that there is an assist of the given kind.
4158 */ 4159 */
4159 Future<Assist> _assertHasAssist(AssistKind kind) async { 4160 Future<Assist> _assertHasAssist(AssistKind kind) async {
4160 List<Assist> assists = await computeAssists( 4161 List<Assist> assists = await computeAssists(plugin, context,
4161 plugin, context, testUnit.element.source, offset, length); 4162 elementForCompilationUnit(testUnit).source, offset, length);
4162 for (Assist assist in assists) { 4163 for (Assist assist in assists) {
4163 if (assist.kind == kind) { 4164 if (assist.kind == kind) {
4164 return assist; 4165 return assist;
4165 } 4166 }
4166 } 4167 }
4167 throw fail('Expected to find assist $kind in\n${assists.join('\n')}'); 4168 throw fail('Expected to find assist $kind in\n${assists.join('\n')}');
4168 } 4169 }
4169 4170
4170 void _assertLinkedGroup(LinkedEditGroup group, List<String> expectedStrings, 4171 void _assertLinkedGroup(LinkedEditGroup group, List<String> expectedStrings,
4171 [List<LinkedEditSuggestion> expectedSuggestions]) { 4172 [List<LinkedEditSuggestion> expectedSuggestions]) {
(...skipping 11 matching lines...) Expand all
4183 positions.add(new Position(testFile, offset)); 4184 positions.add(new Position(testFile, offset));
4184 } 4185 }
4185 return positions; 4186 return positions;
4186 } 4187 }
4187 4188
4188 void _setStartEndSelection() { 4189 void _setStartEndSelection() {
4189 offset = findOffset('// start\n') + '// start\n'.length; 4190 offset = findOffset('// start\n') + '// start\n'.length;
4190 length = findOffset('// end') - offset; 4191 length = findOffset('// end') - offset;
4191 } 4192 }
4192 } 4193 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698