Merge: doc: fixed some typos and other misc. corrections
[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 isa_af(x: Object): Bool
24 do
25 return x isa A[F]
26 end
27 end
28
29 class H[E, F]
30 fun new_gafgaaenae: G[nullable Object, nullable Object] do return new G[A[F],G[A[A[E]],nullable A[E]]]
31 end
32
33 var gib = new G[Int, Bool]
34
35 var gib_ae = gib.new_ae
36 gib_ae.output_class_name
37 (gib_ae isa A[Object]).output
38 (gib_ae isa A[Int]).output
39 (not gib_ae isa A[Bool]).output
40
41 '\n'.output
42
43 var hib = new H[Int, Bool]
44 var gib_x = hib.new_gafgaaenae
45 gib_x.output_class_name
46 (gib_x isa G[Object, Object]).output
47 (gib_x isa G[A[Object], G[nullable A[Object], nullable Object]]).output
48 (not gib_x isa G[A[Object], G[nullable A[Object], Object]]).output
49 (gib_x isa G[A[Bool],G[A[A[Int]],nullable A[Int]]]).output
50 (not gib_x isa G[A[Bool],G[A[A[Bool]],nullable A[Int]]]).output
51
52 '\n'.output
53
54 var gbi = new G[Bool, Int]
55 gbi.output_class_name
56 var gbi_ae = gbi.new_ae
57 gbi_ae.output_class_name
58 (not gib.isa_af(gib_ae)).output
59 (gib.isa_af(gbi_ae)).output
60 (gib_ae.isa_gtno(gib)).output
61 (not gib_ae.isa_gtno(gib_x)).output
62 (not gib_ae.isa_gtno(gbi)).output
63 (not gib_x.isa_af(gib_ae)).output
64 (not gib_x.isa_af(gbi_ae)).output
65 (gbi.isa_af(gib_ae)).output
66 (not gbi.isa_af(gbi_ae)).output