neo_doxygen: Add some unit tests.
authorJean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>
Mon, 24 Nov 2014 14:37:54 +0000 (09:37 -0500)
committerJean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>
Tue, 25 Nov 2014 17:01:06 +0000 (12:01 -0500)
Signed-off-by: Jean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>

contrib/neo_doxygen/src/tests/README.md [new file with mode: 0644]
contrib/neo_doxygen/src/tests/neo_doxygen_file_compound.nit [new file with mode: 0644]
contrib/neo_doxygen/src/tests/neo_doxygen_graph_empty_project.nit [new file with mode: 0644]
contrib/neo_doxygen/src/tests/neo_doxygen_member_resolve_introducer.nit [new file with mode: 0644]
contrib/neo_doxygen/src/tests/tests.nit [new file with mode: 0644]
tests/sav/neo_doxygen_file_compound.res [new file with mode: 0644]
tests/sav/neo_doxygen_graph_empty_project.res [new file with mode: 0644]
tests/sav/neo_doxygen_member_resolve_introducer.res [new file with mode: 0644]

diff --git a/contrib/neo_doxygen/src/tests/README.md b/contrib/neo_doxygen/src/tests/README.md
new file mode 100644 (file)
index 0000000..fbb4393
--- /dev/null
@@ -0,0 +1,7 @@
+Test scripts for `neo_doxygen`.
+
+The name of each test script is prefixed by `neo_doxygen_` to avoid name
+conflicts in `/tests/sav` and `/tests/out`. The expected output of each script
+is saved as a `*.res` file in `/tests/sav`.
+
+Note: All paths indicated here are relative to the root of the repository.
diff --git a/contrib/neo_doxygen/src/tests/neo_doxygen_file_compound.nit b/contrib/neo_doxygen/src/tests/neo_doxygen_file_compound.nit
new file mode 100644 (file)
index 0000000..c654bd4
--- /dev/null
@@ -0,0 +1,47 @@
+# 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.
+
+import tests
+import model::module_compound
+
+var graph = new ProjectGraph("foo")
+var file = new FileCompound(graph)
+var file_2 = new FileCompound(graph)
+var bar_class = new ClassCompound(graph)
+var c_ns = new Namespace(graph)
+var buffer = new RopeBuffer
+
+file.full_name = "Bar.java"
+file.model_id = "_Bar_8java"
+file.declare_class("classa_b_bar", "a::b::Bar")
+file.declare_namespace("", "a::b")
+file.put_in_graph
+
+file_2.full_name = "Bar.java"
+file_2.model_id = "_Bar_8java_2"
+file_2.declare_namespace("namespacec", "c")
+file_2.declare_namespace("", "d")
+file_2.put_in_graph
+
+bar_class.model_id = "classa_b_bar"
+bar_class.full_name = "a::b::Bar"
+bar_class.put_in_graph
+
+c_ns.model_id = "namespacec"
+c_ns.full_name = "c"
+c_ns.put_in_graph
+
+graph.put_edges
+graph.debug buffer
+print buffer
diff --git a/contrib/neo_doxygen/src/tests/neo_doxygen_graph_empty_project.nit b/contrib/neo_doxygen/src/tests/neo_doxygen_graph_empty_project.nit
new file mode 100644 (file)
index 0000000..f011ae8
--- /dev/null
@@ -0,0 +1,22 @@
+# 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.
+
+import tests
+
+var graph = new ProjectGraph("foo")
+var buffer = new RopeBuffer
+
+graph.put_edges
+graph.debug buffer
+print buffer
diff --git a/contrib/neo_doxygen/src/tests/neo_doxygen_member_resolve_introducer.nit b/contrib/neo_doxygen/src/tests/neo_doxygen_member_resolve_introducer.nit
new file mode 100644 (file)
index 0000000..4909e9d
--- /dev/null
@@ -0,0 +1,34 @@
+# 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.
+
+import model::member
+
+# Copied from the documentation of `Member::resolve_introducer`.
+
+var g = new ProjectGraph("foo")
+var m1 = new Attribute(g)
+var m2 = new Attribute(g)
+var m3 = new Attribute(g)
+
+m1.model_id = "1"
+m1.put_in_graph
+m2.reimplement("1")
+m2.put_in_graph
+assert m1.resolve_introducer == m1.introducer
+assert m2.resolve_introducer == m1.introducer
+
+m3.model_id = "3"
+m3.reimplement("3")
+m3.put_in_graph
+assert m3.resolve_introducer == null
diff --git a/contrib/neo_doxygen/src/tests/tests.nit b/contrib/neo_doxygen/src/tests/tests.nit
new file mode 100644 (file)
index 0000000..797886b
--- /dev/null
@@ -0,0 +1,83 @@
+# 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.
+
+# Base module for tests related to `neo_doxygen`.
+module tests::tests
+
+import model::graph
+
+# Adds debugging output to graphs.
+redef class NeoGraph
+
+       # Append the debugging output of all relationships to the specified buffer.
+       fun debug(buffer: Buffer) do
+               buffer.append "# Graph\n"
+               for edge in all_edges do
+                       edge.debug buffer
+               end
+       end
+end
+
+# Adds debugging output to relationships.
+redef class NeoEdge
+
+       # Append the debugging output of this relationship to the specified buffer.
+       #
+       # Append the relationship type, the properties, and the debugging output of
+       # both extremities.
+       fun debug(buffer: Buffer) do
+               var rel_type = self.rel_type or else "?"
+               buffer.append "Edge\n"
+               buffer.append "=type={rel_type.length}:{rel_type}\n"
+               buffer.append "=properties=JsonObject({properties.length}):\n"
+               buffer.append properties.to_json
+               buffer.append "\n----\n=from="
+               from.debug buffer
+               buffer.append "----\n=to="
+               to.debug buffer
+               buffer.append "\n"
+       end
+end
+
+# Adds debugging output to nodes.
+redef class NeoNode
+
+       # Append the debugging output of this node to the specified buffer.
+       #
+       # Append the labels and the properties.
+       fun debug(buffer: Buffer) do
+               buffer.append "Node\n"
+               buffer.append "=labels=Array({labels.length}):\n"
+               for lab in labels do buffer.append "{lab.length}:{lab}\n"
+               buffer.append "=properties=JsonObject({properties.length}):\n"
+               buffer.append properties.to_json
+               buffer.append "\n"
+       end
+end
+
+# Adds debugging output to entities.
+redef class Entity
+
+       # Append the debugging output of this entity to the specified buffer.
+       #
+       # Append the `model_id`, the labels and the properties.
+       redef fun debug(buffer: Buffer) do
+               buffer.append "Entity#{model_id.length}:{model_id}\n"
+               buffer.append "=labels=Array({labels.length}):\n"
+               for lab in labels do buffer.append "{lab.length}:{lab}\n"
+               buffer.append "=properties=JsonObject({properties.length}):\n"
+               buffer.append properties.to_json
+               buffer.append "\n"
+       end
+end
diff --git a/tests/sav/neo_doxygen_file_compound.res b/tests/sav/neo_doxygen_file_compound.res
new file mode 100644 (file)
index 0000000..e606150
--- /dev/null
@@ -0,0 +1,299 @@
+# Graph
+Edge
+=type=4:ROOT
+=properties=JsonObject(0):
+{}
+----
+=from=Node
+=labels=Array(3):
+3:foo
+7:MEntity
+8:MProject
+=properties=JsonObject(1):
+{"name":"foo"}
+----
+=to=Entity#0:
+=labels=Array(3):
+3:foo
+7:MEntity
+6:MGroup
+=properties=JsonObject(2):
+{"full_name":"","name":"foo"}
+
+Edge
+=type=7:PROJECT
+=properties=JsonObject(0):
+{}
+----
+=from=Entity#0:
+=labels=Array(3):
+3:foo
+7:MEntity
+6:MGroup
+=properties=JsonObject(2):
+{"full_name":"","name":"foo"}
+----
+=to=Node
+=labels=Array(3):
+3:foo
+7:MEntity
+8:MProject
+=properties=JsonObject(1):
+{"name":"foo"}
+
+Edge
+=type=8:DECLARES
+=properties=JsonObject(0):
+{}
+----
+=from=Entity#0:
+=labels=Array(3):
+3:foo
+7:MEntity
+6:MGroup
+=properties=JsonObject(2):
+{"full_name":"","name":"foo"}
+----
+=to=Entity#0:
+=labels=Array(3):
+3:foo
+7:MEntity
+7:MModule
+=properties=JsonObject(3):
+{"location":"\/dev\/null:1,1--1,1","full_name":"a::b::Bar","name":"Bar"}
+
+Edge
+=type=10:INTRODUCES
+=properties=JsonObject(0):
+{}
+----
+=from=Entity#0:
+=labels=Array(3):
+3:foo
+7:MEntity
+7:MModule
+=properties=JsonObject(3):
+{"location":"\/dev\/null:1,1--1,1","full_name":"a::b::Bar","name":"Bar"}
+----
+=to=Entity#12:classa_b_bar
+=labels=Array(3):
+3:foo
+7:MEntity
+6:MClass
+=properties=JsonObject(4):
+{"kind":"class","visibility":"public","full_name":"a::b::Bar","name":"Bar"}
+
+Edge
+=type=7:DEFINES
+=properties=JsonObject(0):
+{}
+----
+=from=Entity#0:
+=labels=Array(3):
+3:foo
+7:MEntity
+7:MModule
+=properties=JsonObject(3):
+{"location":"\/dev\/null:1,1--1,1","full_name":"a::b::Bar","name":"Bar"}
+----
+=to=Entity#0:
+=labels=Array(3):
+3:foo
+7:MEntity
+9:MClassDef
+=properties=JsonObject(4):
+{"location":"\/dev\/null:1,1--1,1","is_intro":true,"name":"Bar","full_name":"a::b::Bar"}
+
+Edge
+=type=8:DECLARES
+=properties=JsonObject(0):
+{}
+----
+=from=Entity#10:namespacec
+=labels=Array(3):
+3:foo
+7:MEntity
+6:MGroup
+=properties=JsonObject(2):
+{"full_name":"c","name":"c"}
+----
+=to=Entity#0:
+=labels=Array(3):
+3:foo
+7:MEntity
+7:MModule
+=properties=JsonObject(3):
+{"location":"\/dev\/null:1,1--1,1","full_name":"c::Bar","name":"Bar"}
+
+Edge
+=type=8:DECLARES
+=properties=JsonObject(0):
+{}
+----
+=from=Entity#0:
+=labels=Array(3):
+3:foo
+7:MEntity
+6:MGroup
+=properties=JsonObject(2):
+{"full_name":"","name":"foo"}
+----
+=to=Entity#0:
+=labels=Array(3):
+3:foo
+7:MEntity
+7:MModule
+=properties=JsonObject(3):
+{"location":"\/dev\/null:1,1--1,1","full_name":"d::Bar","name":"Bar"}
+
+Edge
+=type=9:CLASSTYPE
+=properties=JsonObject(0):
+{}
+----
+=from=Entity#12:classa_b_bar
+=labels=Array(3):
+3:foo
+7:MEntity
+6:MClass
+=properties=JsonObject(4):
+{"kind":"class","visibility":"public","full_name":"a::b::Bar","name":"Bar"}
+----
+=to=Entity#0:
+=labels=Array(4):
+3:foo
+7:MEntity
+5:MType
+10:MClassType
+=properties=JsonObject(2):
+{"name":"Bar","full_name":"a::b::Bar"}
+
+Edge
+=type=5:CLASS
+=properties=JsonObject(0):
+{}
+----
+=from=Entity#0:
+=labels=Array(4):
+3:foo
+7:MEntity
+5:MType
+10:MClassType
+=properties=JsonObject(2):
+{"name":"Bar","full_name":"a::b::Bar"}
+----
+=to=Entity#12:classa_b_bar
+=labels=Array(3):
+3:foo
+7:MEntity
+6:MClass
+=properties=JsonObject(4):
+{"kind":"class","visibility":"public","full_name":"a::b::Bar","name":"Bar"}
+
+Edge
+=type=9:BOUNDTYPE
+=properties=JsonObject(0):
+{}
+----
+=from=Entity#0:
+=labels=Array(3):
+3:foo
+7:MEntity
+9:MClassDef
+=properties=JsonObject(4):
+{"location":"\/dev\/null:1,1--1,1","is_intro":true,"name":"Bar","full_name":"a::b::Bar"}
+----
+=to=Entity#0:
+=labels=Array(4):
+3:foo
+7:MEntity
+5:MType
+10:MClassType
+=properties=JsonObject(2):
+{"name":"Bar","full_name":"a::b::Bar"}
+
+Edge
+=type=6:MCLASS
+=properties=JsonObject(0):
+{}
+----
+=from=Entity#0:
+=labels=Array(3):
+3:foo
+7:MEntity
+9:MClassDef
+=properties=JsonObject(4):
+{"location":"\/dev\/null:1,1--1,1","is_intro":true,"name":"Bar","full_name":"a::b::Bar"}
+----
+=to=Entity#12:classa_b_bar
+=labels=Array(3):
+3:foo
+7:MEntity
+6:MClass
+=properties=JsonObject(4):
+{"kind":"class","visibility":"public","full_name":"a::b::Bar","name":"Bar"}
+
+Edge
+=type=7:PROJECT
+=properties=JsonObject(0):
+{}
+----
+=from=Entity#10:namespacec
+=labels=Array(3):
+3:foo
+7:MEntity
+6:MGroup
+=properties=JsonObject(2):
+{"full_name":"c","name":"c"}
+----
+=to=Node
+=labels=Array(3):
+3:foo
+7:MEntity
+8:MProject
+=properties=JsonObject(1):
+{"name":"foo"}
+
+Edge
+=type=6:PARENT
+=properties=JsonObject(0):
+{}
+----
+=from=Entity#10:namespacec
+=labels=Array(3):
+3:foo
+7:MEntity
+6:MGroup
+=properties=JsonObject(2):
+{"full_name":"c","name":"c"}
+----
+=to=Entity#0:
+=labels=Array(3):
+3:foo
+7:MEntity
+6:MGroup
+=properties=JsonObject(2):
+{"full_name":"","name":"foo"}
+
+Edge
+=type=5:NESTS
+=properties=JsonObject(0):
+{}
+----
+=from=Entity#0:
+=labels=Array(3):
+3:foo
+7:MEntity
+6:MGroup
+=properties=JsonObject(2):
+{"full_name":"","name":"foo"}
+----
+=to=Entity#10:namespacec
+=labels=Array(3):
+3:foo
+7:MEntity
+6:MGroup
+=properties=JsonObject(2):
+{"full_name":"c","name":"c"}
+
+
diff --git a/tests/sav/neo_doxygen_graph_empty_project.res b/tests/sav/neo_doxygen_graph_empty_project.res
new file mode 100644 (file)
index 0000000..d57edd6
--- /dev/null
@@ -0,0 +1,44 @@
+# Graph
+Edge
+=type=4:ROOT
+=properties=JsonObject(0):
+{}
+----
+=from=Node
+=labels=Array(3):
+3:foo
+7:MEntity
+8:MProject
+=properties=JsonObject(1):
+{"name":"foo"}
+----
+=to=Entity#0:
+=labels=Array(3):
+3:foo
+7:MEntity
+6:MGroup
+=properties=JsonObject(2):
+{"full_name":"","name":"foo"}
+
+Edge
+=type=7:PROJECT
+=properties=JsonObject(0):
+{}
+----
+=from=Entity#0:
+=labels=Array(3):
+3:foo
+7:MEntity
+6:MGroup
+=properties=JsonObject(2):
+{"full_name":"","name":"foo"}
+----
+=to=Node
+=labels=Array(3):
+3:foo
+7:MEntity
+8:MProject
+=properties=JsonObject(1):
+{"name":"foo"}
+
+
diff --git a/tests/sav/neo_doxygen_member_resolve_introducer.res b/tests/sav/neo_doxygen_member_resolve_introducer.res
new file mode 100644 (file)
index 0000000..e69de29