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

Side by Side Diff: pkg/analysis_server/test/index/index_test.dart

Issue 367793002: Update Element/navigation/outline to use Location. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Forgotten file 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
« no previous file with comments | « pkg/analysis_server/test/domain_analysis_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.index; 5 library test.index;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io' show Directory; 8 import 'dart:io' show Directory;
9 9
10 import 'package:analysis_server/src/index/index.dart'; 10 import 'package:analysis_server/src/index/index.dart';
11 import 'package:analysis_server/src/resource.dart';
12 import 'package:analyzer/src/generated/ast.dart'; 11 import 'package:analyzer/src/generated/ast.dart';
13 import 'package:analyzer/src/generated/element.dart'; 12 import 'package:analyzer/src/generated/element.dart';
14 import 'package:analyzer/src/generated/engine.dart';
15 import 'package:analyzer/src/generated/html.dart'; 13 import 'package:analyzer/src/generated/html.dart';
16 import 'package:analyzer/src/generated/index.dart'; 14 import 'package:analyzer/src/generated/index.dart';
17 import 'package:analyzer/src/generated/sdk.dart';
18 import 'package:analyzer/src/generated/source_io.dart'; 15 import 'package:analyzer/src/generated/source_io.dart';
19 import 'package:unittest/unittest.dart'; 16 import 'package:unittest/unittest.dart';
20 17
21 import '../mocks.dart'; 18 import '../abstract_context.dart';
22 import '../reflective_tests.dart'; 19 import '../reflective_tests.dart';
20 import 'store/memory_node_manager.dart';
23 import 'store/single_source_container.dart'; 21 import 'store/single_source_container.dart';
24 import 'store/memory_node_manager.dart';
25 22
26 23
27 main() { 24 main() {
28 groupSep = ' | '; 25 groupSep = ' | ';
29 group('LocalIndex', () { 26 group('LocalIndex', () {
30 runReflectiveTests(LocalIndexTest); 27 runReflectiveTests(LocalIndexTest);
31 }); 28 });
32 } 29 }
33 30
34 31
35 void _assertElementNames(List<Location> locations, List expected) { 32 void _assertElementNames(List<Location> locations, List expected) {
36 expect(_toElementNames(locations), unorderedEquals(expected)); 33 expect(_toElementNames(locations), unorderedEquals(expected));
37 } 34 }
38 35
39 36
40 Iterable<String> _toElementNames(List<Location> locations) { 37 Iterable<String> _toElementNames(List<Location> locations) {
41 return locations.map((loc) => loc.element.name); 38 return locations.map((loc) => loc.element.name);
42 } 39 }
43 40
44 41
45 @ReflectiveTestCase() 42 @ReflectiveTestCase()
46 class LocalIndexTest { 43 class LocalIndexTest extends AbstractContextTest {
47 static final DartSdk SDK = new MockSdk(); 44 Directory indexDirectory;
48
49 AnalysisContext context;
50 LocalIndex index; 45 LocalIndex index;
51 Directory indexDirectory;
52 MemoryResourceProvider provider = new MemoryResourceProvider();
53 46
54 void setUp() { 47 void setUp() {
48 super.setUp();
55 // prepare Index 49 // prepare Index
56 indexDirectory = Directory.systemTemp.createTempSync( 50 indexDirectory = Directory.systemTemp.createTempSync(
57 'AnalysisServer_index'); 51 'AnalysisServer_index');
58 index = new LocalIndex(new MemoryNodeManager()); 52 index = new LocalIndex(new MemoryNodeManager());
59 // prepare AnalysisContext
60 context = AnalysisEngine.instance.createAnalysisContext();
61 context.sourceFactory = new SourceFactory(<UriResolver>[new DartUriResolver(
62 SDK), new ResourceUriResolver(provider)]);
63 } 53 }
64 54
65 void tearDown() { 55 void tearDown() {
56 super.tearDown();
66 indexDirectory.delete(recursive: true); 57 indexDirectory.delete(recursive: true);
67 index = null; 58 index = null;
68 context = null;
69 provider = null;
70 } 59 }
71 60
72 Future test_clear() { 61 Future test_clear() {
73 _indexTest('main() {}'); 62 _indexTest('main() {}');
74 return _getDefinedFunctions().then((locations) { 63 return _getDefinedFunctions().then((locations) {
75 _assertElementNames(locations, ['main']); 64 _assertElementNames(locations, ['main']);
76 // clear 65 // clear
77 index.clear(); 66 index.clear();
78 return _getDefinedFunctions().then((locations) { 67 return _getDefinedFunctions().then((locations) {
79 expect(locations, isEmpty); 68 expect(locations, isEmpty);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 return _getDefinedFunctions().then((locations) { 140 return _getDefinedFunctions().then((locations) {
152 _assertElementNames(locations, ['fb']); 141 _assertElementNames(locations, ['fb']);
153 }); 142 });
154 }); 143 });
155 } 144 }
156 145
157 void test_statistics() { 146 void test_statistics() {
158 expect(index.statistics, '[0 locations, 0 sources, 0 names]'); 147 expect(index.statistics, '[0 locations, 0 sources, 0 names]');
159 } 148 }
160 149
161 Source _addSource(String path, String content) {
162 File file = provider.newFile(path, content);
163 Source source = file.createSource(UriKind.FILE_URI);
164 ChangeSet changeSet = new ChangeSet();
165 changeSet.addedSource(source);
166 context.applyChanges(changeSet);
167 context.setContents(source, content);
168 return source;
169 }
170
171 Future<List<Location>> _getDefinedFunctions() { 150 Future<List<Location>> _getDefinedFunctions() {
172 return index.getRelationshipsAsync(UniverseElement.INSTANCE, 151 return index.getRelationshipsAsync(UniverseElement.INSTANCE,
173 IndexConstants.DEFINES_FUNCTION); 152 IndexConstants.DEFINES_FUNCTION);
174 } 153 }
175 154
176 Source _indexLibraryUnit(String path, String content) { 155 Source _indexLibraryUnit(String path, String content) {
177 Source source = _addSource(path, content); 156 Source source = addSource(path, content);
178 CompilationUnit dartUnit = _resolveLibraryUnit(source); 157 CompilationUnit dartUnit = resolveLibraryUnit(source);
179 index.indexUnit(context, dartUnit); 158 index.indexUnit(context, dartUnit);
180 return source; 159 return source;
181 } 160 }
182 161
183 void _indexTest(String content) { 162 void _indexTest(String content) {
184 _indexLibraryUnit('/test.dart', content); 163 _indexLibraryUnit('/test.dart', content);
185 } 164 }
186
187 CompilationUnit _resolveLibraryUnit(Source source) {
188 return context.resolveCompilationUnit2(source, source);
189 }
190 } 165 }
191 166
192 167
193 /** 168 /**
194 * A [RelationshipCallback] that remembers [Location]s. 169 * A [RelationshipCallback] that remembers [Location]s.
195 */ 170 */
196 class _RecordingRelationshipCallback extends RelationshipCallback { 171 class _RecordingRelationshipCallback extends RelationshipCallback {
197 List<Location> locations; 172 List<Location> locations;
198 173
199 @override 174 @override
200 void hasRelationships(Element element, Relationship relationship, 175 void hasRelationships(Element element, Relationship relationship,
201 List<Location> locations) { 176 List<Location> locations) {
202 this.locations = locations; 177 this.locations = locations;
203 } 178 }
204 } 179 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/domain_analysis_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698