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_templates_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 var mainmodule
: MModule is noinit
28 private var model
: Model do
29 var toolcontext
= new ToolContext
31 var mbuilder
= new ModelBuilder(model
, toolcontext
)
32 var mmodules
= mbuilder
.parse_full
([lib_path
])
33 if mmodules
.is_empty
then return model
35 toolcontext
.run_global_phases
(mmodules
)
36 mainmodule
= mmodules
.first
40 fun test_refs_to_full_json
is test
do
41 var mentities
= new Array[MEntity]
42 mentities
.add model
.mpackages
.first
43 mentities
.add model
.mmodules
.first
44 mentities
.add model
.mclasses
.first
45 for mentity
in mentities
do
46 print
((new MEntityRef(mentity
)).serialize_to_json
(pretty
= true, plain
= true))
50 fun test_packages_to_full_json
is test
do
51 for mentity
in model
.mpackages
do
52 print mentity
.serialize_to_json
(pretty
= true, plain
= true)
56 fun test_groups_to_full_json
is test
do
57 for mpackage
in model
.mpackages
do
58 for mentity
in mpackage
.mgroups
do
59 print mentity
.serialize_to_json
(pretty
= true, plain
= true)
64 fun test_modules_to_full_json
is test
do
65 for mentity
in model
.mmodules
do
66 print mentity
.serialize_to_json
(pretty
= true, plain
= true)
70 fun test_classes_to_full_json
is test
do
71 for mentity
in model
.mclasses
do
72 print mentity
.serialize_to_json
(pretty
= true, plain
= true)
76 fun test_classdefs_to_full_json
is test
do
77 for mclass
in model
.mclasses
do
78 for mentity
in mclass
.mclassdefs
do
79 print mentity
.serialize_to_json
(pretty
= true, plain
= true)
84 fun test_props_to_full_json
is test
do
85 for mentity
in model
.mproperties
do
86 print mentity
.serialize_to_json
(pretty
= true, plain
= true)
90 fun test_propdefs_to_full_json
is test
do
91 for mprop
in model
.mproperties
do
92 for mentity
in mprop
.mpropdefs
do
93 print mentity
.serialize_to_json
(pretty
= true, plain
= true)
99 redef class nitc
::Location
102 # Avoid diff on location absolute path
103 redef fun core_serialize_to
(v
) do
104 v
.serialize_attribute
("column_end", column_end
)
105 v
.serialize_attribute
("column_start", column_start
)
106 v
.serialize_attribute
("line_end", line_end
)
107 v
.serialize_attribute
("line_start", line_start
)
110 v
.serialize_attribute
("file", "test_location")