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
)
35 for mpackage
in test_model
.mpackages
do
36 catalog
.package_page
(mpackage
)
37 catalog
.git_info
(mpackage
)
38 catalog
.mpackage_stats
(mpackage
)
43 fun test_cmd_catalog
is test
do
44 var cmd
= new CmdCatalogPackages(test_model
, test_catalog
)
45 var res
= cmd
.init_command
46 assert res
isa CmdSuccess
47 assert cmd
.results
.as(not null).first
.full_name
== "test_prog"
50 fun test_cmd_catalog_search
is test
do
51 var cmd
= new CmdCatalogSearch(test_model
, test_catalog
, query
= "testprog")
52 var res
= cmd
.init_command
53 assert res
isa CmdSuccess
54 assert cmd
.results
.as(not null).first
.full_name
== "test_prog"
55 assert cmd
.results
.as(not null).first
isa MPackage
58 fun test_cmd_catalog_search_without_filter
is test
do
59 var cmd
= new CmdCatalogSearch(test_model
, test_catalog
, query
= "MyGame")
60 var res
= cmd
.init_command
61 assert res
isa CmdSuccess
62 assert cmd
.results
.as(not null).first
.full_name
== "test_prog::MyGame"
63 assert cmd
.results
.as(not null).first
isa MClass
66 fun test_cmd_catalog_search_with_filter
is test
do
67 var filter
= new ModelFilter(accept_example
= false)
68 var cmd
= new CmdCatalogSearch(test_model
, test_catalog
, filter
, query
= "MGame")
69 var res
= cmd
.init_command
70 assert res
isa CmdSuccess
71 assert cmd
.results
.as(not null).first
.full_name
== "test_prog::Game" # not MyGame
72 assert cmd
.results
.as(not null).first
isa MClass
75 fun test_cmd_catalog_stats
is test
do
76 var cmd
= new CmdCatalogStats(test_model
, test_catalog
)
77 var res
= cmd
.init_command
78 assert res
isa CmdSuccess
79 assert cmd
.stats
!= null
82 fun test_cmd_catalog_tags
is test
do
83 var cmd
= new CmdCatalogTags(test_model
, test_catalog
)
84 var res
= cmd
.init_command
85 assert res
isa CmdSuccess
86 assert cmd
.packages_count_by_tags
.as(not null).length
== 2
89 fun test_cmd_catalog_tag
is test
do
90 var cmd
= new CmdCatalogTag(test_model
, test_catalog
, tag
= "test")
91 var res
= cmd
.init_command
92 assert res
isa CmdSuccess
93 assert cmd
.tag
== "test"
94 assert cmd
.results
.as(not null).length
== 1
97 fun test_cmd_catalog_person
is test
do
98 var cmd
= new CmdCatalogPerson(test_model
, test_catalog
,
99 person_name
= "Alexandre Terrasa")
100 var res
= cmd
.init_command
101 assert res
isa CmdSuccess
102 assert cmd
.person
.as(not null).name
== "Alexandre Terrasa"
105 fun test_cmd_catalog_contributing
is test
do
106 var cmd
= new CmdCatalogContributing(test_model
, test_catalog
,
107 person_name
= "Alexandre Terrasa")
108 var res
= cmd
.init_command
109 assert res
isa CmdSuccess
110 assert cmd
.person
.as(not null).name
== "Alexandre Terrasa"
111 assert cmd
.results
.as(not null).length
== 1
114 fun test_cmd_catalog_maintaining
is test
do
115 var cmd
= new CmdCatalogMaintaining(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
== 2