test_commands_catalog: Update to use packages importation graph
[nit.git] / src / doc / commands / tests / test_commands_catalog.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_catalog is test
16
17 import test_commands
18 import doc::commands::commands_catalog
19
20 class TestCommandsCatalog
21 super TestCommands
22 test
23
24 # Catalog used for tests
25 var test_catalog: Catalog is lazy do
26 var catalog = new Catalog(test_builder)
27
28 # Compute the poset
29 for p in test_model.mpackages do
30 var g = p.root
31 assert g != null
32 test_builder.scan_group(g)
33 end
34 # Build the catalog
35 for mpackage in test_model.mpackages do
36 catalog.package_page(mpackage)
37 catalog.git_info(mpackage)
38 catalog.mpackage_stats(mpackage)
39 end
40 return catalog
41 end
42
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"
48 end
49
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
56 end
57
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
64 end
65
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
73 end
74
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
80 end
81
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
87 end
88
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
95 end
96
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"
103 end
104
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
112 end
113
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
121 end
122 end