tests: add base_attr_named_setters
authorJean Privat <jean@pryen.org>
Mon, 21 Jul 2014 16:09:54 +0000 (12:09 -0400)
committerJean Privat <jean@pryen.org>
Mon, 21 Jul 2014 16:11:18 +0000 (12:11 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

tests/base_attr_named_setters.nit [new file with mode: 0644]
tests/sav/base_attr_named_setters.res [new file with mode: 0644]
tests/sav/base_attr_named_setters_alt1.res [new file with mode: 0644]
tests/sav/base_attr_named_setters_alt2.res [new file with mode: 0644]
tests/sav/base_attr_named_setters_alt3.res [new file with mode: 0644]
tests/sav/base_attr_named_setters_alt4.res [new file with mode: 0644]

diff --git a/tests/base_attr_named_setters.nit b/tests/base_attr_named_setters.nit
new file mode 100644 (file)
index 0000000..136c740
--- /dev/null
@@ -0,0 +1,67 @@
+# 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 foo: Int do return 1
+       fun set_bar(i: Int) do i.output
+       fun baz: Int do return 4
+       fun set_baz(i: Int) do i.output
+       fun zz do end
+end
+
+class B
+       super A
+       redef var foo: Int = 20 is writable(set_foo)
+       var bar: Int = 30 is redef writable(set_bar)
+       redef var baz: Int = 40 is writable(set_baz)
+       #alt2#var z: Int is writable(set_baz)
+       #alt3#var z: Int is writable(zz)
+       #alt4#var z: Int is redef writable(zz)
+end
+
+class C
+       super B
+       fun foo=(i: Int) do set_foo(i)
+       fun bar=(i: Int) do set_bar(i)
+       fun baz=(i: Int) do set_baz(i)
+end
+
+var a = new A
+a.foo.output
+a.set_bar 2
+a.set_baz 3
+a.baz.output
+
+'\n'.output
+
+var b = new B
+b.set_foo 10
+#alt1#b.foo = 10
+b.foo.output
+b.set_bar 20
+b.bar.output
+b.set_baz 30
+b.baz.output
+
+'\n'.output
+
+var c = new C
+c.foo = 100
+c.foo.output
+c.bar = 200
+c.bar.output
+c.baz = 300
+c.baz.output
diff --git a/tests/sav/base_attr_named_setters.res b/tests/sav/base_attr_named_setters.res
new file mode 100644 (file)
index 0000000..9e263e5
--- /dev/null
@@ -0,0 +1,12 @@
+1
+2
+3
+4
+
+10
+20
+30
+
+100
+200
+300
diff --git a/tests/sav/base_attr_named_setters_alt1.res b/tests/sav/base_attr_named_setters_alt1.res
new file mode 100644 (file)
index 0000000..cf8d660
--- /dev/null
@@ -0,0 +1 @@
+alt/base_attr_named_setters_alt1.nit:52,1--10: Error: Method 'foo=' doesn't exists in B.
diff --git a/tests/sav/base_attr_named_setters_alt2.res b/tests/sav/base_attr_named_setters_alt2.res
new file mode 100644 (file)
index 0000000..ada80a6
--- /dev/null
@@ -0,0 +1 @@
+alt/base_attr_named_setters_alt2.nit:30,6: Error: A property set_baz is already defined in class B at line 29.
diff --git a/tests/sav/base_attr_named_setters_alt3.res b/tests/sav/base_attr_named_setters_alt3.res
new file mode 100644 (file)
index 0000000..ed64fb8
--- /dev/null
@@ -0,0 +1 @@
+alt/base_attr_named_setters_alt3.nit:31,6: Redef error: B::zz is an inherited property. To redefine it, add the redef keyword.
diff --git a/tests/sav/base_attr_named_setters_alt4.res b/tests/sav/base_attr_named_setters_alt4.res
new file mode 100644 (file)
index 0000000..9409278
--- /dev/null
@@ -0,0 +1 @@
+alt/base_attr_named_setters_alt4.nit:32,9--11: Redef Error: 1 parameters found, 0 expected. Signature is base_attr_named_setters_alt4#B#zz