From 3a3aa8cb4e4cc22076e1a4701efed0fff4408bfb Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Mon, 29 Sep 2014 16:14:35 -0400 Subject: [PATCH] tests: add base_init_autoinit.nit Signed-off-by: Jean Privat --- tests/base_init_autoinit.nit | 83 +++++++++++++++++++++++++++++++++ tests/sav/base_init_autoinit.res | 16 +++++++ tests/sav/base_init_autoinit_alt1.res | 1 + 3 files changed, 100 insertions(+) create mode 100644 tests/base_init_autoinit.nit create mode 100644 tests/sav/base_init_autoinit.res create mode 100644 tests/sav/base_init_autoinit_alt1.res diff --git a/tests/base_init_autoinit.nit b/tests/base_init_autoinit.nit new file mode 100644 index 0000000..e5bd4ab --- /dev/null +++ b/tests/base_init_autoinit.nit @@ -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 index 0000000..64605d9 --- /dev/null +++ b/tests/sav/base_init_autoinit.res @@ -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 index 0000000..af10e70 --- /dev/null +++ b/tests/sav/base_init_autoinit_alt1.res @@ -0,0 +1 @@ +alt/base_init_autoinit_alt1.nit:53,20--27: Error: `autoinit` cannot be set on redefinitions -- 1.7.9.5