5e921b57eac91b3c5be337b324b96db3e46590ed
[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
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
37 var ip = im.mpackage
38 if ip == null or ip == p then continue
39 test_catalog.deps.add_edge(p, ip)
40 end
41 end
42 end
43 # Build the catalog
44 for mpackage in test_model.mpackages do
45 catalog.package_page(mpackage)
46 catalog.git_info(mpackage)
47 catalog.mpackage_stats(mpackage)
48 end
49 return catalog
50 end
51
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"
57 end
58
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
65 end
66
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
73 end
74
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
82 end
83
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
89 end
90
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
96 end
97
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
104 end
105
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"
112 end
113
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
121 end
122
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
130 end
131 end