tests: add base_new_factory
authorJean Privat <jean@pryen.org>
Sat, 23 Apr 2016 00:08:05 +0000 (20:08 -0400)
committerJean Privat <jean@pryen.org>
Sat, 23 Apr 2016 00:08:05 +0000 (20:08 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

tests/base_new_factory.nit [new file with mode: 0644]
tests/sav/base_new_factory.res [new file with mode: 0644]

diff --git a/tests/base_new_factory.nit b/tests/base_new_factory.nit
new file mode 100644 (file)
index 0000000..d8b704c
--- /dev/null
@@ -0,0 +1,71 @@
+# 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 core::kernel
+
+interface A
+       new do return new B(5)
+end
+
+class B
+       super A
+       var i: Int
+       redef fun output do
+               'B'.output
+               i.output
+       end
+end
+
+interface G[E: Object]
+       new(a: E) do return new H[E](a)
+       fun dup:G[E] is abstract
+end
+
+class H[F: Object]
+       super G[F]
+       var o: F
+
+       redef fun output do
+               'H'.output
+               o.output
+       end
+
+       redef fun dup do return new G[F](self.o)
+end
+
+var b = new B(1)
+b.output
+var a = new A
+a.output
+
+var ha = new H[A](a)
+ha.output
+var hb = new H[B](b)
+hb.output
+
+var ga = new G[A](a)
+ga.output
+var gb = new G[B](b)
+gb.output
+
+ga.dup.output
+gb.dup.output
+
+var gga = new G[G[A]](ga)
+gga.output
+var ggb = new G[G[B]](gb)
+ggb.output
+
+gga.dup.output
+ggb.dup.output
diff --git a/tests/sav/base_new_factory.res b/tests/sav/base_new_factory.res
new file mode 100644 (file)
index 0000000..238446a
--- /dev/null
@@ -0,0 +1,12 @@
+B1
+B5
+HB5
+HB1
+HB5
+HB1
+HB5
+HB1
+HHB5
+HHB1
+HHB5
+HHB1