doc/commands: introduce commands results to json translation
[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 # CmdInheritance
44
45 fun test_cmd_parents is test do
46 var cmd = new CmdParents(test_view, mentity_name = "test_prog::Warrior")
47 cmd.init_command
48 print_json cmd.to_json
49 end
50
51 fun test_cmd_ancestors is test do
52 var cmd = new CmdAncestors(test_view, mentity_name = "test_prog::Warrior", parents = false)
53 cmd.init_command
54 print_json cmd.to_json
55 end
56
57 fun test_cmd_children is test do
58 var cmd = new CmdChildren(test_view, mentity_name = "test_prog::Career")
59 cmd.init_command
60 print_json cmd.to_json
61 end
62
63 fun test_cmd_descendants is test do
64 var cmd = new CmdDescendants(test_view, mentity_name = "test_prog::Career")
65 cmd.init_command
66 print_json cmd.to_json
67 end
68
69 # CmdSearch
70
71 fun test_cmd_search is test do
72 var cmd = new CmdSearch(test_view, query = "Carer", limit = 10)
73 cmd.init_command
74 print_json cmd.to_json
75 end
76
77 # CmdFeatures
78
79 fun test_cmd_features is test do
80 var cmd = new CmdFeatures(test_view, mentity_name = "test_prog::Career")
81 cmd.init_command
82 print_json cmd.to_json
83 end
84
85 # CmdLinearization
86
87 fun test_cmd_lin is test do
88 var cmd = new CmdLinearization(test_view, mentity_name = "init")
89 cmd.init_command
90 print_json cmd.to_json
91 end
92
93 # CmdModel
94
95 fun test_cmd_mentities is test do
96 var cmd = new CmdModelEntities(test_view, kind = "modules")
97 cmd.init_command
98 print_json cmd.to_json
99 end
100
101 # CmdUsage
102
103 fun test_cmd_new is test do
104 var cmd = new CmdNew(test_view, test_builder, mentity_name = "test_prog::Character")
105 cmd.init_command
106 print_json cmd.to_json
107 end
108
109 fun test_cmd_call is test do
110 var cmd = new CmdCall(test_view, test_builder, mentity_name = "strength_bonus")
111 cmd.init_command
112 print_json cmd.to_json
113 end
114
115 fun test_cmd_return is test do
116 var cmd = new CmdReturn(test_view, mentity_name = "test_prog::Character")
117 cmd.init_command
118 print_json cmd.to_json
119 end
120
121 fun test_cmd_param is test do
122 var cmd = new CmdParam(test_view, mentity_name = "test_prog::Character")
123 cmd.init_command
124 print_json cmd.to_json
125 end
126 end
127
128 redef class nitc::Location
129 serialize
130
131 # Avoid diff on location absolute path
132 redef fun core_serialize_to(v) do
133 v.serialize_attribute("column_end", column_end)
134 v.serialize_attribute("column_start", column_start)
135 v.serialize_attribute("line_end", line_end)
136 v.serialize_attribute("line_start", line_start)
137 var file = self.file
138 if file != null then
139 v.serialize_attribute("file", "test_location")
140 end
141 end
142 end