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