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_model
is test
18 import doc
::commands
::commands_model
20 class TestCommandsModel
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"
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"
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
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
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
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
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
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
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
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
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
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"
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
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
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
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
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
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
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
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
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