doc/commands: introduce model commands
[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 # CmdInheritance
69
70 fun test_cmd_parents is test do
71 var cmd = new CmdParents(test_view, mentity_name = "test_prog::Warrior")
72 var res = cmd.init_command
73 assert res isa CmdSuccess
74 assert cmd.results.as(not null).length == 1
75 end
76
77 fun test_cmd_ancestors is test do
78 var cmd = new CmdAncestors(test_view, mentity_name = "test_prog::Warrior")
79 var res = cmd.init_command
80 assert res isa CmdSuccess
81 assert cmd.results.as(not null).length == 2
82 end
83
84 fun test_cmd_ancestorsi_without_parents is test do
85 var cmd = new CmdAncestors(test_view, mentity_name = "test_prog::Warrior", parents = false)
86 var res = cmd.init_command
87 assert res isa CmdSuccess
88 assert cmd.results.as(not null).length == 1
89 end
90
91 fun test_cmd_children is test do
92 var cmd = new CmdChildren(test_view, mentity_name = "test_prog::Career")
93 var res = cmd.init_command
94 assert res isa CmdSuccess
95 assert cmd.results.as(not null).length == 3
96 end
97
98 fun test_cmd_descendants is test do
99 var cmd = new CmdDescendants(test_view, mentity_name = "test_prog::Career", children = false)
100 var res = cmd.init_command
101 assert res isa CmdSuccess
102 assert cmd.results.as(not null).length == 0
103 end
104
105 # CmdSearch
106
107 fun test_cmd_search is test do
108 var cmd = new CmdSearch(test_view, query = "Carer")
109 var res = cmd.init_command
110 assert res isa CmdSuccess
111 assert cmd.results.as(not null).first.full_name == "test_prog::Career"
112 end
113
114 fun test_cmd_search_no_query is test do
115 var cmd = new CmdSearch(test_view)
116 var res = cmd.init_command
117 assert res isa ErrorNoQuery
118 end
119
120 # CmdFeatures
121
122 fun test_cmd_features is test do
123 var cmd = new CmdFeatures(test_view, mentity_name = "test_prog::Career")
124 var res = cmd.init_command
125 assert res isa CmdSuccess
126 assert cmd.results.as(not null).length == 10
127 end
128
129 fun test_cmd_features_no_features is test do
130 var cmd = new CmdFeatures(test_view, mentity_name = "test_prog$Career$strength_bonus")
131 var res = cmd.init_command
132 assert res isa WarningNoFeatures
133 end
134
135 # CmdLinearization
136
137 fun test_cmd_lin is test do
138 var cmd = new CmdLinearization(test_view, mentity_name = "init")
139 var res = cmd.init_command
140 assert res isa CmdSuccess
141 print cmd.results.as(not null)
142 assert cmd.results.as(not null).length == 10
143 end
144
145 fun test_cmd_lin_no_lin is test do
146 var cmd = new CmdLinearization(test_view, mentity_name = "test_prog")
147 var res = cmd.init_command
148 assert res isa WarningNoLinearization
149 end
150
151 # CmdCode
152
153 fun test_cmd_code is test do
154 var cmd = new CmdCode(test_view, test_builder, mentity_name = "test_prog::Career")
155 var res = cmd.init_command
156 assert res isa CmdSuccess
157 assert cmd.node isa AStdClassdef
158 end
159
160 fun test_cmd_code_no_code is test do
161 var cmd = new CmdCode(test_view, test_builder, mentity_name = "test_prog")
162 var res = cmd.init_command
163 assert res isa WarningNoCode
164 end
165
166 # CmdModel
167
168 fun test_cmd_results is test do
169 var cmd = new CmdModelEntities(test_view, kind = "modules")
170 var res = cmd.init_command
171 assert res isa CmdSuccess
172 assert cmd.results.as(not null).length == 9
173 end
174
175 fun test_cmd_results_random is test do
176 var cmd = new CmdRandomEntities(test_view, kind = "packages")
177 var res = cmd.init_command
178 assert res isa CmdSuccess
179 assert cmd.results.as(not null).length == 2
180 end
181 end