indexing: Use `test_frontend`
[nit.git] / src / indexing / tests / test_code_index.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 module test_code_index is test
16
17 import code_index
18 import test_frontend
19
20 class TestCodeIndex
21 super TestModel
22 test
23
24 # CodeIndex used in tests
25 var test_index = new CodeIndex(test_context)
26
27 redef fun build_test_env do
28 super
29 for mmodule in test_model.mmodules do
30 test_index.index_mentity(mmodule)
31 end
32 test_builder.paths.add test_src
33 end
34
35 fun test_find1 is test do
36 var query = "import game\n"
37 var matches = test_index.match_code(query)
38 assert matches.first.document.mentity.full_name == "test_prog::test_prog"
39 end
40
41 fun test_find2 is test do
42 var query = "import game\nimport rpg\n"
43 var matches = test_index.match_code(query)
44 assert matches.first.document.mentity.full_name == "test_prog::game"
45 end
46
47 fun test_find3 is test do
48 var query = "import game\nclass MyGame\nsuper Game\nredef fun start_game do end\nend\n"
49 var matches = test_index.match_code(query)
50 assert matches.first.document.mentity.full_name == "test_prog::game_examples"
51 end
52
53 fun test_find_error is test do
54 var query = "error"
55 var matches = test_index.match_code(query)
56 assert matches.is_empty
57 end
58 end