New test suite for default blocs.
authorJean Privat <jean@pryen.org>
Fri, 6 Feb 2009 15:11:20 +0000 (10:11 -0500)
committerJean Privat <jean@pryen.org>
Fri, 6 Feb 2009 15:11:20 +0000 (10:11 -0500)
32 files changed:
tests/base_closure_default1.nit [new file with mode: 0644]
tests/base_closure_default2.nit [new file with mode: 0644]
tests/base_closure_default3.nit [new file with mode: 0644]
tests/base_closure_default4.nit [new file with mode: 0644]
tests/sav/base_closure_default1.sav [new file with mode: 0644]
tests/sav/base_closure_default1_alt1.sav [new file with mode: 0644]
tests/sav/base_closure_default1_alt2.sav [new file with mode: 0644]
tests/sav/base_closure_default1_alt3.sav [new file with mode: 0644]
tests/sav/base_closure_default1_alt4.sav [new file with mode: 0644]
tests/sav/base_closure_default1_alt5.sav [new file with mode: 0644]
tests/sav/base_closure_default2.sav [new file with mode: 0644]
tests/sav/base_closure_default2_alt1.sav [new file with mode: 0644]
tests/sav/base_closure_default2_alt2.sav [new file with mode: 0644]
tests/sav/base_closure_default2_alt3.sav [new file with mode: 0644]
tests/sav/base_closure_default2_alt4.sav [new file with mode: 0644]
tests/sav/base_closure_default2_alt5.sav [new file with mode: 0644]
tests/sav/base_closure_default2_alt6.sav [new file with mode: 0644]
tests/sav/base_closure_default3.sav [new file with mode: 0644]
tests/sav/base_closure_default3_alt1.sav [new file with mode: 0644]
tests/sav/base_closure_default3_alt2.sav [new file with mode: 0644]
tests/sav/base_closure_default3_alt3.sav [new file with mode: 0644]
tests/sav/base_closure_default3_alt4.sav [new file with mode: 0644]
tests/sav/base_closure_default3_alt5.sav [new file with mode: 0644]
tests/sav/base_closure_default4.sav [new file with mode: 0644]
tests/sav/base_closure_default4_alt1.sav [new file with mode: 0644]
tests/sav/base_closure_default4_alt2.sav [new file with mode: 0644]
tests/sav/base_closure_default4_alt3.sav [new file with mode: 0644]
tests/sav/base_closure_default4_alt4.sav [new file with mode: 0644]
tests/sav/base_closure_default4_alt5.sav [new file with mode: 0644]
tests/sav/test_map_closure_default.sav [new file with mode: 0644]
tests/sav/test_map_closure_default_alt1.sav [new file with mode: 0644]
tests/test_map_closure_default.nit [new file with mode: 0644]

