tests: add some base tests
authorJean Privat <jean@pryen.org>
Tue, 10 Apr 2012 20:50:07 +0000 (16:50 -0400)
committerJean Privat <jean@pryen.org>
Mon, 16 Apr 2012 18:35:33 +0000 (14:35 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

19 files changed:
tests/base_fun_reassign.nit [new file with mode: 0644]
tests/base_init.nit [new file with mode: 0644]
tests/base_isa_formal_type.nit [new file with mode: 0644]
tests/base_recurcivity.nit [new file with mode: 0644]
tests/base_simple3.nit [new file with mode: 0644]
tests/base_types_formal_and_virtual4.nit [new file with mode: 0644]
tests/base_var_type_evolution_null5.nit [new file with mode: 0644]
tests/base_var_type_evolution_null_while.nit [new file with mode: 0644]
tests/base_var_type_evolution_nullable.nit [new file with mode: 0644]
tests/example_power_with_iterate.nit [new file with mode: 0644]
tests/sav/base_fun_reassign.sav [new file with mode: 0644]
tests/sav/base_init.sav [new file with mode: 0644]
tests/sav/base_recurcivity.sav [new file with mode: 0644]
tests/sav/base_simple3.sav [new file with mode: 0644]
tests/sav/base_types_formal_and_virtual4.sav [new file with mode: 0644]
tests/sav/base_var_type_evolution_null5.sav [new file with mode: 0644]
tests/sav/base_var_type_evolution_null_while.sav [new file with mode: 0644]
tests/sav/base_var_type_evolution_nullable.sav [new file with mode: 0644]
tests/sav/example_power_with_iterate.sav [new file with mode: 0644]

diff --git a/tests/base_fun_reassign.nit b/tests/base_fun_reassign.nit
new file mode 100644 (file)
index 0000000..b58d575
--- /dev/null
@@ -0,0 +1,31 @@
+# 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
+       var x: Int = 0
+       fun y(i: Int): Int do return x * i
+       fun y=(i, o: Int) do x = (o / i)
+end
+
+var a = new A
+a.x += 2
+a.x.output
+
+a.y(10).output
+a.y(10) += 30
+a.y(10).output
+
+a.x.output
diff --git a/tests/base_init.nit b/tests/base_init.nit
new file mode 100644 (file)
index 0000000..87cbcbf
--- /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 end
+
+interface Object
+end
+
+enum Char
+       fun output is intern
+end
+
+class A
+       init
+       do
+               'A'.output
+       end
+end
+
+class B
+       super A
+       init
+       do
+               'B'.output
+       end
+end
+
+class C
+       super A
+end
+
+var a = new A
+'\n'.output
+
+var b = new B
+'\n'.output
+
+var c = new C
+'\n'.output
diff --git a/tests/base_isa_formal_type.nit b/tests/base_isa_formal_type.nit
new file mode 100644 (file)
index 0000000..855298f
--- /dev/null
@@ -0,0 +1,63 @@
+# 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[T]
+       type U: Object
+       fun testT(o: Object): Bool do return o isa T
+       fun testU(o: Object): Bool do return o isa U
+
+       fun get_c: C[U,T] do return new C[U,T]
+
+       fun testall
+       do
+               self.testT(1).output
+               self.testT(true).output
+               self.testU(1).output
+               self.testU(true).output
+               var c = get_c
+               c.testT(1).output
+               c.testT(true).output
+               c.testU(1).output
+               c.testU(true).output
+               '\n'.output
+       end
+end
+
+class B
+       super A[Int]
+       redef type U: Bool
+       fun foo: A[Bool] do return get_c
+end
+
+class C[V, W]
+       super A[V]
+       redef type U: W
+       fun foo: A[W] do return get_c
+end
+
+var ao = new A[Object]
+var ai = new A[Int]
+var b = new B
+var coo = new C[Object, Object]
+var cib = new C[Int, Bool]
+
+ao.testall
+ai.testall
+b.testall
+b.foo.testall
+coo.testall
+cib.testall
+cib.foo.testall
diff --git a/tests/base_recurcivity.nit b/tests/base_recurcivity.nit
new file mode 100644 (file)
index 0000000..2276d92
--- /dev/null
@@ -0,0 +1,23 @@
+# 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
+
+fun foo(i: Int)
+do
+       i.output
+       if i>0 then foo(i-1)
+       i.output
+end
+foo(5)
diff --git a/tests/base_simple3.nit b/tests/base_simple3.nit
new file mode 100644 (file)
index 0000000..8bb2bc8
--- /dev/null
@@ -0,0 +1,66 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2006-2008 Jean Privat <jean@pryen.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 end
+
+interface Object
+end
+
+enum Bool
+end
+
+enum Int
+       fun output is intern
+end
+
+class A
+       init do 5.output
+       fun run do 6.output
+end
+
+class B
+       var val: Int
+       init(v: Int)
+       do
+               7.output
+               self.val = v
+       end
+       fun run do val.output
+end
+
+class C
+       var val1: Int
+       var val2: Int = 10
+end
+
+fun foo do 2.output
+fun bar(i: Int) do i.output
+fun baz: Int do return 4
+
+1.output
+foo
+bar(3)
+baz.output
+
+var a = new A
+a.run
+
+var b = new B(8)
+b.run
+
+var c = new C(9)
+c.val1.output
+c.val2.output
diff --git a/tests/base_types_formal_and_virtual4.nit b/tests/base_types_formal_and_virtual4.nit
new file mode 100644 (file)
index 0000000..717376e
--- /dev/null
@@ -0,0 +1,44 @@
+# 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 end
+
+class Object
+end
+
+class A[E: Object]
+       fun e: E is abstract
+end
+
+class C[G: Object]
+       type V: A[G]
+       fun v: V is abstract
+       fun test
+       do
+               __debug__ type V : v
+               __debug__ type G : v.e
+       end
+end
+
+class B[F: A[X]]
+       fun f: F is abstract
+       fun test
+       do
+               __debug__ type F : f
+               __debug__ type X : f.e
+       end
+end
+
+class X
+end
diff --git a/tests/base_var_type_evolution_null5.nit b/tests/base_var_type_evolution_null5.nit
new file mode 100644 (file)
index 0000000..d3acc6e
--- /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 end
+
+class Object
+       fun ==(o: nullable Object): Bool do return self is o
+       fun !=(o: nullable Object): Bool do return not self is o
+end
+
+class A
+end
+
+class Bool
+       fun output is intern
+end
+
+fun test(a: nullable A)
+do
+       #__debug__ type nullable A : a
+
+       #if a != null then
+       #       __debug__ type A : a
+       #end
+
+       #__debug__ type nullable A : a
+
+       if a == null then
+               false.output
+               return
+       end
+
+       __debug__ type A : a
+
+       true.output
+end
+
+test(new A)
+test(null)
diff --git a/tests/base_var_type_evolution_null_while.nit b/tests/base_var_type_evolution_null_while.nit
new file mode 100644 (file)
index 0000000..56eacc1
--- /dev/null
@@ -0,0 +1,60 @@
+# 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 end
+
+class Object
+       fun ==(o: nullable Object): Bool do return self is o
+       fun !=(o: nullable Object): Bool do return not self is o
+end
+
+class A
+end
+
+class Bool
+       fun output is intern
+end
+
+fun maybe: Bool do return true
+
+fun test1(a: nullable A)
+do
+       var res = a
+       while res == null do
+               if maybe then
+                       false.output
+                       return
+               end
+       end
+       __debug__ type A : res
+       true.output
+end
+
+fun test2(a: nullable A)
+do
+       var res = a
+       while res != null do
+               __debug__ type A : res
+               if maybe then
+                       false.output
+                       return
+               end
+       end
+       true.output
+end
+
+test1(new A)
+test1(null)
+test2(new A)
+test2(null)
diff --git a/tests/base_var_type_evolution_nullable.nit b/tests/base_var_type_evolution_nullable.nit
new file mode 100644 (file)
index 0000000..a6e25fe
--- /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 end
+
+class Object
+       fun ==(o: nullable Object): Bool is intern
+       fun !=(o: nullable Object): Bool is intern
+end
+
+class A
+end
+
+class Bool
+       fun output is intern
+end
+
+fun test(a: nullable A)
+do
+       __debug__ type nullable A : a
+
+       if a isa A then
+               __debug__ type A : a
+       end
+
+       __debug__ type nullable A : a
+
+       if not a isa A then
+               false.output
+               return
+       end
+
+       __debug__ type A : a
+
+       true.output
+end
+
+test(new A)
+test(null)
diff --git a/tests/example_power_with_iterate.nit b/tests/example_power_with_iterate.nit
new file mode 100644 (file)
index 0000000..aa31971
--- /dev/null
@@ -0,0 +1,31 @@
+# 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 Power
+       var number: Int
+       var exponent: Int
+
+       fun iterate !each(i: Int)
+       do
+               var res = 1
+               for i in [0..self.exponent[ do
+                       res = res * self.number
+                       each(res)
+               end
+       end
+end
+
+for i in new Power(2, 8) do
+       print i
+end
diff --git a/tests/sav/base_fun_reassign.sav b/tests/sav/base_fun_reassign.sav
new file mode 100644 (file)
index 0000000..a46faab
--- /dev/null
@@ -0,0 +1,4 @@
+2
+20
+50
+5
diff --git a/tests/sav/base_init.sav b/tests/sav/base_init.sav
new file mode 100644 (file)
index 0000000..d796442
--- /dev/null
@@ -0,0 +1,3 @@
+A
+AB
+A
diff --git a/tests/sav/base_recurcivity.sav b/tests/sav/base_recurcivity.sav
new file mode 100644 (file)
index 0000000..977d57b
--- /dev/null
@@ -0,0 +1,12 @@
+5
+4
+3
+2
+1
+0
+0
+1
+2
+3
+4
+5
diff --git a/tests/sav/base_simple3.sav b/tests/sav/base_simple3.sav
new file mode 100644 (file)
index 0000000..f00c965
--- /dev/null
@@ -0,0 +1,10 @@
+1
+2
+3
+4
+5
+6
+7
+8
+9
+10
diff --git a/tests/sav/base_types_formal_and_virtual4.sav b/tests/sav/base_types_formal_and_virtual4.sav
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/sav/base_var_type_evolution_null5.sav b/tests/sav/base_var_type_evolution_null5.sav
new file mode 100644 (file)
index 0000000..da29283
--- /dev/null
@@ -0,0 +1,2 @@
+true
+false
diff --git a/tests/sav/base_var_type_evolution_null_while.sav b/tests/sav/base_var_type_evolution_null_while.sav
new file mode 100644 (file)
index 0000000..e50fb21
--- /dev/null
@@ -0,0 +1,4 @@
+true
+false
+false
+true
diff --git a/tests/sav/base_var_type_evolution_nullable.sav b/tests/sav/base_var_type_evolution_nullable.sav
new file mode 100644 (file)
index 0000000..642baae
--- /dev/null
@@ -0,0 +1,4 @@
+base_var_type_evolution_nullable.nit:33,5--11: Warning: Prefer '!= null'.
+base_var_type_evolution_nullable.nit:39,9--15: Warning: Prefer '!= null'.
+true
+false
diff --git a/tests/sav/example_power_with_iterate.sav b/tests/sav/example_power_with_iterate.sav
new file mode 100644 (file)
index 0000000..06d3a66
--- /dev/null
@@ -0,0 +1,8 @@
+2
+4
+8
+16
+32
+64
+128
+256