tests: add base_init_autoinit.nit
authorJean Privat <privat@pryen.org>
Mon, 29 Sep 2014 20:14:35 +0000 (16:14 -0400)
committerJean Privat <jean@pryen.org>
Mon, 29 Sep 2014 20:18:03 +0000 (16:18 -0400)
Signed-off-by: Jean Privat <privat@pryen.org>

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

diff --git a/tests/base_init_autoinit.nit b/tests/base_init_autoinit.nit
new file mode 100644 (file)
index 0000000..e5bd4ab
--- /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.
+
+import kernel
+
+class A
+       fun toto(i: Int) is autoinit do
+               'A'.output
+               'o'.output
+               i.output
+       end
+
+       fun tata is autoinit do
+               'A'.output
+               'a'.output
+               '\n'.output
+       end
+
+       init do
+               'A'.output
+               '\n'.output
+       end
+end
+
+class B
+       super A
+       fun tutu=(j: Int) is autoinit do
+               # no super here!
+               'B'.output
+               'u'.output
+               j.output
+       end
+
+       redef fun toto(i)
+       do
+               super
+               'B'.output
+               'o'.output
+               i.output
+       end
+
+       redef fun tata do #alt1#redef fun tata is autoinit do
+               'B'.output
+               'a'.output
+               '\n'.output
+       end
+
+       init do
+               'B'.output
+               '\n'.output
+       end
+end
+
+class C
+       super A
+       fun tete(k,l: Int) is autoinit do
+               'C'.output
+               'e'.output
+               k.output
+               l.output
+       end
+end
+
+var a = new A(1)
+
+'\n'.output
+
+var b = new B(10,20)
+
+'\n'.output
+
+var c = new C(100,200,300)
diff --git a/tests/sav/base_init_autoinit.res b/tests/sav/base_init_autoinit.res
new file mode 100644 (file)
index 0000000..64605d9
--- /dev/null
@@ -0,0 +1,16 @@
+Ao1
+Aa
+A
+
+Ao10
+Bo10
+Ba
+Bu20
+A
+B
+
+Ao100
+Aa
+Ce200
+300
+A
diff --git a/tests/sav/base_init_autoinit_alt1.res b/tests/sav/base_init_autoinit_alt1.res
new file mode 100644 (file)
index 0000000..af10e70
--- /dev/null
@@ -0,0 +1 @@
+alt/base_init_autoinit_alt1.nit:53,20--27: Error: `autoinit` cannot be set on redefinitions