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
20 class TestModelSerialization
23 var suite_path
: String = "NIT_TESTING_PATH".environ
24 var lib_path
: String = "{suite_path.dirname}/../../tests/test_prog"
26 private var model
: Model do
27 var toolcontext
= new ToolContext
29 var mbuilder
= new ModelBuilder(model
, toolcontext
)
30 var mmodules
= mbuilder
.parse_full
([lib_path
])
31 if mmodules
.is_empty
then return model
33 toolcontext
.run_global_phases
(mmodules
)
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
)
47 fun test_packages_to_full_json
is test
do
48 for mentity
in model
.mpackages
do
49 print mentity
.to_pretty_full_json
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
61 fun test_modules_to_full_json
is test
do
62 for mentity
in model
.mmodules
do
63 print mentity
.to_pretty_full_json
67 fun test_classes_to_full_json
is test
do
68 for mentity
in model
.mclasses
do
69 print mentity
.to_pretty_full_json
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
81 fun test_props_to_full_json
is test
do
82 for mentity
in model
.mproperties
do
83 print mentity
.to_pretty_full_json
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
96 redef class nitc
::Location
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
)
107 v
.serialize_attribute
("file", "test_location")