tests: add base_attr_abstract.nit
authorJean Privat <jean@pryen.org>
Thu, 26 Feb 2015 13:04:53 +0000 (20:04 +0700)
committerJean Privat <jean@pryen.org>
Thu, 26 Feb 2015 13:04:53 +0000 (20:04 +0700)
Signed-off-by: Jean Privat <jean@pryen.org>

tests/base_attr_abstract.nit [new file with mode: 0644]
tests/sav/base_attr_abstract.res [new file with mode: 0644]
tests/sav/base_attr_abstract_alt1.res [new file with mode: 0644]
tests/sav/base_attr_abstract_alt2.res [new file with mode: 0644]
tests/sav/base_attr_abstract_alt3.res [new file with mode: 0644]
tests/sav/base_attr_abstract_alt4.res [new file with mode: 0644]

diff --git a/tests/base_attr_abstract.nit b/tests/base_attr_abstract.nit
new file mode 100644 (file)
index 0000000..34c1e4c
--- /dev/null
@@ -0,0 +1,50 @@
+# 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
+
+interface Foo
+       var a: Object is abstract
+       #alt1#var b = 1 is abstract
+       #alt2#var b is abstract, noautoinit
+end
+
+class Bar
+       super Foo
+       redef var a
+end
+
+class Baz
+       super Foo
+       redef fun a do return 100
+       redef fun a=(x) do (101).output
+end
+
+class FooBar
+       super Foo
+end
+
+var f: Foo = new Bar(1)
+f.a.output
+f.a = 2
+f.a.output
+
+f = new Baz
+f.a.output
+f.a = 3
+f.a.output
+
+f = new FooBar
+#alt3#f.a.output
+#alt4#f.a = 4
diff --git a/tests/sav/base_attr_abstract.res b/tests/sav/base_attr_abstract.res
new file mode 100644 (file)
index 0000000..36f0f1a
--- /dev/null
@@ -0,0 +1,5 @@
+1
+2
+100
+101
+100
diff --git a/tests/sav/base_attr_abstract_alt1.res b/tests/sav/base_attr_abstract_alt1.res
new file mode 100644 (file)
index 0000000..6971473
--- /dev/null
@@ -0,0 +1 @@
+alt/base_attr_abstract_alt1.nit:19,15--22: Error: `abstract` attributes cannot have an initial value
diff --git a/tests/sav/base_attr_abstract_alt2.res b/tests/sav/base_attr_abstract_alt2.res
new file mode 100644 (file)
index 0000000..1ed3535
--- /dev/null
@@ -0,0 +1,2 @@
+alt/base_attr_abstract_alt2.nit:20,6: Error: Untyped attribute base_attr_abstract_alt2#Foo#b
+alt/base_attr_abstract_alt2.nit:20,21--30: Error: `noautoinit` attributes cannot be abstract
diff --git a/tests/sav/base_attr_abstract_alt3.res b/tests/sav/base_attr_abstract_alt3.res
new file mode 100644 (file)
index 0000000..4052598
--- /dev/null
@@ -0,0 +1,6 @@
+Runtime error: Abstract method `a` called on `FooBar` (alt/base_attr_abstract_alt3.nit:18)
+1
+2
+100
+101
+100
diff --git a/tests/sav/base_attr_abstract_alt4.res b/tests/sav/base_attr_abstract_alt4.res
new file mode 100644 (file)
index 0000000..09d65f9
--- /dev/null
@@ -0,0 +1,6 @@
+Runtime error: Abstract method `a=` called on `FooBar` (alt/base_attr_abstract_alt4.nit:18)
+1
+2
+100
+101
+100