tests: add base_init_autoinit2.nit
authorJean Privat <jean@pryen.org>
Wed, 29 Oct 2014 17:25:09 +0000 (13:25 -0400)
committerJean Privat <jean@pryen.org>
Fri, 31 Oct 2014 11:14:12 +0000 (07:14 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

tests/base_init_autoinit2.nit [new file with mode: 0644]
tests/sav/base_init_autoinit2.res [new file with mode: 0644]
tests/sav/base_init_autoinit2_alt1.res [new file with mode: 0644]
tests/sav/base_init_autoinit2_alt2.res [new file with mode: 0644]

diff --git a/tests/base_init_autoinit2.nit b/tests/base_init_autoinit2.nit
new file mode 100644 (file)
index 0000000..afce0f9
--- /dev/null
@@ -0,0 +1,43 @@
+# 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
+       var a: Object = get(5) is lazy
+       var b: Object is noinit
+       #alt1#var b2: Object = get(-4) is noinit
+       var c: Object is noinit
+       var d: Object = get(2) is autoinit
+       #alt2#var d2: Object = get(-2) is autoinit, lazy
+       var e: Object = get(1)
+       fun setc(v: Object) is autoinit do self.c = get(v)
+       init do
+               b = get(4)
+       end
+       fun get(v: Object): Object
+       do
+               'g'.output
+               v.output
+               return v
+       end
+end
+
+var a = new A(3)
+'\n'.output
+a.a.output
+a.b.output
+a.c.output
+a.d.output
+a.e.output
diff --git a/tests/sav/base_init_autoinit2.res b/tests/sav/base_init_autoinit2.res
new file mode 100644 (file)
index 0000000..243898c
--- /dev/null
@@ -0,0 +1,11 @@
+g1
+g2
+g3
+g4
+
+g5
+5
+4
+3
+2
+1
diff --git a/tests/sav/base_init_autoinit2_alt1.res b/tests/sav/base_init_autoinit2_alt1.res
new file mode 100644 (file)
index 0000000..9c9fbe0
--- /dev/null
@@ -0,0 +1 @@
+alt/base_init_autoinit2_alt1.nit:20,30--35: Error: `noinit` attributes cannot have an initial value
diff --git a/tests/sav/base_init_autoinit2_alt2.res b/tests/sav/base_init_autoinit2_alt2.res
new file mode 100644 (file)
index 0000000..3c28719
--- /dev/null
@@ -0,0 +1 @@
+alt/base_init_autoinit2_alt2.nit:23,40--43: Error: lazy incompatible with autoinit