diff --git a/tests/base_closure_default1.nit b/tests/base_closure_default1.nit
new file mode 100644 (file)
index 0000000..0210965
--- /dev/null
@@ -0,0 +1,41 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2009 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 kernel
+
+class A
+       meth foo
+               with bar do
+                       #alt1# return
+                       #alt2# return 1
+                       #alt3# abort
+                       #alt4# continue
+                       #alt5# continue 20
+                       20.output
+               end
+       do
+               1.output
+               bar
+               3.output
+       end
+end
+
+var a = new A
+0.output
+a.foo with do 2.output
+0.output
+a.foo
+0.output
diff --git a/tests/base_closure_default2.nit b/tests/base_closure_default2.nit
new file mode 100644 (file)
index 0000000..30b5f29
--- /dev/null
@@ -0,0 +1,42 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2009 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 kernel
+
+class A
+       meth foo
+               with bar(i: Int) do
+                       #alt1# return
+                       #alt2# return 1
+                       #alt3# abort
+                       #alt4# continue
+                       #alt5# continue 20
+                       (i * 10).output
+               end
+       do
+               1.output
+               bar(2)
+               #alt6#i.output
+               3.output
+       end
+end
+
+var a = new A
+0.output
+a.foo with j do j.output
+0.output
+a.foo
+0.output
diff --git a/tests/base_closure_default3.nit b/tests/base_closure_default3.nit
new file mode 100644 (file)
index 0000000..522b39c
--- /dev/null
@@ -0,0 +1,40 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2009 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 kernel
+
+class A
+       meth foo
+               with bar: Int do
+                       #alt1# return
+                       #alt2# return 1
+                       #alt3# abort
+                       #alt4# continue
+                       continue 20 #!alt5#
+               end
+       do
+               1.output
+               bar.output
+               3.output
+       end
+end
+
+var a = new A
+0.output
+a.foo with do continue 2
+0.output
+a.foo
+0.output
diff --git a/tests/base_closure_default4.nit b/tests/base_closure_default4.nit
new file mode 100644 (file)
index 0000000..494cebb
--- /dev/null
@@ -0,0 +1,40 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2009 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 kernel
+
+class A
+       meth foo
+               with bar(i: Int): Int do
+                       #alt1# return
+                       #alt2# return -1
+                       #alt3# abort
+                       #alt4# continue
+                       continue (i * 10) #!alt5#
+               end
+       do
+               1.output
+               bar(2).output
+               3.output
+       end
+end
+
+var a = new A
+0.output
+a.foo with j do continue j
+0.output
+a.foo
+0.output
diff --git a/tests/sav/base_closure_default1.sav b/tests/sav/base_closure_default1.sav
new file mode 100644 (file)
index 0000000..861f40d
--- /dev/null
@@ -0,0 +1,9 @@
+0
+1
+2
+3
+0
+1
+20
+3
+0
diff --git a/tests/sav/base_closure_default1_alt1.sav b/tests/sav/base_closure_default1_alt1.sav
new file mode 100644 (file)
index 0000000..e8350ed
--- /dev/null
@@ -0,0 +1,7 @@
+0
+1
+2
+3
+0
+1
+0
diff --git a/tests/sav/base_closure_default1_alt2.sav b/tests/sav/base_closure_default1_alt2.sav
new file mode 100644 (file)
index 0000000..4f8aa5e
--- /dev/null
@@ -0,0 +1 @@
+alt/base_closure_default1_alt2.nit:23,5--12: Error: Return with value in a procedure.
diff --git a/tests/sav/base_closure_default1_alt3.sav b/tests/sav/base_closure_default1_alt3.sav
new file mode 100644 (file)
index 0000000..6c6724d
--- /dev/null
@@ -0,0 +1,11 @@
+0
+1
+2
+3
+0
+1
+Aborted in base_closure_default1_alt3::A::foo (alt/base_closure_default1_alt3.nit:24)
+,---- Stack trace -- - -  -
+| base_closure_default1_alt3::A::foo (alt/base_closure_default1_alt3.nit:20)
+| base_closure_default1_alt3::Sys::(kernel::Sys::main) (alt/base_closure_default1_alt3.nit:36)
+`------------------- - -  -
diff --git a/tests/sav/base_closure_default1_alt4.sav b/tests/sav/base_closure_default1_alt4.sav
new file mode 100644 (file)
index 0000000..0327e7a
--- /dev/null
@@ -0,0 +1,8 @@
+0
+1
+2
+3
+0
+1
+3
+0
diff --git a/tests/sav/base_closure_default1_alt5.sav b/tests/sav/base_closure_default1_alt5.sav
new file mode 100644 (file)
index 0000000..eef04b1
--- /dev/null
@@ -0,0 +1 @@
+alt/base_closure_default1_alt5.nit:26,5--15: Error: continue without value required in this bloc.
diff --git a/tests/sav/base_closure_default2.sav b/tests/sav/base_closure_default2.sav
new file mode 100644 (file)
index 0000000..861f40d
--- /dev/null
@@ -0,0 +1,9 @@
+0
+1
+2
+3
+0
+1
+20
+3
+0
diff --git a/tests/sav/base_closure_default2_alt1.sav b/tests/sav/base_closure_default2_alt1.sav
new file mode 100644 (file)
index 0000000..e8350ed
--- /dev/null
@@ -0,0 +1,7 @@
+0
+1
+2
+3
+0
+1
+0
diff --git a/tests/sav/base_closure_default2_alt2.sav b/tests/sav/base_closure_default2_alt2.sav
new file mode 100644 (file)
index 0000000..c08373d
--- /dev/null
@@ -0,0 +1 @@
+alt/base_closure_default2_alt2.nit:23,5--12: Error: Return with value in a procedure.
diff --git a/tests/sav/base_closure_default2_alt3.sav b/tests/sav/base_closure_default2_alt3.sav
new file mode 100644 (file)
index 0000000..8bf2118
--- /dev/null
@@ -0,0 +1,11 @@
+0
+1
+2
+3
+0
+1
+Aborted in base_closure_default2_alt3::A::foo (alt/base_closure_default2_alt3.nit:24)
+,---- Stack trace -- - -  -
+| base_closure_default2_alt3::A::foo (alt/base_closure_default2_alt3.nit:20)
+| base_closure_default2_alt3::Sys::(kernel::Sys::main) (alt/base_closure_default2_alt3.nit:37)
+`------------------- - -  -
diff --git a/tests/sav/base_closure_default2_alt4.sav b/tests/sav/base_closure_default2_alt4.sav
new file mode 100644 (file)
index 0000000..0327e7a
--- /dev/null
@@ -0,0 +1,8 @@
+0
+1
+2
+3
+0
+1
+3
+0
diff --git a/tests/sav/base_closure_default2_alt5.sav b/tests/sav/base_closure_default2_alt5.sav
new file mode 100644 (file)
index 0000000..42e9672
--- /dev/null
@@ -0,0 +1 @@
+alt/base_closure_default2_alt5.nit:26,5--15: Error: continue without value required in this bloc.
diff --git a/tests/sav/base_closure_default2_alt6.sav b/tests/sav/base_closure_default2_alt6.sav
new file mode 100644 (file)
index 0000000..1cb19a8
--- /dev/null
@@ -0,0 +1 @@
+alt/base_closure_default2_alt6.nit:32,3--3: Error: Method or variable 'i' unknown in A.
diff --git a/tests/sav/base_closure_default3.sav b/tests/sav/base_closure_default3.sav
new file mode 100644 (file)
index 0000000..861f40d
--- /dev/null
@@ -0,0 +1,9 @@
+0
+1
+2
+3
+0
+1
+20
+3
+0
diff --git a/tests/sav/base_closure_default3_alt1.sav b/tests/sav/base_closure_default3_alt1.sav
new file mode 100644 (file)
index 0000000..e8350ed
--- /dev/null
@@ -0,0 +1,7 @@
+0
+1
+2
+3
+0
+1
+0
diff --git a/tests/sav/base_closure_default3_alt2.sav b/tests/sav/base_closure_default3_alt2.sav
new file mode 100644 (file)
index 0000000..9ff31f3
--- /dev/null
@@ -0,0 +1 @@
+alt/base_closure_default3_alt2.nit:23,5--12: Error: Return with value in a procedure.
diff --git a/tests/sav/base_closure_default3_alt3.sav b/tests/sav/base_closure_default3_alt3.sav
new file mode 100644 (file)
index 0000000..c7a3b8e
--- /dev/null
@@ -0,0 +1,11 @@
+0
+1
+2
+3
+0
+1
+Aborted in base_closure_default3_alt3::A::foo (alt/base_closure_default3_alt3.nit:24)
+,---- Stack trace -- - -  -
+| base_closure_default3_alt3::A::foo (alt/base_closure_default3_alt3.nit:20)
+| base_closure_default3_alt3::Sys::(kernel::Sys::main) (alt/base_closure_default3_alt3.nit:35)
+`------------------- - -  -
diff --git a/tests/sav/base_closure_default3_alt4.sav b/tests/sav/base_closure_default3_alt4.sav
new file mode 100644 (file)
index 0000000..dddc0da
--- /dev/null
@@ -0,0 +1 @@
+alt/base_closure_default3_alt4.nit:25,5--12: Error: continue with a value required in this bloc.
diff --git a/tests/sav/base_closure_default3_alt5.sav b/tests/sav/base_closure_default3_alt5.sav
new file mode 100644 (file)
index 0000000..39912c2
--- /dev/null
@@ -0,0 +1 @@
+alt/base_closure_default3_alt5.nit:21,3--15: Control error: Reached end of bloc (a 'continue' with a value was expected).
diff --git a/tests/sav/base_closure_default4.sav b/tests/sav/base_closure_default4.sav
new file mode 100644 (file)
index 0000000..861f40d
--- /dev/null
@@ -0,0 +1,9 @@
+0
+1
+2
+3
+0
+1
+20
+3
+0
diff --git a/tests/sav/base_closure_default4_alt1.sav b/tests/sav/base_closure_default4_alt1.sav
new file mode 100644 (file)
index 0000000..e8350ed
--- /dev/null
@@ -0,0 +1,7 @@
+0
+1
+2
+3
+0
+1
+0
diff --git a/tests/sav/base_closure_default4_alt2.sav b/tests/sav/base_closure_default4_alt2.sav
new file mode 100644 (file)
index 0000000..5eb4ee1
--- /dev/null
@@ -0,0 +1 @@
+alt/base_closure_default4_alt2.nit:23,5--13: Error: Return with value in a procedure.
diff --git a/tests/sav/base_closure_default4_alt3.sav b/tests/sav/base_closure_default4_alt3.sav
new file mode 100644 (file)
index 0000000..d758e10
--- /dev/null
@@ -0,0 +1,11 @@
+0
+1
+2
+3
+0
+1
+Aborted in base_closure_default4_alt3::A::foo (alt/base_closure_default4_alt3.nit:24)
+,---- Stack trace -- - -  -
+| base_closure_default4_alt3::A::foo (alt/base_closure_default4_alt3.nit:20)
+| base_closure_default4_alt3::Sys::(kernel::Sys::main) (alt/base_closure_default4_alt3.nit:35)
+`------------------- - -  -
diff --git a/tests/sav/base_closure_default4_alt4.sav b/tests/sav/base_closure_default4_alt4.sav
new file mode 100644 (file)
index 0000000..ff126c2
--- /dev/null
@@ -0,0 +1 @@
+alt/base_closure_default4_alt4.nit:25,5--12: Error: continue with a value required in this bloc.
diff --git a/tests/sav/base_closure_default4_alt5.sav b/tests/sav/base_closure_default4_alt5.sav
new file mode 100644 (file)
index 0000000..5359278
--- /dev/null
@@ -0,0 +1 @@
+alt/base_closure_default4_alt5.nit:21,3--23: Control error: Reached end of bloc (a 'continue' with a value was expected).
diff --git a/tests/sav/test_map_closure_default.sav b/tests/sav/test_map_closure_default.sav
new file mode 100644 (file)
index 0000000..b0a3084
--- /dev/null
@@ -0,0 +1,12 @@
+B:
+true
+blue
+R:
+false
+red
+true
+red
+N:
+false
+black
+false
diff --git a/tests/sav/test_map_closure_default_alt1.sav b/tests/sav/test_map_closure_default_alt1.sav
new file mode 100644 (file)
index 0000000..2b8295a
--- /dev/null
@@ -0,0 +1,17 @@
+B:
+true
+blue
+R:
+false
+red
+true
+red
+N:
+false
+black
+false
+Aborted in test_map_closure_default_alt1::Map::get (alt/test_map_closure_default_alt1.nit:19)
+,---- Stack trace -- - -  -
+| test_map_closure_default_alt1::Map::get (alt/test_map_closure_default_alt1.nit:18)
+| test_map_closure_default_alt1::Sys::(kernel::Sys::main) (alt/test_map_closure_default_alt1.nit:28)
+`------------------- - -  -
diff --git a/tests/test_map_closure_default.nit b/tests/test_map_closure_default.nit
new file mode 100644 (file)
index 0000000..d6a57d6
--- /dev/null
@@ -0,0 +1,56 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2009 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.
+
+redef class Map[K, V]
+       meth get(k: K): V
+               with default: V do abort
+       do
+               if has_key(k) then return self[k]
+               var d = default
+               self[k] = d
+               return d
+       end
+end
+
+var h = new HashMap[String, String]
+h["bleu"] = "blue"
+
+print "B:"
+
+print h.has_key("bleu")
+var v = h.get("bleu") with do
+       print "Error"
+       abort
+end
+print v
+
+print "R:"
+
+print h.has_key("rouge")
+v = h.get("rouge") with do continue "red"
+print v
+print h.has_key("rouge")
+v = h.get("rouge")
+print v
+
+print "N:"
+
+print h.has_key("noir")
+v = h.get("noir") with do break "black"
+print v
+print h.has_key("noir")
+
+#alt1#v = h.get("noir")