tests: add base_adaptive_loop*.nit
authorJean Privat <jean@pryen.org>
Sun, 12 Apr 2015 04:14:58 +0000 (11:14 +0700)
committerJean Privat <jean@pryen.org>
Tue, 14 Apr 2015 09:31:36 +0000 (16:31 +0700)
Signed-off-by: Jean Privat <jean@pryen.org>

30 files changed:
tests/base_adaptive_loop.nit [new file with mode: 0644]
tests/base_adaptive_loop2.nit [new file with mode: 0644]
tests/base_adaptive_loop3.nit [new file with mode: 0644]
tests/base_adaptive_loop_array.nit [new file with mode: 0644]
tests/base_adaptive_loop_call.nit [new file with mode: 0644]
tests/base_adaptive_loop_null.nit [new file with mode: 0644]
tests/sav/base_adaptive_loop.res [new file with mode: 0644]
tests/sav/base_adaptive_loop2.res [new file with mode: 0644]
tests/sav/base_adaptive_loop2_alt1.res [new file with mode: 0644]
tests/sav/base_adaptive_loop2_alt2.res [new file with mode: 0644]
tests/sav/base_adaptive_loop2_alt3.res [new file with mode: 0644]
tests/sav/base_adaptive_loop3.res [new file with mode: 0644]
tests/sav/base_adaptive_loop3_alt1.res [new file with mode: 0644]
tests/sav/base_adaptive_loop3_alt2.res [new file with mode: 0644]
tests/sav/base_adaptive_loop3_alt3.res [new file with mode: 0644]
tests/sav/base_adaptive_loop_alt1.res [new file with mode: 0644]
tests/sav/base_adaptive_loop_array.res [new file with mode: 0644]
tests/sav/base_adaptive_loop_array_1alt1.res [new file with mode: 0644]
tests/sav/base_adaptive_loop_array_1alt1_alt1.res [new file with mode: 0644]
tests/sav/base_adaptive_loop_array_1alt2.res [new file with mode: 0644]
tests/sav/base_adaptive_loop_array_1alt2_alt1.res [new file with mode: 0644]
tests/sav/base_adaptive_loop_array_alt1.res [new file with mode: 0644]
tests/sav/base_adaptive_loop_call.res [new file with mode: 0644]
tests/sav/base_adaptive_loop_call_alt1.res [new file with mode: 0644]
tests/sav/base_adaptive_loop_call_alt2.res [new file with mode: 0644]
tests/sav/base_adaptive_loop_null.res [new file with mode: 0644]
tests/sav/base_adaptive_loop_null_alt1.res [new file with mode: 0644]
tests/sav/base_adaptive_loop_null_alt2.res [new file with mode: 0644]
tests/sav/base_adaptive_loop_null_alt3.res [new file with mode: 0644]
tests/sav/base_adaptive_loop_null_alt4.res [new file with mode: 0644]

