OLD | NEW |
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.src.index.local_index; | 5 library test.services.src.index.local_index; |
6 | 6 |
| 7 import 'package:analysis_server/src/services/index/index_contributor.dart'; |
7 import 'package:analysis_server/src/services/index/local_index.dart'; | 8 import 'package:analysis_server/src/services/index/local_index.dart'; |
8 import 'package:analysis_server/src/services/index/local_memory_index.dart'; | 9 import 'package:analysis_server/src/services/index/local_memory_index.dart'; |
9 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
10 import 'package:analyzer/src/generated/element.dart'; | 11 import 'package:analyzer/src/generated/element.dart'; |
11 import 'package:analyzer/src/generated/html.dart'; | |
12 import 'package:analyzer/src/generated/source_io.dart'; | 12 import 'package:analyzer/src/generated/source_io.dart'; |
13 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 13 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
14 import 'package:unittest/unittest.dart'; | 14 import 'package:unittest/unittest.dart'; |
15 | 15 |
16 import '../../abstract_context.dart'; | 16 import '../../abstract_context.dart'; |
17 import '../../utils.dart'; | 17 import '../../utils.dart'; |
18 import 'store/single_source_container.dart'; | 18 import 'store/single_source_container.dart'; |
19 | 19 |
20 main() { | 20 main() { |
21 initializeTestEnvironment(); | 21 initializeTestEnvironment(); |
22 defineReflectiveTests(LocalIndexTest); | 22 defineReflectiveTests(LocalIndexTest); |
23 } | 23 } |
24 | 24 |
25 void _assertElementNames(List<Element> elements, List expected) { | 25 void _assertElementNames(List<Element> elements, List expected) { |
26 expect(_toElementNames(elements), unorderedEquals(expected)); | 26 expect(_toElementNames(elements), unorderedEquals(expected)); |
27 } | 27 } |
28 | 28 |
29 Iterable<String> _toElementNames(List<Element> elements) { | 29 Iterable<String> _toElementNames(List<Element> elements) { |
30 return elements.map((element) => element.name); | 30 return elements.map((element) => element.name); |
31 } | 31 } |
32 | 32 |
33 @reflectiveTest | 33 @reflectiveTest |
34 class LocalIndexTest extends AbstractContextTest { | 34 class LocalIndexTest extends AbstractContextTest { |
35 LocalIndex index; | 35 LocalIndex index; |
36 | 36 |
37 void setUp() { | 37 void setUp() { |
38 super.setUp(); | 38 super.setUp(); |
39 index = createLocalMemoryIndex(); | 39 index = createLocalMemoryIndex(); |
| 40 index.contributors = [new DartIndexContributor()]; |
40 } | 41 } |
41 | 42 |
42 void tearDown() { | 43 void tearDown() { |
43 super.tearDown(); | 44 super.tearDown(); |
44 index = null; | 45 index = null; |
45 } | 46 } |
46 | 47 |
47 void test_clear() { | 48 void test_clear() { |
48 _indexTest('main() {}'); | 49 _indexTest('main() {}'); |
49 _assertElementNames(_getTopElements(), ['main']); | 50 _assertElementNames(_getTopElements(), ['main']); |
50 // clear | 51 // clear |
51 index.clear(); | 52 index.clear(); |
52 expect(_getTopElements(), isEmpty); | 53 expect(_getTopElements(), isEmpty); |
53 } | 54 } |
54 | 55 |
55 void test_indexHtmlUnit_nullUnit() { | 56 void test_index() { |
56 index.indexHtmlUnit(context, null); | |
57 } | |
58 | |
59 void test_indexHtmlUnit_nullUnitElement() { | |
60 HtmlUnit unit = new HtmlUnit(null, [], null); | |
61 index.indexHtmlUnit(context, unit); | |
62 } | |
63 | |
64 void test_indexUnit() { | |
65 _indexTest('main() {}'); | 57 _indexTest('main() {}'); |
66 _assertElementNames(_getTopElements(), ['main']); | 58 _assertElementNames(_getTopElements(), ['main']); |
67 } | 59 } |
68 | 60 |
69 void test_indexUnit_nullUnit() { | 61 void test_index_nullObject() { |
70 index.indexUnit(context, null); | 62 index.index(context, null); |
71 } | 63 } |
72 | 64 |
73 void test_indexUnit_nullUnitElement() { | 65 void test_index_nullUnitElement() { |
74 CompilationUnit unit = new CompilationUnit(null, null, [], [], null); | 66 CompilationUnit unit = new CompilationUnit(null, null, [], [], null); |
75 index.indexUnit(context, unit); | 67 index.index(context, unit); |
76 } | 68 } |
77 | 69 |
78 void test_removeContext() { | 70 void test_removeContext() { |
79 _indexTest('main() {}'); | 71 _indexTest('main() {}'); |
80 // OK, there is an element | 72 // OK, there is an element |
81 _assertElementNames(_getTopElements(), ['main']); | 73 _assertElementNames(_getTopElements(), ['main']); |
82 // remove context | 74 // remove context |
83 index.removeContext(context); | 75 index.removeContext(context); |
84 expect(_getTopElements(), isEmpty); | 76 expect(_getTopElements(), isEmpty); |
85 } | 77 } |
(...skipping 22 matching lines...) Expand all Loading... |
108 expect(index.statistics, '[0 locations, 0 sources, 0 names]'); | 100 expect(index.statistics, '[0 locations, 0 sources, 0 names]'); |
109 } | 101 } |
110 | 102 |
111 List<Element> _getTopElements() { | 103 List<Element> _getTopElements() { |
112 return index.getTopLevelDeclarations((_) => true); | 104 return index.getTopLevelDeclarations((_) => true); |
113 } | 105 } |
114 | 106 |
115 Source _indexLibraryUnit(String path, String content) { | 107 Source _indexLibraryUnit(String path, String content) { |
116 Source source = addSource(path, content); | 108 Source source = addSource(path, content); |
117 CompilationUnit dartUnit = resolveLibraryUnit(source); | 109 CompilationUnit dartUnit = resolveLibraryUnit(source); |
118 index.indexUnit(context, dartUnit); | 110 index.index(context, dartUnit); |
119 return source; | 111 return source; |
120 } | 112 } |
121 | 113 |
122 void _indexTest(String content) { | 114 void _indexTest(String content) { |
123 _indexLibraryUnit('/test.dart', content); | 115 _indexLibraryUnit('/test.dart', content); |
124 } | 116 } |
125 } | 117 } |
OLD | NEW |