Skip to content

Commit

Permalink
Merge: Fix model_json and nitweb
Browse files Browse the repository at this point in the history
Was broken since #2312

* Migrate `model_json` to new serialization API
* Add tests to `model_json` to ensure this doesn't happen anymore
* Migrate `web` package and `nitweb` to new API

@xymus a lot of serialization for you. Note: for each entity, I needed two deserialization version `full` and no full. Wasn't sure on how to handle this concern properly with your API

Pull-Request: #2327
Reviewed-by: Alexis Laferrière <[email protected]>
  • Loading branch information
privat committed Dec 3, 2016
2 parents df1c460 + a1547db commit 86d9345
Show file tree
Hide file tree
Showing 13 changed files with 11,070 additions and 315 deletions.
370 changes: 168 additions & 202 deletions src/model/model_json.nit

Large diffs are not rendered by default.

111 changes: 111 additions & 0 deletions src/model/test_model_json.nit
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# This file is part of NIT ( http://www.nitlanguage.org ).
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

module test_model_json is test_suite

import test_suite
import model_json
import frontend

class TestModelSerialization
super TestSuite

var suite_path: String = "NIT_TESTING_PATH".environ
var lib_path: String = "{suite_path.dirname}/../../tests/test_prog"

private var model: Model do
var toolcontext = new ToolContext
var model = new Model
var mbuilder = new ModelBuilder(model, toolcontext)
var mmodules = mbuilder.parse_full([lib_path])
if mmodules.is_empty then return model
mbuilder.run_phases
toolcontext.run_global_phases(mmodules)
return model
end

fun test_refs_to_full_json do
var mentities = new Array[MEntity]
mentities.add model.mpackages.first
mentities.add model.mmodules.first
mentities.add model.mclasses.first
for mentity in mentities do
print ((new MEntityRef(mentity)).to_pretty_full_json)
end
end

fun test_packages_to_full_json do
for mentity in model.mpackages do
print mentity.to_pretty_full_json
end
end

fun test_groups_to_full_json do
for mpackage in model.mpackages do
for mentity in mpackage.mgroups do
print mentity.to_pretty_full_json
end
end
end

fun test_modules_to_full_json do
for mentity in model.mmodules do
print mentity.to_pretty_full_json
end
end

fun test_classes_to_full_json do
for mentity in model.mclasses do
print mentity.to_pretty_full_json
end
end

fun test_classdefs_to_full_json do
for mclass in model.mclasses do
for mentity in mclass.mclassdefs do
print mentity.to_pretty_full_json
end
end
end

fun test_props_to_full_json do
for mentity in model.mproperties do
print mentity.to_pretty_full_json
end
end

fun test_propdefs_to_full_json do
for mprop in model.mproperties do
for mentity in mprop.mpropdefs do
print mentity.to_pretty_full_json
end
end
end
end

redef class Location
serialize

# Avoid diff on location absolute path
redef fun core_serialize_to(v) do
v.serialize_attribute("column_end", column_end)
v.serialize_attribute("column_start", column_start)
v.serialize_attribute("line_end", line_end)
v.serialize_attribute("line_start", line_start)
var file = self.file
if file != null then
v.serialize_attribute("file", "test_location")
end
end
end
Loading

0 comments on commit 86d9345

Please sign in to comment.