From 2399e75c518684086c10d3745a952e24f3f5e9ef Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Thu, 16 Apr 2015 18:40:15 +0700 Subject: [PATCH] tests: add base_arg_default*.nit Signed-off-by: Jean Privat --- tests/base_arg_default.nit | 110 ++++++++++++++++++++++++++ tests/base_arg_default2.nit | 104 ++++++++++++++++++++++++ tests/base_arg_default_autoinit.nit | 96 ++++++++++++++++++++++ tests/sav/base_arg_default.res | 83 +++++++++++++++++++ tests/sav/base_arg_default2.res | 47 +++++++++++ tests/sav/base_arg_default2_alt1.res | 9 +++ tests/sav/base_arg_default_alt1.res | 6 ++ tests/sav/base_arg_default_alt2.res | 1 + tests/sav/base_arg_default_autoinit.res | 31 ++++++++ tests/sav/base_arg_default_autoinit_alt1.res | 6 ++ 10 files changed, 493 insertions(+) create mode 100644 tests/base_arg_default.nit create mode 100644 tests/base_arg_default2.nit create mode 100644 tests/base_arg_default_autoinit.nit create mode 100644 tests/sav/base_arg_default.res create mode 100644 tests/sav/base_arg_default2.res create mode 100644 tests/sav/base_arg_default2_alt1.res create mode 100644 tests/sav/base_arg_default_alt1.res create mode 100644 tests/sav/base_arg_default_alt2.res create mode 100644 tests/sav/base_arg_default_autoinit.res create mode 100644 tests/sav/base_arg_default_autoinit_alt1.res diff --git a/tests/base_arg_default.nit b/tests/base_arg_default.nit new file mode 100644 index 0000000..2d1af37 --- /dev/null +++ b/tests/base_arg_default.nit @@ -0,0 +1,110 @@ +# 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 standard::kernel + +class A + fun foo(a, b: nullable Int, c, d: Int, e,f: nullable Int) + do + if a == null then '\n'.output else a.output + if b == null then '\n'.output else b.output + c.output + d.output + if e == null then '\n'.output else e.output + if f == null then '\n'.output else f.output + '-'.output + '\n'.output + + end + + fun bar(a,b,c: nullable Int) + do + if a == null then '\n'.output else a.output + if b == null then '\n'.output else b.output + if c == null then '\n'.output else c.output + '-'.output + '\n'.output + end + + fun bar=(a,b,c: nullable Int) + do + if a == null then '\n'.output else a.output + if b == null then '\n'.output else b.output + if c == null then '\n'.output else c.output + '-'.output + '\n'.output + end + + fun [](a,b,c: nullable Int): Int + do + if a == null then '\n'.output else a.output + if b == null then '\n'.output else b.output + if c == null then '\n'.output else c.output + '-'.output + '\n'.output + return 0 + end + + fun []=(a,b,c: nullable Int): Int + do + if a == null then '\n'.output else a.output + if b == null then '\n'.output else b.output + if c == null then '\n'.output else c.output + '-'.output + '\n'.output + return 0 + end + + fun +(a: nullable Int): Int + do + if a == null then '\n'.output else a.output + '-'.output + '\n'.output + return 0 + end +end + +var a = new A +var x + +#alt1#a.foo +#alt1#a.foo(2) +a.foo(1,2) +a.foo(1,2,3) +a.foo(1,2,3,4) +a.foo(1,2,3,4,5) +a.foo(1,2,3,4,5,6) +#alt1#a.foo(1,2,3,4,5,6,7) + +a.bar +a.bar(1) +a.bar(1,2) +a.bar(1,2,3) +#alt1#a.bar(1,2,3,4) + +a.bar= 10 +a.bar(1) = 20 +a.bar(1,2) = 30 +#alt1#a.bar(1,2,3) = 40 + +#alt2# x = a[] +x = a[1] +x = a[1,2] +x = a[1,2,3] +#alt2#x = a[1,2,3,4] + +#alt2#a[] = 10 +a[1] = 20 +a[1,2] = 30 +#alt1#a[1,2,3] = 40 diff --git a/tests/base_arg_default2.nit b/tests/base_arg_default2.nit new file mode 100644 index 0000000..228f5ac --- /dev/null +++ b/tests/base_arg_default2.nit @@ -0,0 +1,104 @@ +# 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. + +class A + fun foo(a: nullable Int, bs: Int..., c: nullable Int) + do + if a == null then '\n'.output else a.output + for b in bs do + ' '.output + b.output + end + if c == null then '\n'.output else c.output + '-'.output + '\n'.output + + end + + fun bar(a: nullable Int, bs: Int...) + do + if a == null then '\n'.output else a.output + for b in bs do + ' '.output + b.output + end + '-'.output + '\n'.output + end + + fun bar=(a:nullable Int, bs: Int..., c: nullable Int) + do + if a == null then '\n'.output else a.output + for b in bs do + ' '.output + b.output + end + if c == null then '\n'.output else c.output + '-'.output + '\n'.output + end + + fun [](a: nullable Int, bs: Int...): Int + do + if a == null then '\n'.output else a.output + for b in bs do + ' '.output + b.output + end + '-'.output + '\n'.output + return 0 + end + + fun []=(a: nullable Int, bs: Int..., c: nullable Int): Int + do + if a == null then '\n'.output else a.output + for b in bs do + ' '.output + b.output + end + if c == null then '\n'.output else c.output + '-'.output + '\n'.output + return 0 + end +end + +var a = new A +var x + +#alt1#a.foo +#alt1#a.foo(2) +#alt1#a.foo(1,2) +a.foo(1,2,3) +a.foo(1,2,3,4) + +#alt1#a.bar +#alt1#a.bar(1) +a.bar(1,2) +a.bar(1,2,3) + +#alt1#a.bar = 10 +#alt1#a.bar(1) = 20 +a.bar(1,2) = 30 +a.bar(1,2,3) = 40 + +#alt1#x = a[1] +x = a[1,2] +x = a[1,2,3] + +#alt1#a[1] = 20 +a[1,2] = 30 +a[1,2,3] = 40 +a[1,2,3,4] = 50 diff --git a/tests/base_arg_default_autoinit.nit b/tests/base_arg_default_autoinit.nit new file mode 100644 index 0000000..6ea74cf --- /dev/null +++ b/tests/base_arg_default_autoinit.nit @@ -0,0 +1,96 @@ +# 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 standard::kernel + +class A + var mandatory: Int + var optional: nullable Int + + fun foo + do + '-'.output + '\n'.output + mandatory.output + if optional == null then + ' '.output + '\n'.output + else + optional.output + end + end +end + +class B + super A + var optional_b: nullable Int + var mandatory_b: Int + redef fun foo + do + super + if optional_b == null then + ' '.output + '\n'.output + else + optional_b.output + end + mandatory_b.output + end +end + +class C + super B + autoinit optional_b, mandatory_b, mandatory +end + +var a + +#alt1#a = new A +#alt1#a.foo + +a = new A(1) +a.foo + +a = new A(1,2) +a.foo + +#alt1#a = new A(1,2,3) +#alt1#a.foo + +#alt1#a = new B(1) +#alt1#a.foo + +a = new B(1,4) +a.foo + +a = new B(1,2,4) +a.foo + +a = new B(1,2,3,4) +a.foo + +#alt1#a = new B(1,2,3,4,5) +#alt1#a.foo + +#alt1#a = new C(1) +#alt1#a.foo + +a = new C(4,1) +a.foo + +a = new C(3,4,1) +a.foo + +#alt1#a = new C(1,2,3,4) +#alt1#a.foo diff --git a/tests/sav/base_arg_default.res b/tests/sav/base_arg_default.res new file mode 100644 index 0000000..61ea614 --- /dev/null +++ b/tests/sav/base_arg_default.res @@ -0,0 +1,83 @@ + + +1 +2 + + +- +1 + +2 +3 + + +- +1 +2 +3 +4 + + +- +1 +2 +3 +4 +5 + +- +1 +2 +3 +4 +5 +6 +- + + + +- +1 + + +- +1 +2 + +- +1 +2 +3 +- + + +10 +- +1 + +20 +- +1 +2 +30 +- +1 + + +- +1 +2 + +- +1 +2 +3 +- +1 + +20 +- +1 +2 +30 +- diff --git a/tests/sav/base_arg_default2.res b/tests/sav/base_arg_default2.res new file mode 100644 index 0000000..388e53a --- /dev/null +++ b/tests/sav/base_arg_default2.res @@ -0,0 +1,47 @@ +1 + 2 +3 +- +1 + 2 + 3 +4 +- +1 + 2 +- +1 + 2 + 3 +- +1 + 2 +30 +- +1 + 2 + 3 +40 +- +1 + 2 +- +1 + 2 + 3 +- +1 + 2 +30 +- +1 + 2 + 3 +40 +- +1 + 2 + 3 + 4 +50 +- diff --git a/tests/sav/base_arg_default2_alt1.res b/tests/sav/base_arg_default2_alt1.res new file mode 100644 index 0000000..2dc6089 --- /dev/null +++ b/tests/sav/base_arg_default2_alt1.res @@ -0,0 +1,9 @@ +alt/base_arg_default2_alt1.nit:81,3--5: Error: expected at least 3 argument(s) for `foo(a: nullable Int, bs: Int..., c: nullable Int)`; got 0. See introduction at `base_arg_default2_alt1::A::foo`. +alt/base_arg_default2_alt1.nit:82,3--5: Error: expected at least 3 argument(s) for `foo(a: nullable Int, bs: Int..., c: nullable Int)`; got 1. See introduction at `base_arg_default2_alt1::A::foo`. +alt/base_arg_default2_alt1.nit:83,3--5: Error: expected at least 3 argument(s) for `foo(a: nullable Int, bs: Int..., c: nullable Int)`; got 2. See introduction at `base_arg_default2_alt1::A::foo`. +alt/base_arg_default2_alt1.nit:87,3--5: Error: expected at least 2 argument(s) for `bar(a: nullable Int, bs: Int...)`; got 0. See introduction at `base_arg_default2_alt1::A::bar`. +alt/base_arg_default2_alt1.nit:88,3--5: Error: expected at least 2 argument(s) for `bar(a: nullable Int, bs: Int...)`; got 1. See introduction at `base_arg_default2_alt1::A::bar`. +alt/base_arg_default2_alt1.nit:92,3--5: Error: expected at least 3 argument(s) for `bar=(a: nullable Int, bs: Int..., c: nullable Int)`; got 1. See introduction at `base_arg_default2_alt1::A::bar=`. +alt/base_arg_default2_alt1.nit:93,3--5: Error: expected at least 3 argument(s) for `bar=(a: nullable Int, bs: Int..., c: nullable Int)`; got 2. See introduction at `base_arg_default2_alt1::A::bar=`. +alt/base_arg_default2_alt1.nit:97,5--8: Error: expected at least 2 argument(s) for `[](a: nullable Int, bs: Int...): Int`; got 1. See introduction at `base_arg_default2_alt1::A::[]`. +alt/base_arg_default2_alt1.nit:101,1--9: Error: expected at least 3 argument(s) for `[]=(a: nullable Int, bs: Int..., c: nullable Int): Int`; got 2. See introduction at `base_arg_default2_alt1::A::[]=`. diff --git a/tests/sav/base_arg_default_alt1.res b/tests/sav/base_arg_default_alt1.res new file mode 100644 index 0000000..fba2f2b --- /dev/null +++ b/tests/sav/base_arg_default_alt1.res @@ -0,0 +1,6 @@ +alt/base_arg_default_alt1.nit:81,3--5: Error: expected at least 2 argument(s) for `foo(a: nullable Int, b: nullable Int, c: Int, d: Int, e: nullable Int, f: nullable Int)`; got 0. See introduction at `base_arg_default_alt1::A::foo`. +alt/base_arg_default_alt1.nit:82,3--5: Error: expected at least 2 argument(s) for `foo(a: nullable Int, b: nullable Int, c: Int, d: Int, e: nullable Int, f: nullable Int)`; got 1. See introduction at `base_arg_default_alt1::A::foo`. +alt/base_arg_default_alt1.nit:88,3--5: Error: expected at most 6 argument(s) for `foo(a: nullable Int, b: nullable Int, c: Int, d: Int, e: nullable Int, f: nullable Int)`; got 7. See introduction at `base_arg_default_alt1::A::foo`. +alt/base_arg_default_alt1.nit:94,3--5: Error: expected at most 3 argument(s) for `bar(a: nullable Int, b: nullable Int, c: nullable Int)`; got 4. See introduction at `base_arg_default_alt1::A::bar`. +alt/base_arg_default_alt1.nit:99,3--5: Error: expected at most 3 argument(s) for `bar=(a: nullable Int, b: nullable Int, c: nullable Int)`; got 4. See introduction at `base_arg_default_alt1::A::bar=`. +alt/base_arg_default_alt1.nit:110,1--13: Error: expected at most 3 argument(s) for `[]=(a: nullable Int, b: nullable Int, c: nullable Int): Int`; got 4. See introduction at `base_arg_default_alt1::A::[]=`. diff --git a/tests/sav/base_arg_default_alt2.res b/tests/sav/base_arg_default_alt2.res new file mode 100644 index 0000000..ca32b19 --- /dev/null +++ b/tests/sav/base_arg_default_alt2.res @@ -0,0 +1 @@ +alt/base_arg_default_alt2.nit:101,7: Syntax Error: unexpected ']'. diff --git a/tests/sav/base_arg_default_autoinit.res b/tests/sav/base_arg_default_autoinit.res new file mode 100644 index 0000000..437e8ee --- /dev/null +++ b/tests/sav/base_arg_default_autoinit.res @@ -0,0 +1,31 @@ +- +1 + +- +1 +2 +- +1 + + +4 +- +1 +2 + +4 +- +1 +2 +3 +4 +- +1 + + +4 +- +1 + +3 +4 diff --git a/tests/sav/base_arg_default_autoinit_alt1.res b/tests/sav/base_arg_default_autoinit_alt1.res new file mode 100644 index 0000000..cdf6690 --- /dev/null +++ b/tests/sav/base_arg_default_autoinit_alt1.res @@ -0,0 +1,6 @@ +alt/base_arg_default_autoinit_alt1.nit:59,5--7: Error: expected at least 1 argument(s) for `init(mandatory: Int, optional: nullable Int)`; got 0. See introduction at `standard::Object::init`. +alt/base_arg_default_autoinit_alt1.nit:68,5--7: Error: expected at most 2 argument(s) for `init(mandatory: Int, optional: nullable Int)`; got 3. See introduction at `standard::Object::init`. +alt/base_arg_default_autoinit_alt1.nit:71,5--7: Error: expected at least 2 argument(s) for `init(mandatory: Int, optional: nullable Int, optional_b: nullable Int, mandatory_b: Int)`; got 1. See introduction at `standard::Object::init`. +alt/base_arg_default_autoinit_alt1.nit:83,5--7: Error: expected at most 4 argument(s) for `init(mandatory: Int, optional: nullable Int, optional_b: nullable Int, mandatory_b: Int)`; got 5. See introduction at `standard::Object::init`. +alt/base_arg_default_autoinit_alt1.nit:86,5--7: Error: expected at least 2 argument(s) for `init(optional_b: nullable Int, mandatory_b: Int, mandatory: Int)`; got 1. See introduction at `standard::Object::init`. +alt/base_arg_default_autoinit_alt1.nit:95,5--7: Error: expected at most 3 argument(s) for `init(optional_b: nullable Int, mandatory_b: Int, mandatory: Int)`; got 4. See introduction at `standard::Object::init`. -- 1.7.9.5