1 # This file is part of NIT ( http://www.nitlanguage.org ).
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 module test_model_json
is test_suite
21 class TestModelSerialization
24 var suite_path
: String = "NIT_TESTING_PATH".environ
25 var lib_path
: String = "{suite_path.dirname}/../../tests/test_prog"
27 private var model
: Model do
28 var toolcontext
= new ToolContext
30 var mbuilder
= new ModelBuilder(model
, toolcontext
)
31 var mmodules
= mbuilder
.parse_full
([lib_path
])
32 if mmodules
.is_empty
then return model
34 toolcontext
.run_global_phases
(mmodules
)
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
)
48 fun test_packages_to_full_json
do
49 for mentity
in model
.mpackages
do
50 print mentity
.to_pretty_full_json
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
62 fun test_modules_to_full_json
do
63 for mentity
in model
.mmodules
do
64 print mentity
.to_pretty_full_json
68 fun test_classes_to_full_json
do
69 for mentity
in model
.mclasses
do
70 print mentity
.to_pretty_full_json
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
82 fun test_props_to_full_json
do
83 for mentity
in model
.mproperties
do
84 print mentity
.to_pretty_full_json
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
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
)
108 v
.serialize_attribute
("file", "test_location")