doc/commands: render `commands_ini` as JSON
[nit.git] / src / doc / commands / tests / test_commands_json.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_json is test
16
17 import test_commands
18 import doc::commands::commands_json
19
20 class TestCommandsJson
21 super TestCommands
22 test
23
24 fun print_json(json: nullable Serializable) do
25 if json == null then return
26 print json.serialize_to_json(pretty = true, plain = true)
27 end
28
29 # CmdEntity
30
31 fun test_cmd_entity is test do
32 var cmd = new CmdEntity(test_view, mentity_name = "test_prog::Character")
33 cmd.init_command
34 print_json cmd.to_json
35 end
36
37 fun test_cmd_comment is test do
38 var cmd = new CmdComment(test_view, mentity_name = "test_prog::Character")
39 cmd.init_command
40 print_json cmd.to_json
41 end
42
43 fun test_cmd_link is test do
44 var cmd = new CmdEntityLink(test_view, mentity_name = "test_prog::Character")
45 cmd.init_command
46 print_json cmd.to_json
47 end
48
49 # CmdInheritance
50
51 fun test_cmd_parents is test do
52 var cmd = new CmdParents(test_view, mentity_name = "test_prog::Warrior")
53 cmd.init_command
54 print_json cmd.to_json
55 end
56
57 fun test_cmd_ancestors is test do
58 var cmd = new CmdAncestors(test_view, mentity_name = "test_prog::Warrior", parents = false)
59 cmd.init_command
60 print_json cmd.to_json
61 end
62
63 fun test_cmd_children is test do
64 var cmd = new CmdChildren(test_view, mentity_name = "test_prog::Career")
65 cmd.init_command
66 print_json cmd.to_json
67 end
68
69 fun test_cmd_descendants is test do
70 var cmd = new CmdDescendants(test_view, mentity_name = "test_prog::Career")
71 cmd.init_command
72 print_json cmd.to_json
73 end
74
75 # CmdSearch
76
77 fun test_cmd_search is test do
78 var cmd = new CmdSearch(test_view, query = "Carer", limit = 10)
79 cmd.init_command
80 print_json cmd.to_json
81 end
82
83 # CmdFeatures
84
85 fun test_cmd_features is test do
86 var cmd = new CmdFeatures(test_view, mentity_name = "test_prog::Career")
87 cmd.init_command
88 print_json cmd.to_json
89 end
90
91 # CmdLinearization
92
93 fun test_cmd_lin is test do
94 var cmd = new CmdLinearization(test_view, mentity_name = "init")
95 cmd.init_command
96 print_json cmd.to_json
97 end
98
99 # CmdModel
100
101 fun test_cmd_mentities is test do
102 var cmd = new CmdModelEntities(test_view, kind = "modules")
103 cmd.init_command
104 print_json cmd.to_json
105 end
106
107 # CmdUsage
108
109 fun test_cmd_new is test do
110 var cmd = new CmdNew(test_view, test_builder, mentity_name = "test_prog::Character")
111 cmd.init_command
112 print_json cmd.to_json
113 end
114
115 fun test_cmd_call is test do
116 var cmd = new CmdCall(test_view, test_builder, mentity_name = "strength_bonus")
117 cmd.init_command
118 print_json cmd.to_json
119 end
120
121 fun test_cmd_return is test do
122 var cmd = new CmdReturn(test_view, mentity_name = "test_prog::Character")
123 cmd.init_command
124 print_json cmd.to_json
125 end
126
127 fun test_cmd_param is test do
128 var cmd = new CmdParam(test_view, mentity_name = "test_prog::Character")
129 cmd.init_command
130 print_json cmd.to_json
131 end
132
133 # CmdIni
134
135 fun test_cmd_ini_desc is test do
136 var cmd = new CmdIniDescription(test_view, mentity_name = "test_prog")
137 cmd.init_command
138 print_json cmd.to_json
139 end
140
141 fun test_cmd_ini_git is test do
142 var cmd = new CmdIniGitUrl(test_view, mentity_name = "test_prog")
143 cmd.init_command
144 print_json cmd.to_json
145 end
146
147 fun test_cmd_ini_clone is test do
148 var cmd = new CmdIniCloneCommand(test_view, mentity_name = "test_prog")
149 cmd.init_command
150 print_json cmd.to_json
151 end
152
153 fun test_cmd_ini_issues is test do
154 var cmd = new CmdIniIssuesUrl(test_view, mentity_name = "test_prog")
155 cmd.init_command
156 print_json cmd.to_json
157 end
158
159 fun test_cmd_ini_maintainer is test do
160 var cmd = new CmdIniMaintainer(test_view, mentity_name = "test_prog")
161 cmd.init_command
162 print_json cmd.to_json
163 end
164
165 fun test_cmd_ini_contributors is test do
166 var cmd = new CmdIniContributors(test_view, mentity_name = "test_prog")
167 cmd.init_command
168 print_json cmd.to_json
169 end
170
171 fun test_cmd_ini_license is test do
172 var cmd = new CmdIniLicense(test_view, mentity_name = "test_prog")
173 cmd.init_command
174 print_json cmd.to_json
175 end
176
177 fun test_cmd_ini_license_file is test do
178 var cmd = new CmdLicenseFile(test_view, mentity_name = "test_prog")
179 cmd.init_command
180 cmd.file = cmd.file.as(not null).basename # for testing path
181 print_json cmd.to_json
182 end
183
184 fun test_cmd_ini_license_file_content is test do
185 var cmd = new CmdLicenseFileContent(test_view, mentity_name = "test_prog")
186 cmd.init_command
187 cmd.file = cmd.file.as(not null).basename # for testing path
188 print_json cmd.to_json
189 end
190
191 fun test_cmd_ini_contrib_file is test do
192 var cmd = new CmdContribFile(test_view, mentity_name = "test_prog")
193 cmd.init_command
194 cmd.file = cmd.file.as(not null).basename # for testing path
195 print_json cmd.to_json
196 end
197
198 fun test_cmd_ini_contrib_file_content is test do
199 var cmd = new CmdContribFileContent(test_view, mentity_name = "test_prog")
200 cmd.init_command
201 cmd.file = cmd.file.as(not null).basename # for testing path
202 print_json cmd.to_json
203 end
204 end
205
206 redef class nitc::Location
207 serialize
208
209 # Avoid diff on location absolute path
210 redef fun core_serialize_to(v) do
211 v.serialize_attribute("column_end", column_end)
212 v.serialize_attribute("column_start", column_start)
213 v.serialize_attribute("line_end", line_end)
214 v.serialize_attribute("line_start", line_start)
215 var file = self.file
216 if file != null then
217 v.serialize_attribute("file", "test_location")
218 end
219 end
220 end