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_commands_parser
is test
18 import doc
::commands
::tests
::test_commands_catalog
19 import doc
::commands
::commands_parser
21 class TestCommandsParser
22 super TestCommandsCatalog
27 fun test_cmd_parser_comment
is test
do
28 var parser
= new CommandParser(test_view
, test_builder
)
29 var cmd
= parser
.parse
("doc: test_prog::Character")
30 assert cmd
isa CmdComment
31 assert parser
.error
== null
32 assert cmd
.mdoc
!= null
37 fun test_cmd_parser_parents
is test
do
38 var parser
= new CommandParser(test_view
, test_builder
)
39 var cmd
= parser
.parse
("parents: test_prog::Warrior")
40 assert cmd
isa CmdParents
41 assert parser
.error
== null
42 assert cmd
.results
.as(not null).length
== 1
45 fun test_cmd_parser_ancestors
is test
do
46 var parser
= new CommandParser(test_view
, test_builder
)
47 var cmd
= parser
.parse
("ancestors: test_prog::Warrior")
48 assert cmd
isa CmdAncestors
49 assert parser
.error
== null
50 assert cmd
.results
.as(not null).length
== 2
53 fun test_cmd_parser_ancestors_without_parents
is test
do
54 var parser
= new CommandParser(test_view
, test_builder
)
55 var cmd
= parser
.parse
("ancestors: test_prog::Warrior | parents: false")
56 assert cmd
isa CmdAncestors
57 assert parser
.error
== null
58 assert cmd
.results
.as(not null).length
== 1
61 fun test_cmd_parser_children
is test
do
62 var parser
= new CommandParser(test_view
, test_builder
)
63 var cmd
= parser
.parse
("children: test_prog::Career")
64 assert cmd
isa CmdChildren
65 assert parser
.error
== null
66 assert cmd
.results
.as(not null).length
== 3
69 fun test_cmd_parser_descendants
is test
do
70 var parser
= new CommandParser(test_view
, test_builder
)
71 var cmd
= parser
.parse
("descendants: Object")
72 assert cmd
isa CmdDescendants
73 assert parser
.error
== null
74 assert cmd
.results
.as(not null).length
== 19
77 fun test_cmd_parser_descendants_without_children
is test
do
78 var parser
= new CommandParser(test_view
, test_builder
)
79 var cmd
= parser
.parse
("descendants: Object | children: false")
80 assert cmd
isa CmdDescendants
81 assert parser
.error
== null
82 print cmd
.results
.as(not null)
83 assert cmd
.results
.as(not null).length
== 7
88 fun test_cmd_parser_search
is test
do
89 var parser
= new CommandParser(test_view
, test_builder
)
90 var cmd
= parser
.parse
("search: Caracter")
91 assert cmd
isa CmdSearch
92 assert parser
.error
== null
93 assert cmd
.results
!= null
96 fun test_cmd_parser_search_limit
is test
do
97 var parser
= new CommandParser(test_view
, test_builder
)
98 var cmd
= parser
.parse
("search: Caracter | limit: 2")
99 assert cmd
isa CmdSearch
100 assert parser
.error
== null
101 assert cmd
.results
.as(not null).length
== 2
106 fun test_cmd_parser_features
is test
do
107 var parser
= new CommandParser(test_view
, test_builder
)
108 var cmd
= parser
.parse
("defs: test_prog::Character")
109 assert cmd
isa CmdFeatures
110 assert parser
.error
== null
111 assert cmd
.results
!= null
114 fun test_cmd_parser_features_limit
is test
do
115 var parser
= new CommandParser(test_view
, test_builder
)
116 var cmd
= parser
.parse
("defs: test_prog::Character | limit: 2")
117 assert cmd
isa CmdFeatures
118 assert parser
.error
== null
119 assert cmd
.results
.as(not null).length
== 2
124 fun test_cmd_parser_lin
is test
do
125 var parser
= new CommandParser(test_view
, test_builder
)
126 var cmd
= parser
.parse
("lin: test_prog::Character")
127 assert cmd
isa CmdLinearization
128 assert parser
.error
== null
129 assert cmd
.results
!= null
132 fun test_cmd_parser_lin_limit
is test
do
133 var parser
= new CommandParser(test_view
, test_builder
)
134 var cmd
= parser
.parse
("lin: test_prog::Character | limit: 2")
135 assert cmd
isa CmdLinearization
136 assert parser
.error
== null
137 assert cmd
.results
.as(not null).length
== 2
142 fun test_cmd_parser_code
is test
do
143 var parser
= new CommandParser(test_view
, test_builder
)
144 var cmd
= parser
.parse
("code: test_prog::Character")
145 assert cmd
isa CmdCode
146 assert parser
.error
== null
147 assert cmd
.node
!= null
152 fun test_cmd_parser_mentities
is test
do
153 var parser
= new CommandParser(test_view
, test_builder
)
154 var cmd
= parser
.parse
("list: modules")
155 assert cmd
isa CmdModelEntities
156 assert parser
.error
== null
157 assert cmd
.results
!= null
160 fun test_cmd_parser_results_mentities
is test
do
161 var parser
= new CommandParser(test_view
, test_builder
)
162 var cmd
= parser
.parse
("random: modules")
163 assert cmd
isa CmdRandomEntities
164 assert parser
.error
== null
165 assert cmd
.results
!= null
170 fun test_cmd_parser_uml
is test
do
171 var parser
= new CommandParser(test_view
, test_builder
)
172 var cmd
= parser
.parse
("uml: test_prog::Career")
173 assert cmd
isa CmdUML
174 assert parser
.error
== null
175 assert cmd
.uml
!= null
178 fun test_cmd_parser_inh_graph
is test
do
179 var parser
= new CommandParser(test_view
, test_builder
)
180 var cmd
= parser
.parse
("graph: test_prog::Career")
181 assert cmd
isa CmdInheritanceGraph
182 assert parser
.error
== null
183 assert cmd
.graph
!= null
186 fun test_cmd_parser_inh_graph_opts
is test
do
187 var parser
= new CommandParser(test_view
, test_builder
)
188 var cmd
= parser
.parse
("graph: test_prog::Career | cdepth: 2, pdepth: 5")
189 assert cmd
isa CmdInheritanceGraph
190 assert parser
.error
== null
191 assert cmd
.graph
!= null
192 assert cmd
.cdepth
== 2
193 assert cmd
.pdepth
== 5
198 fun test_cmd_parser_new
is test
do
199 var parser
= new CommandParser(test_view
, test_builder
)
200 var cmd
= parser
.parse
("new: test_prog::Career")
201 assert cmd
isa CmdNew
202 assert parser
.error
== null
203 assert cmd
.results
!= null
206 fun test_cmd_parser_call
is test
do
207 var parser
= new CommandParser(test_view
, test_builder
)
208 var cmd
= parser
.parse
("call: strength_bonus")
209 assert cmd
isa CmdCall
210 assert parser
.error
== null
211 assert cmd
.results
!= null
214 fun test_cmd_parser_return
is test
do
215 var parser
= new CommandParser(test_view
, test_builder
)
216 var cmd
= parser
.parse
("return: test_prog::Career")
217 assert cmd
isa CmdReturn
218 assert parser
.error
== null
219 assert cmd
.results
!= null
222 fun test_cmd_parser_param
is test
do
223 var parser
= new CommandParser(test_view
, test_builder
)
224 var cmd
= parser
.parse
("param: test_prog::Career")
225 assert cmd
isa CmdParam
226 assert parser
.error
== null
227 assert cmd
.results
!= null
232 fun test_parser_catalog_search
is test
do
233 var parser
= new CommandParser(test_view
, test_builder
)
234 var cmd
= parser
.parse
("search: Caracter")
235 assert cmd
isa CmdSearch
236 assert parser
.error
== null
237 assert cmd
.results
!= null
240 fun test_cmd_parser_catalog_packages
is test
do
241 var parser
= new CommandParser(test_view
, test_builder
, test_catalog
)
242 var cmd
= parser
.parse
("catalog:")
243 assert cmd
isa CmdCatalogPackages
244 assert parser
.error
== null
245 assert cmd
.results
!= null
248 fun test_cmd_parser_catalog_stats
is test
do
249 var parser
= new CommandParser(test_view
, test_builder
, test_catalog
)
250 var cmd
= parser
.parse
("stats:")
251 assert cmd
isa CmdCatalogStats
252 assert parser
.error
== null
253 assert cmd
.stats
!= null
256 fun test_cmd_parser_catalog_tags
is test
do
257 var parser
= new CommandParser(test_view
, test_builder
, test_catalog
)
258 var cmd
= parser
.parse
("tags:")
259 assert cmd
isa CmdCatalogTags
260 assert parser
.error
== null
261 assert cmd
.packages_count_by_tags
!= null
264 fun test_cmd_parser_catalog_tag
is test
do
265 var parser
= new CommandParser(test_view
, test_builder
, test_catalog
)
266 var cmd
= parser
.parse
("tag: test")
267 assert cmd
isa CmdCatalogTag
268 assert parser
.error
== null
269 assert cmd
.tag
== "test"
270 assert cmd
.results
!= null
273 fun test_cmd_parser_catalog_person
is test
do
274 var parser
= new CommandParser(test_view
, test_builder
, test_catalog
)
275 var cmd
= parser
.parse
("person: Alexandre Terrasa")
276 assert cmd
isa CmdCatalogPerson
277 assert parser
.error
== null
278 assert cmd
.person
.as(not null).name
== "Alexandre Terrasa"
281 fun test_cmd_parser_catalog_contributing
is test
do
282 var parser
= new CommandParser(test_view
, test_builder
, test_catalog
)
283 var cmd
= parser
.parse
("contrib: Alexandre Terrasa")
284 assert cmd
isa CmdCatalogContributing
285 assert parser
.error
== null
286 assert cmd
.person
.as(not null).name
== "Alexandre Terrasa"
287 assert cmd
.results
!= null
290 fun test_cmd_parser_catalog_maintaining
is test
do
291 var parser
= new CommandParser(test_view
, test_builder
, test_catalog
)
292 var cmd
= parser
.parse
("maintain: Alexandre Terrasa")
293 assert cmd
isa CmdCatalogMaintaining
294 assert parser
.error
== null
295 assert cmd
.person
.as(not null).name
== "Alexandre Terrasa"
296 assert cmd
.results
!= null