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_catalog
is test
18 import doc
::commands
::commands_catalog
20 class TestCommandsCatalog
24 # Catalog used for tests
25 var test_catalog
: Catalog is lazy
do
26 var catalog
= new Catalog(test_builder
)
29 for p
in test_model
.mpackages
do
32 test_builder
.scan_group
(g
)
34 catalog
.deps
.add_node
(p
)
35 for gg
in p
.mgroups
do for m
in gg
.mmodules
do
36 for im
in m
.in_importation
.direct_greaters
do
38 if ip
== null or ip
== p
then continue
39 test_catalog
.deps
.add_edge
(p
, ip
)
44 for mpackage
in test_model
.mpackages
do
45 catalog
.package_page
(mpackage
)
46 catalog
.git_info
(mpackage
)
47 catalog
.mpackage_stats
(mpackage
)
52 fun test_cmd_catalog
is test
do
53 var cmd
= new CmdCatalogPackages(test_model
, test_catalog
)
54 var res
= cmd
.init_command
55 assert res
isa CmdSuccess
56 assert cmd
.results
.as(not null).first
.full_name
== "test_prog"
59 fun test_cmd_catalog_search
is test
do
60 var cmd
= new CmdCatalogSearch(test_model
, test_catalog
, query
= "testprog")
61 var res
= cmd
.init_command
62 assert res
isa CmdSuccess
63 assert cmd
.results
.as(not null).first
.full_name
== "test_prog"
64 assert cmd
.results
.as(not null).first
isa MPackage
67 fun test_cmd_catalog_search_without_filter
is test
do
68 var cmd
= new CmdCatalogSearch(test_model
, test_catalog
, query
= "MyGame")
69 var res
= cmd
.init_command
70 assert res
isa CmdSuccess
71 assert cmd
.results
.as(not null).first
.full_name
== "test_prog::MyGame"
72 assert cmd
.results
.as(not null).first
isa MClass
75 fun test_cmd_catalog_search_with_filter
is test
do
76 var filter
= new ModelFilter(accept_example
= false)
77 var cmd
= new CmdCatalogSearch(test_model
, test_catalog
, filter
, query
= "MGame")
78 var res
= cmd
.init_command
79 assert res
isa CmdSuccess
80 assert cmd
.results
.as(not null).first
.full_name
== "test_prog::Game" # not MyGame
81 assert cmd
.results
.as(not null).first
isa MClass
84 fun test_cmd_catalog_stats
is test
do
85 var cmd
= new CmdCatalogStats(test_model
, test_catalog
)
86 var res
= cmd
.init_command
87 assert res
isa CmdSuccess
88 assert cmd
.stats
!= null
91 fun test_cmd_catalog_tags
is test
do
92 var cmd
= new CmdCatalogTags(test_model
, test_catalog
)
93 var res
= cmd
.init_command
94 assert res
isa CmdSuccess
95 assert cmd
.packages_count_by_tags
.as(not null).length
== 2
98 fun test_cmd_catalog_tag
is test
do
99 var cmd
= new CmdCatalogTag(test_model
, test_catalog
, tag
= "test")
100 var res
= cmd
.init_command
101 assert res
isa CmdSuccess
102 assert cmd
.tag
== "test"
103 assert cmd
.results
.as(not null).length
== 1
106 fun test_cmd_catalog_person
is test
do
107 var cmd
= new CmdCatalogPerson(test_model
, test_catalog
,
108 person_name
= "Alexandre Terrasa")
109 var res
= cmd
.init_command
110 assert res
isa CmdSuccess
111 assert cmd
.person
.as(not null).name
== "Alexandre Terrasa"
114 fun test_cmd_catalog_contributing
is test
do
115 var cmd
= new CmdCatalogContributing(test_model
, test_catalog
,
116 person_name
= "Alexandre Terrasa")
117 var res
= cmd
.init_command
118 assert res
isa CmdSuccess
119 assert cmd
.person
.as(not null).name
== "Alexandre Terrasa"
120 assert cmd
.results
.as(not null).length
== 1
123 fun test_cmd_catalog_maintaining
is test
do
124 var cmd
= new CmdCatalogMaintaining(test_model
, test_catalog
,
125 person_name
= "Alexandre Terrasa")
126 var res
= cmd
.init_command
127 assert res
isa CmdSuccess
128 assert cmd
.person
.as(not null).name
== "Alexandre Terrasa"
129 assert cmd
.results
.as(not null).length
== 2