doc: Commands tests use `test_frontend`
[nit.git] / src / doc / templates / tests / test_json_model.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_json_model is test
16
17 import json_model
18 import test_frontend
19
20 class TestModelSerialization
21 super TestModel
22 test
23
24 fun test_refs_to_full_json is test do
25 var mentities = new Array[MEntity]
26 mentities.add test_model.mpackages.first
27 mentities.add test_model.mmodules.first
28 mentities.add test_model.mclasses.first
29 for mentity in mentities do
30 print ((new MEntityRef(mentity)).serialize_to_json(pretty = true, plain = true))
31 end
32 end
33
34 fun test_packages_to_full_json is test do
35 for mentity in test_model.mpackages do
36 print mentity.serialize_to_json(pretty = true, plain = true)
37 end
38 end
39
40 fun test_groups_to_full_json is test do
41 for mpackage in test_model.mpackages do
42 for mentity in mpackage.mgroups do
43 print mentity.serialize_to_json(pretty = true, plain = true)
44 end
45 end
46 end
47
48 fun test_modules_to_full_json is test do
49 for mentity in test_model.mmodules do
50 print mentity.serialize_to_json(pretty = true, plain = true)
51 end
52 end
53
54 fun test_classes_to_full_json is test do
55 for mentity in test_model.mclasses do
56 print mentity.serialize_to_json(pretty = true, plain = true)
57 end
58 end
59
60 fun test_classdefs_to_full_json is test do
61 for mclass in test_model.mclasses do
62 for mentity in mclass.mclassdefs do
63 print mentity.serialize_to_json(pretty = true, plain = true)
64 end
65 end
66 end
67
68 fun test_props_to_full_json is test do
69 for mentity in test_model.mproperties do
70 print mentity.serialize_to_json(pretty = true, plain = true)
71 end
72 end
73
74 fun test_propdefs_to_full_json is test do
75 for mprop in test_model.mproperties do
76 for mentity in mprop.mpropdefs do
77 print mentity.serialize_to_json(pretty = true, plain = true)
78 end
79 end
80 end
81 end
82
83 redef class nitc::Location
84 serialize
85
86 # Avoid diff on location absolute path
87 redef fun core_serialize_to(v) do
88 v.serialize_attribute("column_end", column_end)
89 v.serialize_attribute("column_start", column_start)
90 v.serialize_attribute("line_end", line_end)
91 v.serialize_attribute("line_start", line_start)
92 var file = self.file
93 if file != null then
94 v.serialize_attribute("file", "test_location")
95 end
96 end
97 end