From ea531f9aa29da6e38d231dc036a40ca711c20477 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Wed, 17 Jun 2015 22:12:29 -0400 Subject: [PATCH] tests: new tests base_adaptive_loop_null2.nit base_adaptive_loop_isa.nit Signed-off-by: Jean Privat --- tests/base_adaptive_loop_isa.nit | 52 +++++++++++++++++++++++ tests/base_adaptive_loop_null2.nit | 59 +++++++++++++++++++++++++++ tests/sav/base_adaptive_loop_isa.res | 3 ++ tests/sav/base_adaptive_loop_isa_alt1.res | 4 ++ tests/sav/base_adaptive_loop_null2.res | 26 ++++++++++++ tests/sav/base_adaptive_loop_null2_alt1.res | 18 ++++++++ tests/sav/base_adaptive_loop_null_alt1.res | 1 + 7 files changed, 163 insertions(+) create mode 100644 tests/base_adaptive_loop_isa.nit create mode 100644 tests/base_adaptive_loop_null2.nit create mode 100644 tests/sav/base_adaptive_loop_isa.res create mode 100644 tests/sav/base_adaptive_loop_isa_alt1.res create mode 100644 tests/sav/base_adaptive_loop_null2.res create mode 100644 tests/sav/base_adaptive_loop_null2_alt1.res diff --git a/tests/base_adaptive_loop_isa.nit b/tests/base_adaptive_loop_isa.nit new file mode 100644 index 0000000..26af488 --- /dev/null +++ b/tests/base_adaptive_loop_isa.nit @@ -0,0 +1,52 @@ +# 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 + + +interface A +end + +class B + super A + var next: A +end + +class C + super A +end + +class D + super A +end + +fun foo(a: A): Int +do + var i = 0 + if a isa B then while i < 10 do + i += 1 + + if a isa C then return i + if not a isa B then return -i + a = a.next #alt1# + end + return i +end + +var c = new C +var b = new B(c) +var bd = new B(new D) +foo(c).output +foo(b).output +foo(bd).output diff --git a/tests/base_adaptive_loop_null2.nit b/tests/base_adaptive_loop_null2.nit new file mode 100644 index 0000000..40f5674 --- /dev/null +++ b/tests/base_adaptive_loop_null2.nit @@ -0,0 +1,59 @@ +# 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 + +var x +x = null + +var i = 0 +while i < 2 do + var y + y = x + if y == null then 1.output + y = x + if y != null then 2.output + y = x + if y isa Int then 3.output + y = x + if y isa nullable Int then 4.output + y = x + if y isa nullable Bool then 5.output + y = x or else 6 + y.output + #alt1#x = 1 + + i += 1 +end + +x = 10 +i = 0 +while i < 2 do + var y + y = x + if y == null then 1.output + y = x + if y != null then 2.output + y = x + if y isa Int then 3.output + y = x + if y isa nullable Int then 4.output + y = x + if y isa nullable Bool then 5.output + y = x or else 6 + y.output + #alt1#x = null + + i += 1 +end diff --git a/tests/sav/base_adaptive_loop_isa.res b/tests/sav/base_adaptive_loop_isa.res new file mode 100644 index 0000000..7c0510a --- /dev/null +++ b/tests/sav/base_adaptive_loop_isa.res @@ -0,0 +1,3 @@ +0 +2 +-2 diff --git a/tests/sav/base_adaptive_loop_isa_alt1.res b/tests/sav/base_adaptive_loop_isa_alt1.res new file mode 100644 index 0000000..a9f3a8f --- /dev/null +++ b/tests/sav/base_adaptive_loop_isa_alt1.res @@ -0,0 +1,4 @@ +alt/base_adaptive_loop_isa_alt1.nit:41,10--16: Warning: expression is already a `B`. +0 +10 +10 diff --git a/tests/sav/base_adaptive_loop_null2.res b/tests/sav/base_adaptive_loop_null2.res new file mode 100644 index 0000000..741dade --- /dev/null +++ b/tests/sav/base_adaptive_loop_null2.res @@ -0,0 +1,26 @@ +base_adaptive_loop_null2.nit:24,5: Warning: expression is always `null`. +base_adaptive_loop_null2.nit:26,5: Warning: expression is always `null`. +base_adaptive_loop_null2.nit:30,5--22: Warning: expression is already a `nullable Int` since it is a `null`. +base_adaptive_loop_null2.nit:32,5--23: Warning: expression is already a `nullable Bool` since it is a `null`. +base_adaptive_loop_null2.nit:33,6: Warning: expression is always `null`. +base_adaptive_loop_null2.nit:45,5: Warning: expression is not null, since it is a `Int`. +base_adaptive_loop_null2.nit:47,5: Warning: expression is not null, since it is a `Int`. +base_adaptive_loop_null2.nit:49,5--13: Warning: expression is already a `Int`. +base_adaptive_loop_null2.nit:51,5--22: Warning: expression is already a `nullable Int` since it is a `Int`. +base_adaptive_loop_null2.nit:54,6: Warning: expression is not null, since it is a `Int`. +1 +4 +5 +6 +1 +4 +5 +6 +2 +3 +4 +10 +2 +3 +4 +10 diff --git a/tests/sav/base_adaptive_loop_null2_alt1.res b/tests/sav/base_adaptive_loop_null2_alt1.res new file mode 100644 index 0000000..e8a4e3a --- /dev/null +++ b/tests/sav/base_adaptive_loop_null2_alt1.res @@ -0,0 +1,18 @@ +alt/base_adaptive_loop_null2_alt1.nit:30,5--22: Warning: expression is already a `nullable Int`. +alt/base_adaptive_loop_null2_alt1.nit:51,5--22: Warning: expression is already a `nullable Int`. +1 +4 +5 +6 +2 +3 +4 +1 +2 +3 +4 +10 +1 +4 +5 +6 diff --git a/tests/sav/base_adaptive_loop_null_alt1.res b/tests/sav/base_adaptive_loop_null_alt1.res index 573541a..e4d78f8 100644 --- a/tests/sav/base_adaptive_loop_null_alt1.res +++ b/tests/sav/base_adaptive_loop_null_alt1.res @@ -1 +1,2 @@ +alt/base_adaptive_loop_null_alt1.nit:23,7: Warning: expression is always `null`. 0 -- 1.7.9.5