diff --git a/tests/base_adaptive_loop.nit b/tests/base_adaptive_loop.nit
new file mode 100644 (file)
index 0000000..d31598e
--- /dev/null
@@ -0,0 +1,33 @@
+# 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
+
+fun foo(i: Int): nullable Int do return i
+fun bar(i: Int) do i.output
+
+var i = 0
+var c = 0
+while i < 10 do
+       i += 1
+
+       var b = foo(i)
+       if b == null then
+               continue#alt1#
+       end
+
+       bar(b)
+       c = b
+end
+bar(c)
diff --git a/tests/base_adaptive_loop2.nit b/tests/base_adaptive_loop2.nit
new file mode 100644 (file)
index 0000000..bade6da
--- /dev/null
@@ -0,0 +1,38 @@
+# 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 do 1.output
+end
+
+class B
+       super A
+       fun bar do 2.output
+end
+
+var x: A #alt3# var x
+x = new B
+
+var i = 0
+while i < 3 do
+       i += 1
+       x.bar
+       x = new A
+       x.foo
+       break#alt1#
+end
+x.foo
+#alt2#x.bar
diff --git a/tests/base_adaptive_loop3.nit b/tests/base_adaptive_loop3.nit
new file mode 100644 (file)
index 0000000..33f4c8d
--- /dev/null
@@ -0,0 +1,30 @@
+# 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
+
+redef class Int
+       fun next: nullable Int do if self < 20 then return self + 1 else return null
+end
+
+var t2: nullable Int = 10
+t2.output
+while t2 != null do
+       t2 = t2.next #alt1# t2 = null
+       while t2 != null do
+               t2.output
+               t2 = t2.next #alt2# t2 = null
+       end
+       #alt3#t2 = t2.next
+end
diff --git a/tests/base_adaptive_loop_array.nit b/tests/base_adaptive_loop_array.nit
new file mode 100644 (file)
index 0000000..868c0cc
--- /dev/null
@@ -0,0 +1,28 @@
+# 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::collection::array
+
+var a #1alt1#var a: Array[Object]
+a = [1]#1alt2#
+#1alt2#a = 1
+var i = 0
+while i < 3 do
+       i += 1
+
+       a = [a]
+       a.length.output
+       #alt1#a.first.length.output
+end
+#alt1#a.length.output
diff --git a/tests/base_adaptive_loop_call.nit b/tests/base_adaptive_loop_call.nit
new file mode 100644 (file)
index 0000000..2a99ba7
--- /dev/null
@@ -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
+
+class O
+       fun foo: O do
+               0.output
+               return new B
+       end
+end
+
+class A
+       super O
+       redef fun foo: B do
+               1.output
+               return new B
+       end
+       fun bar: B do
+               10.output
+               return new B
+       end
+end
+
+class B
+       super O
+       redef fun foo: C do
+               2.output
+               return new C
+       end
+       fun bar: C do
+               20.output
+               return new C
+       end
+end
+
+class C
+       super O
+end
+
+var a: O #alt1# var a
+
+a = new A
+var i = 0
+while i < 4 do
+       a = a.foo #alt2# a = a.bar
+       i += 1
+end
diff --git a/tests/base_adaptive_loop_null.nit b/tests/base_adaptive_loop_null.nit
new file mode 100644 (file)
index 0000000..cfbb80f
--- /dev/null
@@ -0,0 +1,53 @@
+# 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
+
+fun foo(i: Int): nullable Int do return i
+fun bar(i: Int) do i.output
+fun baz: nullable Int do return null
+
+bar(0)
+var i = null
+while i == null do
+       i = foo(1) #alt1# exit(1)
+end
+bar(i)
+
+i = foo(2)
+while i != null do
+       bar(i)
+       i = baz
+end
+#alt2#bar(i)
+
+i = null
+loop
+       i = foo(3)
+       if i == null then continue #alt3#
+       bar(i)
+       break
+end
+bar(i)
+
+i = 4
+loop
+       bar(i)
+       i = baz
+       if i != null then
+               bar(i)
+       else
+               break #alt4#
+       end
+end
diff --git a/tests/sav/base_adaptive_loop.res b/tests/sav/base_adaptive_loop.res
new file mode 100644 (file)
index 0000000..958699b
--- /dev/null
@@ -0,0 +1,11 @@
+1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+10
diff --git a/tests/sav/base_adaptive_loop2.res b/tests/sav/base_adaptive_loop2.res
new file mode 100644 (file)
index 0000000..afe234b
--- /dev/null
@@ -0,0 +1,3 @@
+2
+1
+1
diff --git a/tests/sav/base_adaptive_loop2_alt1.res b/tests/sav/base_adaptive_loop2_alt1.res
new file mode 100644 (file)
index 0000000..95f0863
--- /dev/null
@@ -0,0 +1 @@
+alt/base_adaptive_loop2_alt1.nit:32,2--6: Error: Method 'bar' doesn't exists in A.
diff --git a/tests/sav/base_adaptive_loop2_alt2.res b/tests/sav/base_adaptive_loop2_alt2.res
new file mode 100644 (file)
index 0000000..7fb541b
--- /dev/null
@@ -0,0 +1 @@
+alt/base_adaptive_loop2_alt2.nit:38,1--5: Error: Method 'bar' doesn't exists in A.
diff --git a/tests/sav/base_adaptive_loop2_alt3.res b/tests/sav/base_adaptive_loop2_alt3.res
new file mode 100644 (file)
index 0000000..afe234b
--- /dev/null
@@ -0,0 +1,3 @@
+2
+1
+1
diff --git a/tests/sav/base_adaptive_loop3.res b/tests/sav/base_adaptive_loop3.res
new file mode 100644 (file)
index 0000000..e33f5e9
--- /dev/null
@@ -0,0 +1,11 @@
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
diff --git a/tests/sav/base_adaptive_loop3_alt1.res b/tests/sav/base_adaptive_loop3_alt1.res
new file mode 100644 (file)
index 0000000..f599e28
--- /dev/null
@@ -0,0 +1 @@
+10
diff --git a/tests/sav/base_adaptive_loop3_alt2.res b/tests/sav/base_adaptive_loop3_alt2.res
new file mode 100644 (file)
index 0000000..b5fa014
--- /dev/null
@@ -0,0 +1,2 @@
+10
+11
diff --git a/tests/sav/base_adaptive_loop3_alt3.res b/tests/sav/base_adaptive_loop3_alt3.res
new file mode 100644 (file)
index 0000000..2b29529
--- /dev/null
@@ -0,0 +1 @@
+alt/base_adaptive_loop3_alt3.nit:29,7--13: Error: Method 'next' call on 'null'.
diff --git a/tests/sav/base_adaptive_loop_alt1.res b/tests/sav/base_adaptive_loop_alt1.res
new file mode 100644 (file)
index 0000000..8526116
--- /dev/null
@@ -0,0 +1,2 @@
+alt/base_adaptive_loop_alt1.nit:30,6: Type error: expected Int, got nullable Int
+alt/base_adaptive_loop_alt1.nit:31,6: Type error: expected Int, got nullable Int
diff --git a/tests/sav/base_adaptive_loop_array.res b/tests/sav/base_adaptive_loop_array.res
new file mode 100644 (file)
index 0000000..e8183f0
--- /dev/null
@@ -0,0 +1,3 @@
+1
+1
+1
diff --git a/tests/sav/base_adaptive_loop_array_1alt1.res b/tests/sav/base_adaptive_loop_array_1alt1.res
new file mode 100644 (file)
index 0000000..e8183f0
--- /dev/null
@@ -0,0 +1,3 @@
+1
+1
+1
diff --git a/tests/sav/base_adaptive_loop_array_1alt1_alt1.res b/tests/sav/base_adaptive_loop_array_1alt1_alt1.res
new file mode 100644 (file)
index 0000000..fcb49fa
--- /dev/null
@@ -0,0 +1,7 @@
+1
+1
+1
+1
+1
+1
+1
diff --git a/tests/sav/base_adaptive_loop_array_1alt2.res b/tests/sav/base_adaptive_loop_array_1alt2.res
new file mode 100644 (file)
index 0000000..e8183f0
--- /dev/null
@@ -0,0 +1,3 @@
+1
+1
+1
diff --git a/tests/sav/base_adaptive_loop_array_1alt2_alt1.res b/tests/sav/base_adaptive_loop_array_1alt2_alt1.res
new file mode 100644 (file)
index 0000000..aab8da7
--- /dev/null
@@ -0,0 +1,3 @@
+alt/base_adaptive_loop_array_1alt2_alt1.nit:26,2--15: Error: Method 'length' doesn't exists in Int.
+alt/base_adaptive_loop_array_1alt2_alt1.nit:26,2--15: Error: Method 'length' doesn't exists in nullable Object.
+alt/base_adaptive_loop_array_1alt2_alt1.nit:28,1--8: Error: Method 'length' doesn't exists in nullable Object.
diff --git a/tests/sav/base_adaptive_loop_array_alt1.res b/tests/sav/base_adaptive_loop_array_alt1.res
new file mode 100644 (file)
index 0000000..78d6853
--- /dev/null
@@ -0,0 +1,2 @@
+alt/base_adaptive_loop_array_alt1.nit:26,2--15: Error: Method 'length' doesn't exists in nullable Object.
+alt/base_adaptive_loop_array_alt1.nit:28,1--8: Error: Method 'length' doesn't exists in nullable Object.
diff --git a/tests/sav/base_adaptive_loop_call.res b/tests/sav/base_adaptive_loop_call.res
new file mode 100644 (file)
index 0000000..92c5e8d
--- /dev/null
@@ -0,0 +1,4 @@
+1
+2
+0
+2
diff --git a/tests/sav/base_adaptive_loop_call_alt1.res b/tests/sav/base_adaptive_loop_call_alt1.res
new file mode 100644 (file)
index 0000000..36d0245
--- /dev/null
@@ -0,0 +1 @@
+alt/base_adaptive_loop_call_alt1.nit:57,6--10: Error: Method 'foo' doesn't exists in nullable Object.
diff --git a/tests/sav/base_adaptive_loop_call_alt2.res b/tests/sav/base_adaptive_loop_call_alt2.res
new file mode 100644 (file)
index 0000000..f926a35
--- /dev/null
@@ -0,0 +1 @@
+alt/base_adaptive_loop_call_alt2.nit:57,6--10: Error: Method 'bar' doesn't exists in O.
diff --git a/tests/sav/base_adaptive_loop_null.res b/tests/sav/base_adaptive_loop_null.res
new file mode 100644 (file)
index 0000000..ccbe3cc
--- /dev/null
@@ -0,0 +1,6 @@
+0
+1
+2
+3
+3
+4
diff --git a/tests/sav/base_adaptive_loop_null_alt1.res b/tests/sav/base_adaptive_loop_null_alt1.res
new file mode 100644 (file)
index 0000000..573541a
--- /dev/null
@@ -0,0 +1 @@
+0
diff --git a/tests/sav/base_adaptive_loop_null_alt2.res b/tests/sav/base_adaptive_loop_null_alt2.res
new file mode 100644 (file)
index 0000000..17a24a7
--- /dev/null
@@ -0,0 +1 @@
+alt/base_adaptive_loop_null_alt2.nit:33,5: Type error: expected Int, got null
diff --git a/tests/sav/base_adaptive_loop_null_alt3.res b/tests/sav/base_adaptive_loop_null_alt3.res
new file mode 100644 (file)
index 0000000..0d93ee8
--- /dev/null
@@ -0,0 +1,2 @@
+alt/base_adaptive_loop_null_alt3.nit:39,6: Type error: expected Int, got nullable Int
+alt/base_adaptive_loop_null_alt3.nit:42,5: Type error: expected Int, got nullable Int
diff --git a/tests/sav/base_adaptive_loop_null_alt4.res b/tests/sav/base_adaptive_loop_null_alt4.res
new file mode 100644 (file)
index 0000000..bb3b854
--- /dev/null
@@ -0,0 +1 @@
+alt/base_adaptive_loop_null_alt4.nit:46,6: Type error: expected Int, got nullable Int