Rename REAMDE to README.md
[nit.git] / src / test_neo.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 # Test for neo model saving and loading.
16 module test_neo
17
18 import neo
19 import model_utils
20 import frontend
21
22 var test_name = "test_{get_time.to_s}"
23
24 # init tool
25 var toolcontext = new ToolContext
26 toolcontext.tooldescription = "Usage: neo_saver host port files..."
27 toolcontext.process_options(args)
28 var arguments = toolcontext.option_context.rest
29
30 if arguments.length < 3 then
31 toolcontext.usage
32 exit 0
33 end
34
35 var host = arguments.shift
36 var port = arguments.shift
37 var url = "http://{host}:{port}"
38
39 # parse model
40 toolcontext.info("Parse files...", 1)
41 var org_model = new Model
42 var modelbuilder = new ModelBuilder(org_model, toolcontext)
43 modelbuilder.parse(arguments)
44 modelbuilder.run_phases
45
46 toolcontext.info("Open connection to neo4j on {url} for saving...", 1)
47 var save_client = new Neo4jClient(url)
48 var save_model = new NeoModel(test_name, toolcontext, save_client)
49 save_model.save(org_model)
50
51 toolcontext.info("Open connection to neo4j on {url} for reading...", 1)
52 var read_client = new Neo4jClient(url)
53 var neo_model = new Model
54 var read_model = new NeoModel(test_name, toolcontext, read_client)
55 read_model.load(neo_model)
56
57 # Compare model
58 var sorter = new MEntityNameSorter
59
60 print "# mprojects:"
61 var org_mprojects = org_model.mprojects.to_a
62 sorter.sort org_mprojects
63 print org_mprojects.join(" ")
64 print "------------------------------------"
65 var neo_mprojects = neo_model.mprojects.to_a
66 sorter.sort neo_mprojects
67 print neo_mprojects.join(" ")
68
69 print "\n# mmodules:"
70 var org_mmodules = org_model.mmodules.to_a
71 sorter.sort org_mmodules
72 print org_mmodules.join(" ")
73 print "------------------------------------"
74 var neo_mmodules = neo_model.mmodules.to_a
75 sorter.sort neo_mmodules
76 print neo_mmodules.join(" ")
77
78 print "\n# mclasses:"
79 var org_mclasses = org_model.mclasses.to_a
80 sorter.sort org_mclasses
81 print org_mclasses.join(" ")
82 print "------------------------------------"
83 var neo_mclasses = neo_model.mclasses.to_a
84 sorter.sort neo_mclasses
85 print neo_mclasses.join(" ")
86
87 print "\n# mproperties:"
88 var org_mproperties = org_model.mproperties.to_a
89 sorter.sort org_mproperties
90 print org_mproperties.join(" ")
91 print "------------------------------------"
92 var neo_mproperties = neo_model.mproperties.to_a
93 sorter.sort neo_mproperties
94 print neo_mproperties.join(" ")
95
96 print "\n# msignatures:"
97 for org_mprop in org_mproperties do
98 if not org_mprop isa MMethod then continue
99 print "{org_mprop.name}{org_mprop.intro.msignature or else ""}"
100 end
101 print "------------------------------------"
102 for neo_mprop in neo_mproperties do
103 if not neo_mprop isa MMethod then continue
104 print "{neo_mprop.name}{neo_mprop.intro.msignature or else ""}"
105 end