doc/commands: introduce CmdEntityLink command
[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_view, 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_view, mentity_name = "test_prog::Characterzz")
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_view, 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_view)
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_view, 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_view, 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_view, 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_view, 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_view, 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_view, 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_view, 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_view, 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_ancestorsi_without_parents is test do
120 var cmd = new CmdAncestors(test_view, 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_view, 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_descendants is test do
134 var cmd = new CmdDescendants(test_view, mentity_name = "test_prog::Career", children = false)
135 var res = cmd.init_command
136 assert res isa CmdSuccess
137 assert cmd.results.as(not null).length == 0
138 end
139
140 # CmdSearch
141
142 fun test_cmd_search is test do
143 var cmd = new CmdSearch(test_view, query = "Carer")
144 var res = cmd.init_command
145 assert res isa CmdSuccess
146 assert cmd.results.as(not null).first.full_name == "test_prog::Career"
147 end
148
149 fun test_cmd_search_no_query is test do
150 var cmd = new CmdSearch(test_view)
151 var res = cmd.init_command
152 assert res isa ErrorNoQuery
153 end
154
155 # CmdFeatures
156
157 fun test_cmd_features is test do
158 var cmd = new CmdFeatures(test_view, mentity_name = "test_prog::Career")
159 var res = cmd.init_command
160 assert res isa CmdSuccess
161 assert cmd.results.as(not null).length == 10
162 end
163
164 fun test_cmd_features_no_features is test do
165 var cmd = new CmdFeatures(test_view, mentity_name = "test_prog$Career$strength_bonus")
166 var res = cmd.init_command
167 assert res isa WarningNoFeatures
168 end
169
170 # CmdLinearization
171
172 fun test_cmd_lin is test do
173 var cmd = new CmdLinearization(test_view, mentity_name = "init")
174 var res = cmd.init_command
175 assert res isa CmdSuccess
176 print cmd.results.as(not null)
177 assert cmd.results.as(not null).length == 10
178 end
179
180 fun test_cmd_lin_no_lin is test do
181 var cmd = new CmdLinearization(test_view, mentity_name = "test_prog")
182 var res = cmd.init_command
183 assert res isa WarningNoLinearization
184 end
185
186 # CmdCode
187
188 fun test_cmd_code is test do
189 var cmd = new CmdEntityCode(test_view, test_builder, mentity_name = "test_prog::Career")
190 var res = cmd.init_command
191 assert res isa CmdSuccess
192 assert cmd.node isa AStdClassdef
193 end
194
195 fun test_cmd_code_no_code is test do
196 var cmd = new CmdEntityCode(test_view, test_builder, mentity_name = "test_prog")
197 var res = cmd.init_command
198 assert res isa WarningNoCode
199 end
200
201 # CmdModel
202
203 fun test_cmd_results is test do
204 var cmd = new CmdModelEntities(test_view, kind = "modules")
205 var res = cmd.init_command
206 assert res isa CmdSuccess
207 assert cmd.results.as(not null).length == 10
208 end
209
210 fun test_cmd_results_random is test do
211 var cmd = new CmdRandomEntities(test_view, kind = "packages")
212 var res = cmd.init_command
213 assert res isa CmdSuccess
214 assert cmd.results.as(not null).length == 2
215 end
216 end