Merge: nitunit: use annotations
[nit.git] / src / model / test_model_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_model_json is test
16
17 import model_json
18 import frontend
19
20 class TestModelSerialization
21 test
22
23 var suite_path: String = "NIT_TESTING_PATH".environ
24 var lib_path: String = "{suite_path.dirname}/../../tests/test_prog"
25
26 private var model: Model do
27 var toolcontext = new ToolContext
28 var model = new Model
29 var mbuilder = new ModelBuilder(model, toolcontext)
30 var mmodules = mbuilder.parse_full([lib_path])
31 if mmodules.is_empty then return model
32 mbuilder.run_phases
33 toolcontext.run_global_phases(mmodules)
34 return model
35 end
36
37 fun test_refs_to_full_json is test do
38 var mentities = new Array[MEntity]
39 mentities.add model.mpackages.first
40 mentities.add model.mmodules.first
41 mentities.add model.mclasses.first
42 for mentity in mentities do
43 print ((new MEntityRef(mentity)).to_pretty_full_json)
44 end
45 end
46
47 fun test_packages_to_full_json is test do
48 for mentity in model.mpackages do
49 print mentity.to_pretty_full_json
50 end
51 end
52
53 fun test_groups_to_full_json is test do
54 for mpackage in model.mpackages do
55 for mentity in mpackage.mgroups do
56 print mentity.to_pretty_full_json
57 end
58 end
59 end
60
61 fun test_modules_to_full_json is test do
62 for mentity in model.mmodules do
63 print mentity.to_pretty_full_json
64 end
65 end
66
67 fun test_classes_to_full_json is test do
68 for mentity in model.mclasses do
69 print mentity.to_pretty_full_json
70 end
71 end
72
73 fun test_classdefs_to_full_json is test do
74 for mclass in model.mclasses do
75 for mentity in mclass.mclassdefs do
76 print mentity.to_pretty_full_json
77 end
78 end
79 end
80
81 fun test_props_to_full_json is test do
82 for mentity in model.mproperties do
83 print mentity.to_pretty_full_json
84 end
85 end
86
87 fun test_propdefs_to_full_json is test do
88 for mprop in model.mproperties do
89 for mentity in mprop.mpropdefs do
90 print mentity.to_pretty_full_json
91 end
92 end
93 end
94 end
95
96 redef class nitc::Location
97 serialize
98
99 # Avoid diff on location absolute path
100 redef fun core_serialize_to(v) do
101 v.serialize_attribute("column_end", column_end)
102 v.serialize_attribute("column_start", column_start)
103 v.serialize_attribute("line_end", line_end)
104 v.serialize_attribute("line_start", line_start)
105 var file = self.file
106 if file != null then
107 v.serialize_attribute("file", "test_location")
108 end
109 end
110 end