tests: introducing some tests for the catch
authorBlackMinou <romain.chanoir@viacesi.fr>
Sat, 9 Apr 2016 01:24:10 +0000 (21:24 -0400)
committerBlackMinou <romain.chanoir@viacesi.fr>
Tue, 12 Apr 2016 19:39:33 +0000 (15:39 -0400)
Signed-off-by: BlackMinou <romain.chanoir@viacesi.fr>

12 files changed:
tests/sav/test_catch_attributes.res [new file with mode: 0644]
tests/sav/test_catch_imbricated.res [new file with mode: 0644]
tests/sav/test_catch_in_catch.res [new file with mode: 0644]
tests/sav/test_catch_loop.res [new file with mode: 0644]
tests/sav/test_catch_objects.res [new file with mode: 0644]
tests/sav/test_catch_simple.res [new file with mode: 0644]
tests/test_catch_attributes.nit [new file with mode: 0644]
tests/test_catch_imbricated.nit [new file with mode: 0644]
tests/test_catch_in_catch.nit [new file with mode: 0644]
tests/test_catch_loop.nit [new file with mode: 0644]
tests/test_catch_objects.nit [new file with mode: 0644]
tests/test_catch_simple.nit [new file with mode: 0644]

diff --git a/tests/sav/test_catch_attributes.res b/tests/sav/test_catch_attributes.res
new file mode 100644 (file)
index 0000000..f599e28
--- /dev/null
@@ -0,0 +1 @@
+10
diff --git a/tests/sav/test_catch_imbricated.res b/tests/sav/test_catch_imbricated.res
new file mode 100644 (file)
index 0000000..ace9ad9
--- /dev/null
@@ -0,0 +1,6 @@
+1st lvl do
+2nd lvl do
+3rd lvl do
+2nd lvl catch
+1st lvl catch
+fin du programme
diff --git a/tests/sav/test_catch_in_catch.res b/tests/sav/test_catch_in_catch.res
new file mode 100644 (file)
index 0000000..030cb5c
--- /dev/null
@@ -0,0 +1 @@
+catch in catch
diff --git a/tests/sav/test_catch_loop.res b/tests/sav/test_catch_loop.res
new file mode 100644 (file)
index 0000000..88423df
--- /dev/null
@@ -0,0 +1,5 @@
+0
+2
+4
+6
+8
diff --git a/tests/sav/test_catch_objects.res b/tests/sav/test_catch_objects.res
new file mode 100644 (file)
index 0000000..264de7a
--- /dev/null
@@ -0,0 +1,4 @@
+about to abort in A.foo
+catched abort from A.foo
+about to abort in B.bar
+catched the abort from B.bar
diff --git a/tests/sav/test_catch_simple.res b/tests/sav/test_catch_simple.res
new file mode 100644 (file)
index 0000000..257cc56
--- /dev/null
@@ -0,0 +1 @@
+foo
diff --git a/tests/test_catch_attributes.nit b/tests/test_catch_attributes.nit
new file mode 100644 (file)
index 0000000..99115c4
--- /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.
+
+class A
+       var x: Int
+
+       fun foo do
+               x = 10
+               abort
+       end
+end
+
+var y
+y = new A(100)
+do
+       y.foo
+catch
+       print y.x
+end
diff --git a/tests/test_catch_imbricated.nit b/tests/test_catch_imbricated.nit
new file mode 100644 (file)
index 0000000..f00479d
--- /dev/null
@@ -0,0 +1,37 @@
+# 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.
+
+var x = ""
+do
+       x = "1st lvl do"
+       print x
+       do
+               x = "2nd lvl do"
+               print x
+               do
+                       x = "3rd lvl do"
+                       print x
+               end
+               abort
+       catch
+               x = "2nd lvl catch"
+               print x
+               abort
+       end
+catch
+       x = "1st lvl catch"
+       print x
+end
+x = "fin du programme"
+print x
diff --git a/tests/test_catch_in_catch.nit b/tests/test_catch_in_catch.nit
new file mode 100644 (file)
index 0000000..c02e2a2
--- /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.
+
+do
+       abort
+catch
+       do
+               abort
+       catch
+               print "catch in catch"
+       end
+end
diff --git a/tests/test_catch_loop.nit b/tests/test_catch_loop.nit
new file mode 100644 (file)
index 0000000..2d7c252
--- /dev/null
@@ -0,0 +1,21 @@
+# 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.
+
+for i in 10.times do
+       do
+               if i.is_even then abort
+       catch
+               print i
+       end
+end
diff --git a/tests/test_catch_objects.nit b/tests/test_catch_objects.nit
new file mode 100644 (file)
index 0000000..dec13bb
--- /dev/null
@@ -0,0 +1,47 @@
+# 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 do
+               print "about to abort in A.foo"
+               abort
+       end
+
+       fun test do
+               var b
+               do
+                       b = new A
+                       foo
+               catch
+                       print "catched abort from A.foo"
+                       b = new B
+                       b.bar
+               end
+       end
+end
+
+class B
+       fun bar do
+               print "about to abort in B.bar"
+               abort
+       end
+
+end
+
+do
+       var a = new A
+       a.test
+catch
+       print "catched the abort from B.bar"
+end
diff --git a/tests/test_catch_simple.nit b/tests/test_catch_simple.nit
new file mode 100644 (file)
index 0000000..2888d75
--- /dev/null
@@ -0,0 +1,22 @@
+# 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.
+
+var x
+do
+       x = 11
+       abort
+catch
+       x = "foo"
+end
+print x