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/edit/fix_test.dart

Issue 402333006: Implementation of the 'edit.getFixes' API in server. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library test.edit.fix;
6
7 import 'package:analysis_server/src/computer/element.dart';
8 import 'package:analysis_server/src/computer/error.dart';
9 import 'package:analysis_server/src/edit/fix.dart';
10 import 'package:analysis_services/constants.dart';
11 import 'package:analysis_services/correction/change.dart';
12 import 'package:analysis_services/correction/fix.dart' as services;
13 import 'package:analysis_services/index/index.dart' hide Location;
14 import 'package:analysis_services/index/local_memory_index.dart';
15 import 'package:analysis_services/src/search/search_engine.dart';
16 import 'package:analysis_testing/abstract_single_unit.dart';
17 import 'package:analysis_testing/reflective_tests.dart';
18 import 'package:analyzer/src/generated/element.dart' as engine;
19 import 'package:analyzer/src/generated/engine.dart' as engine;
20 import 'package:analyzer/src/generated/error.dart' as engine;
21 import 'package:analyzer/src/generated/utilities_dart.dart' as engine;
22 import 'package:unittest/unittest.dart' hide ERROR;
23
24
25
26 main() {
27 groupSep = ' | ';
28 group('ErrorFixes', () {
29 runReflectiveTests(ErrorFixesTest);
30 });
31 }
32
33
34 @ReflectiveTestCase()
35 class ErrorFixesTest extends AbstractSingleUnitTest {
36 Index index;
37 SearchEngineImpl searchEngine;
38
39 void setUp() {
40 super.setUp();
41 index = createLocalMemoryIndex();
42 searchEngine = new SearchEngineImpl(index);
43 verifyNoTestUnitErrors = false;
44 }
45
46 void test_fromJson() {
47 var json = {
48 ERROR: {
49 SEVERITY: 'ERROR',
50 TYPE: 'SYNTACTIC_ERROR',
51 LOCATION: {
52 FILE: '/test.dart',
53 OFFSET: 19,
54 LENGTH: 1,
55 START_LINE: 2,
56 START_COLUMN: 11
57 },
58 MESSAGE: 'Expected to find \';\''
59 },
60 FIXES: [{
61 MESSAGE: 'Insert \';\'',
62 EDITS: [{
63 FILE: '/test.dart',
64 EDITS: [{
65 OFFSET: 20,
66 LENGTH: 0,
67 REPLACEMENT: ';'
68 }]
69 }],
70 LINKED_POSITION_GROUPS: []
71 }]
72 };
73 ErrorFixes errorFixes = ErrorFixes.fromJson(json);
74 {
75 AnalysisError error = errorFixes.error;
76 expect(error.severity, 'ERROR');
77 expect(error.type, 'SYNTACTIC_ERROR');
78 expect(error.message, "Expected to find ';'");
79 {
80 Location location = error.location;
81 expect(location.file, testFile);
82 expect(location.offset, 19);
83 expect(location.length, 1);
84 expect(location.startLine, 2);
85 expect(location.startColumn, 11);
86 }
87 }
88 expect(errorFixes.fixes, hasLength(1));
89 {
90 Change change = errorFixes.fixes[0];
91 expect(change.message, "Insert ';'");
92 expect(change.edits, hasLength(1));
93 {
94 FileEdit fileEdit = change.edits[0];
95 expect(fileEdit.file, testFile);
96 expect(
97 fileEdit.edits.toString(),
98 "[Edit(offset=20, length=0, replacement=:>;<:)]");
99 }
100 }
101 expect(
102 errorFixes.toString(),
103 'ErrorFixes(error=AnalysisError('
104 'location=Location(file=/test.dart; offset=19; length=1; '
105 'startLine=2; startColumn=11) message=Expected to find \';\'; '
106 'severity=ERROR; type=SYNTACTIC_ERROR; correction=null, '
107 'fixes=[Change(message=Insert \';\', '
108 'edits=[FileEdit(file=/test.dart, edits=[Edit(offset=20, length=0, '
109 'replacement=:>;<:)])], linkedPositionGroups=[])])');
110 }
111
112 void test_fromService() {
113 verifyNoTestUnitErrors = false;
114 resolveTestUnit('''
115 main() {
116 print(42)
117 }
118 ''');
119 engine.AnalysisErrorInfo errors = context.getErrors(testSource);
120 engine.AnalysisError engineError = errors.errors[0];
121 List<services.Fix> servicesFixes =
122 services.computeFixes(searchEngine, testFile, testUnit, engineError);
123 AnalysisError error =
124 new AnalysisError.fromEngine(errors.lineInfo, engineError);
125 ErrorFixes fixes = new ErrorFixes(error);
126 servicesFixes.forEach((fix) => fixes.addFix(fix));
127 expect(fixes.toJson(), {
128 ERROR: {
129 SEVERITY: 'ERROR',
130 TYPE: 'SYNTACTIC_ERROR',
131 LOCATION: {
132 FILE: '/test.dart',
133 OFFSET: 19,
134 LENGTH: 1,
135 START_LINE: 2,
136 START_COLUMN: 11
137 },
138 MESSAGE: 'Expected to find \';\''
139 },
140 FIXES: [{
141 MESSAGE: 'Insert \';\'',
142 EDITS: [{
143 FILE: '/test.dart',
144 EDITS: [{
145 OFFSET: 20,
146 LENGTH: 0,
147 REPLACEMENT: ';'
148 }]
149 }],
150 LINKED_POSITION_GROUPS: []
151 }]
152 });
153 }
154 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698