tests: Fix tests
[nit.git] / src / doc / commands / tests / test_commands_model.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_commands_model is test
16
17 import test_commands
18 import doc::commands::commands_model
19
20 class TestCommandsModel
21 super TestCommands
22 test
23
24 # CmdEntity
25
26 fun test_cmd_entity is test do
27 var cmd = new CmdEntity(test_model, mentity_name = "test_prog::Character")
28 var res = cmd.init_command
29 assert res isa CmdSuccess
30 assert cmd.mentity.as(not null).full_name == "test_prog::Character"
31 end
32
33 fun test_cmd_entity_not_found is test do
34 var cmd = new CmdEntity(test_model, mentity_name = "test_prog::Characterz")
35 var res = cmd.init_command
36 assert res isa ErrorMEntityNotFound
37 assert res.suggestions.first.full_name == "test_prog::Character"
38 end
39
40 fun test_cmd_entity_conflict is test do
41 var cmd = new CmdEntity(test_model, mentity_name = "+")
42 var res = cmd.init_command
43 assert res isa ErrorMEntityConflict
44 assert res.conflicts.length == 2
45 end
46
47 fun test_cmd_entity_no_name is test do
48 var cmd = new CmdEntity(test_model)
49 var res = cmd.init_command
50 assert res isa ErrorMEntityNoName
51 end
52
53 # CmdComment
54
55 fun test_cmd_comment is test do
56 var cmd = new CmdComment(test_model, mentity_name = "test_prog::Character")
57 var res = cmd.init_command
58 assert res isa CmdSuccess
59 assert cmd.mdoc != null
60 end
61
62 fun test_cmd_comment_no_mdoc is test do
63 var cmd = new CmdComment(test_model, mentity_name = "test_prog::Character", fallback = false)
64 var res = cmd.init_command
65 assert res isa WarningNoMDoc
66 end
67
68 # CmdLink
69
70 fun test_cmd_link is test do
71 var cmd = new CmdEntityLink(test_model, mentity_name = "test_prog::Character")
72 var res = cmd.init_command
73 assert res isa CmdSuccess
74 assert cmd.text == "Character"
75 assert cmd.title == "Characters can be played by both the human or the machine."
76 end
77
78 fun test_cmd_link_with_text is test do
79 var cmd = new CmdEntityLink(test_model, mentity_name = "test_prog::Character", text = "foo")
80 var res = cmd.init_command
81 assert res isa CmdSuccess
82 assert cmd.text == "foo"
83 assert cmd.title == "Characters can be played by both the human or the machine."
84 end
85
86 fun test_cmd_link_with_title is test do
87 var cmd = new CmdEntityLink(test_model, mentity_name = "test_prog::Character", title = "bar")
88 var res = cmd.init_command
89 assert res isa CmdSuccess
90 assert cmd.text == "Character"
91 assert cmd.title == "bar"
92 end
93
94 fun test_cmd_link_with_text_and_title is test do
95 var cmd = new CmdEntityLink(test_model, mentity_name = "test_prog::Character",
96 text = "foo", title = "bar")
97 var res = cmd.init_command
98 assert res isa CmdSuccess
99 assert cmd.text == "foo"
100 assert cmd.title == "bar"
101 end
102
103 # CmdInheritance
104
105 fun test_cmd_parents is test do
106 var cmd = new CmdParents(test_model, test_main, mentity_name = "test_prog::Warrior")
107 var res = cmd.init_command
108 assert res isa CmdSuccess
109 assert cmd.results.as(not null).length == 1
110 end
111
112 fun test_cmd_ancestors is test do
113 var cmd = new CmdAncestors(test_model, test_main, mentity_name = "test_prog::Warrior")
114 var res = cmd.init_command
115 assert res isa CmdSuccess
116 assert cmd.results.as(not null).length == 2
117 end
118
119 fun test_cmd_ancestors_without_parents is test do
120 var cmd = new CmdAncestors(test_model, test_main, mentity_name = "test_prog::Warrior", parents = false)
121 var res = cmd.init_command
122 assert res isa CmdSuccess
123 assert cmd.results.as(not null).length == 1
124 end
125
126 fun test_cmd_children is test do
127 var cmd = new CmdChildren(test_model, test_main, mentity_name = "test_prog::Career")
128 var res = cmd.init_command
129 assert res isa CmdSuccess
130 assert cmd.results.as(not null).length == 3
131 end
132
133 fun test_cmd_children_without_filter is test do
134 var cmd = new CmdDescendants(test_model, test_main, mentity_name = "test_prog::Game")
135 var res = cmd.init_command
136 assert res isa CmdSuccess
137 assert cmd.results.as(not null).length == 2
138 end
139
140 fun test_cmd_children_with_filter_example is test do
141 var filter = new ModelFilter(accept_example = false)
142 var cmd = new CmdDescendants(test_model, test_main, filter, mentity_name = "test_prog::Game")
143 var res = cmd.init_command
144 assert res isa CmdSuccess
145 assert cmd.results.as(not null).length == 1
146 end
147
148 fun test_cmd_children_with_filter_match is test do
149 var filter = new ModelFilter(accept_full_name = "MyGame")
150 var cmd = new CmdDescendants(test_model, test_main, filter, mentity_name = "test_prog::Game")
151 var res = cmd.init_command
152 assert res isa CmdSuccess
153 assert cmd.results.as(not null).length == 1
154 end
155
156 fun test_cmd_descendants is test do
157 var cmd = new CmdDescendants(test_model, test_main, mentity_name = "test_prog::Career", children = false)
158 var res = cmd.init_command
159 assert res isa CmdSuccess
160 assert cmd.results.as(not null).length == 0
161 end
162
163 # CmdSearch
164
165 fun test_cmd_search is test do
166 var cmd = new CmdSearch(test_model, query = "Carer")
167 var res = cmd.init_command
168 assert res isa CmdSuccess
169 assert cmd.results.as(not null).first.full_name == "test_prog::Career"
170 end
171
172 fun test_cmd_search_no_query is test do
173 var cmd = new CmdSearch(test_model)
174 var res = cmd.init_command
175 assert res isa ErrorNoQuery
176 end
177
178 # CmdFeatures
179
180 fun test_cmd_features is test do
181 var cmd = new CmdFeatures(test_model, mentity_name = "test_prog::Career")
182 var res = cmd.init_command
183 assert res isa CmdSuccess
184 assert cmd.results.as(not null).length == 11
185 end
186
187 fun test_cmd_features_with_filter_attribute is test do
188 var filter = new ModelFilter(accept_attribute = false)
189 var cmd = new CmdFeatures(test_model, filter, mentity_name = "test_prog::Career")
190 var res = cmd.init_command
191 assert res isa CmdSuccess
192 assert cmd.results.as(not null).length == 8
193 end
194
195 fun test_cmd_features_with_filter_public is test do
196 var filter = new ModelFilter(min_visibility = public_visibility)
197 var cmd = new CmdFeatures(test_model, filter, mentity_name = "test_prog::Career")
198 var res = cmd.init_command
199 assert res isa CmdSuccess
200 assert cmd.results.as(not null).length == 5
201 end
202
203 fun test_cmd_features_with_filter_match is test do
204 var filter = new ModelFilter(accept_full_name = "endurance")
205 var cmd = new CmdFeatures(test_model, filter, mentity_name = "test_prog::Career")
206 var res = cmd.init_command
207 assert res isa CmdSuccess
208 assert cmd.results.as(not null).length == 3
209 end
210
211 fun test_cmd_features_with_filter_inh is test do
212 var context = test_model.mentity_by_full_name("test_prog::TestGame").as(not null)
213 var filter = new ModelFilter(accept_inherited = context)
214 var cmd = new CmdFeatures(test_model, filter, mentity_name = "test_prog::TestGame")
215 var res = cmd.init_command
216 assert res isa CmdSuccess
217 assert cmd.results.as(not null).length == 4
218 end
219
220 fun test_cmd_features_no_features is test do
221 var cmd = new CmdFeatures(test_model, mentity_name = "test_prog$Career$strength_bonus")
222 var res = cmd.init_command
223 assert res isa WarningNoFeatures
224 end
225
226 # CmdLinearization
227
228 fun test_cmd_lin is test do
229 var cmd = new CmdLinearization(test_model, test_main, mentity_name = "init")
230 var res = cmd.init_command
231 assert res isa CmdSuccess
232 assert cmd.results.as(not null).length == 9
233 end
234
235 fun test_cmd_lin_no_lin is test do
236 var cmd = new CmdLinearization(test_model, test_main, mentity_name = "test_prog")
237 var res = cmd.init_command
238 assert res isa WarningNoLinearization
239 end
240
241 # CmdCode
242
243 fun test_cmd_code is test do
244 var cmd = new CmdEntityCode(test_model, test_builder, mentity_name = "test_prog::Career")
245 var res = cmd.init_command
246 assert res isa CmdSuccess
247 assert cmd.node isa AStdClassdef
248 end
249
250 fun test_cmd_code_no_code is test do
251 var cmd = new CmdEntityCode(test_model, test_builder, mentity_name = "test_prog")
252 var res = cmd.init_command
253 assert res isa WarningNoCode
254 end
255
256 # CmdModel
257
258 fun test_cmd_results is test do
259 var cmd = new CmdModelEntities(test_model, kind = "modules")
260 var res = cmd.init_command
261 assert res isa CmdSuccess
262 assert cmd.results.as(not null).length == 11
263 end
264
265 fun test_cmd_results_with_filter is test do
266 var filter = new ModelFilter(accept_test = false, accept_example = false)
267 var cmd = new CmdModelEntities(test_model, filter, kind = "modules")
268 var res = cmd.init_command
269 assert res isa CmdSuccess
270 print cmd.results.as(not null)
271 assert cmd.results.as(not null).length == 9
272 end
273
274 fun test_cmd_results_random is test do
275 var cmd = new CmdRandomEntities(test_model, kind = "packages")
276 var res = cmd.init_command
277 assert res isa CmdSuccess
278 assert cmd.results.as(not null).length == 2
279 end
280 end