tests: add base_formal_isa
[nit.git] / tests / base_formal_isa.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 import kernel
16
17 class A[T]
18 fun isa_gtno(x: Object): Bool do return x isa G[T, Bool]
19 end
20
21 class G[E, F]
22 fun new_ae: A[nullable Object] do return new A[E]
23 fun new_gafgaaenae: G[nullable Object, nullable Object] do return new G[A[F],G[A[A[E]],nullable A[E]]]
24 fun isa_af(x: Object): Bool
25 do
26 return x isa A[F]
27 end
28 end
29
30 var gib = new G[Int, Bool]
31
32 var gib_ae = gib.new_ae
33 gib_ae.output_class_name
34 (gib_ae isa A[Object]).output
35 (gib_ae isa A[Int]).output
36 (not gib_ae isa A[Bool]).output
37
38 '\n'.output
39
40 var gib_x = gib.new_gafgaaenae
41 gib_x.output_class_name
42 (gib_x isa G[Object, Object]).output
43 (gib_x isa G[A[Object], G[nullable A[Object], nullable Object]]).output
44 (not gib_x isa G[A[Object], G[nullable A[Object], Object]]).output
45 (gib_x isa G[A[Bool],G[A[A[Int]],nullable A[Int]]]).output
46 (not gib_x isa G[A[Bool],G[A[A[Bool]],nullable A[Int]]]).output
47
48 '\n'.output
49
50 var gbi = new G[Bool, Int]
51 gbi.output_class_name
52 var gbi_ae = gbi.new_ae
53 gbi_ae.output_class_name
54 (not gib.isa_af(gib_ae)).output
55 (gib.isa_af(gbi_ae)).output
56 (gib_ae.isa_gtno(gib)).output
57 (not gib_ae.isa_gtno(gib_x)).output
58 (not gib_ae.isa_gtno(gbi)).output
59 (not gib_x.isa_af(gib_ae)).output
60 (not gib_x.isa_af(gbi_ae)).output
61 (gbi.isa_af(gib_ae)).output
62 (not gbi.isa_af(gbi_ae)).output