b2a8f2e822bf07bbe206714b982645dd5da07954
1 # This file is part of NIT ( http://www.nitlanguage.org ).
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 module test_code_index
is test
23 # CodeIndex used in tests
24 var test_index
: CodeIndex is noinit
26 # Initialize test variables
28 # Must be called before test execution.
29 # FIXME should be before_all
30 fun build_test_env
is before
do
31 var test_path
= "NIT_TESTING_PATH".environ
.dirname
32 var test_src
= test_path
/ "../../../tests/test_prog"
35 var toolcontext
= new ToolContext
37 var modelbuilder
= new ModelBuilder(model
, toolcontext
)
38 var mmodules
= modelbuilder
.parse_full
([test_src
])
39 modelbuilder
.run_phases
40 toolcontext
.run_global_phases
(mmodules
)
43 var index
= new CodeIndex(toolcontext
)
44 for mmodule
in mmodules
do
45 index
.index_mentity
(mmodule
)
48 modelbuilder
.paths
.add test_src
51 fun test_find1
is test
do
52 var query
= "import game\n"
53 var matches
= test_index
.match_code
(query
)
54 assert matches
.first
.document
.mentity
.full_name
== "test_prog::test_prog"
57 fun test_find2
is test
do
58 var query
= "import game\nimport rpg\n"
59 var matches
= test_index
.match_code
(query
)
60 assert matches
.first
.document
.mentity
.full_name
== "test_prog::game"
63 fun test_find3
is test
do
64 var query
= "import game\nclass MyGame\nsuper Game\nredef fun start_game do end\nend\n"
65 var matches
= test_index
.match_code
(query
)
66 assert matches
.first
.document
.mentity
.full_name
== "test_prog::game_examples"
69 fun test_find_error
is test
do
71 var matches
= test_index
.match_code
(query
)
72 assert matches
.is_empty