tests: add base_as_cast
[nit.git] / tests / base_as_cast.nit
diff --git a/tests/base_as_cast.nit b/tests/base_as_cast.nit
new file mode 100644 (file)
index 0000000..a93c628
--- /dev/null
@@ -0,0 +1,59 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2005-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 kernel
+
+class O
+       redef meth output do 0.output
+end
+
+class A
+special O
+       init do end
+end
+
+class U
+       redef meth output do 1.output
+end
+
+class B
+special A
+special U
+       redef meth output do 2.output
+       init do end
+end
+
+var a: Object = new A
+var b: Object = new B
+
+a.as(Object).output
+a.as(O).output
+a.as(A).output
+#alt1#a.as(U).output
+#alt2#a.as(B).output
+#alt3#a.as(Int).output
+#alt4#a.as(Comparable).output
+
+'\n'.output
+
+b.as(Object).output
+b.as(O).output
+b.as(A).output
+b.as(U).output
+b.as(B).output
+#alt5#b.as(Int).output
+#alt6#b.as(Comparable).output
+