tests: add test_deriving
authorJean Privat <jean@pryen.org>
Sun, 15 Mar 2015 05:55:21 +0000 (12:55 +0700)
committerJean Privat <jean@pryen.org>
Wed, 18 Mar 2015 04:25:35 +0000 (11:25 +0700)
Signed-off-by: Jean Privat <jean@pryen.org>

tests/sav/nitg-g/fixme/test_deriving_alt1.res [new file with mode: 0644]
tests/sav/test_deriving.res [new file with mode: 0644]
tests/sav/test_deriving_alt1.res [new file with mode: 0644]
tests/sav/test_deriving_alt2.res [new file with mode: 0644]
tests/sav/test_deriving_alt3.res [new file with mode: 0644]
tests/sav/test_deriving_alt4.res [new file with mode: 0644]
tests/test_deriving.nit [new file with mode: 0644]

diff --git a/tests/sav/nitg-g/fixme/test_deriving_alt1.res b/tests/sav/nitg-g/fixme/test_deriving_alt1.res
new file mode 100644 (file)
index 0000000..7457500
--- /dev/null
@@ -0,0 +1,15 @@
+<A i: <Int> s: <FlatString>>
+i=5 s=Hello
+<A>
+
+true
+true
+true
+
+<B i: <Int> s: <FlatString> a: <A i: <Int> s: <FlatString>>>
+i=100 s=World a=<A>
+<B>
+
+true
+true
+true
diff --git a/tests/sav/test_deriving.res b/tests/sav/test_deriving.res
new file mode 100644 (file)
index 0000000..6020b5f
--- /dev/null
@@ -0,0 +1,15 @@
+<A i: <Int> s: <FlatString>>
+i=5 s=Hello
+i:5; s:Hello
+
+true
+true
+true
+
+<B i: <Int> s: <FlatString> a: <A i: <Int> s: <FlatString>>>
+i=100 s=World a=i:5; s:Hello
+i:100; s:World; a:i:5; s:Hello
+
+true
+true
+true
diff --git a/tests/sav/test_deriving_alt1.res b/tests/sav/test_deriving_alt1.res
new file mode 100644 (file)
index 0000000..88d1f35
--- /dev/null
@@ -0,0 +1,15 @@
+<A i: <Int> s: <FlatString>>
+i=5 s=Hello
+<A i: <Int> s: <FlatString>>
+
+true
+true
+true
+
+<B i: <Int> s: <FlatString> a: <A i: <Int> s: <FlatString>>>
+i=100 s=World a=<A i: <Int> s: <FlatString>>
+<B i: <Int> s: <FlatString> a: <A i: <Int> s: <FlatString>>>
+
+true
+true
+true
diff --git a/tests/sav/test_deriving_alt2.res b/tests/sav/test_deriving_alt2.res
new file mode 100644 (file)
index 0000000..7af6a70
--- /dev/null
@@ -0,0 +1,15 @@
+<A i: <Int> s: <FlatString>>
+i=5 s=Hello
+i:5; s:Hello
+
+false
+false
+true
+
+<B i: <Int> s: <FlatString> a: <A i: <Int> s: <FlatString>>>
+i=100 s=World a=i:5; s:Hello
+i:100; s:World; a:i:5; s:Hello
+
+false
+false
+true
diff --git a/tests/sav/test_deriving_alt3.res b/tests/sav/test_deriving_alt3.res
new file mode 100644 (file)
index 0000000..9e385ed
--- /dev/null
@@ -0,0 +1,15 @@
+<A i: <Int> s: <FlatString>>
+i=5 s=Hello
+i:5; s:Hello
+
+true
+true
+true
+
+<B i: <Int> s: <FlatString> a: <A i: <Int> s: <FlatString>>>
+i=100 s=World
+i:100; s:World
+
+true
+true
+false
diff --git a/tests/sav/test_deriving_alt4.res b/tests/sav/test_deriving_alt4.res
new file mode 100644 (file)
index 0000000..16cf4a0
--- /dev/null
@@ -0,0 +1,15 @@
+<A i: <Int> s: <FlatString>>
+i=5 s=Hello
+i:5; s:Hello
+
+true
+true
+true
+
+<B a: <A i: <Int> s: <FlatString>>>
+string=World a=i:5; s:Hello
+string:World; a:i:5; s:Hello
+
+true
+true
+true
diff --git a/tests/test_deriving.nit b/tests/test_deriving.nit
new file mode 100644 (file)
index 0000000..5f02241
--- /dev/null
@@ -0,0 +1,82 @@
+# 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 deriving
+
+redef class Object
+       # Redef to avoid unstable `object_id`
+       redef fun inspect_head do return "{class_name}"
+end
+
+class A
+       auto_inspect
+       auto_derive
+       super DeriveToS#alt1#
+       super DeriveEqual#alt2#
+
+       var i: Int
+       var s: String
+end
+
+class A2
+       super DeriveToS
+       super DeriveEqual
+
+       redef fun derive_to_map
+       do
+               var res = super
+               res["string"] = s # drop i
+               return res
+       end
+
+       var i: Int
+       var s: String
+end
+
+class B
+       super A#alt4#super A2
+
+       auto_inspect
+       auto_derive#alt3#
+
+       var a: A
+end
+
+var a = new A(5, "Hello")
+print a.inspect
+print a.derive_to_map.join(" ", "=")
+print a
+
+print ""
+
+var a2 = new A(5, "Hel" + "lo")
+var a3 = new A(6, "Hel" + "lo")
+print a == a2
+print a.hash == a2.hash
+print a != a3
+
+print ""
+
+var b = new B(100, "World", a)
+print b.inspect
+print b.derive_to_map.join(" ", "=")
+print b
+
+print ""
+
+var b2 = new B(100, "World", a2)
+var b3 = new B(100, "World", a3)
+print b == b2
+print b.hash == b2.hash
+print b != b3