Merge: doc: fixed some typos and other misc. corrections
[nit.git] / tests / base_new.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 interface A
18 new do return new B(1)
19 new n2 do return new B(2)
20 new n3: B do return new B(3)
21 new n4: Int do return 4
22 new n5: Int do return new B.ni(5)
23 #alt1#new n do return 5
24 #alt2#new n do 0.output
25 #alt3#new n do return self
26 #alt4#new n: Int do return object_id
27 end
28
29 class B
30 super A
31 var i: Int
32 redef fun output do
33 'B'.output
34 i.output
35 end
36 new n2 do return new B(22)
37 new n3: B do return new B(33)
38 new n4: Int do return 44
39 new n5: Int do return new B.ni(55)
40 new ni(i: Int): Int do return i*10
41 end
42
43 class C
44 super B
45 new(i: Int): B do return new B(i)
46 redef fun output do
47 'C'.output
48 i.output
49 end
50 end
51
52 class D
53 super C
54 new(z: Bool): B do return new C(1111)
55 end
56
57 redef class Int
58 new z do return 0
59 new a: A do return new A
60 end
61
62 (new A).output
63 #alt5#(new A).i.output
64 (new A.n2).output
65 #alt6#(new A.n2).i.output
66 (new A.n3).i.output
67 (new A.n4).output
68 (new A.n5).output
69 #alt1-4#(new A.n).output
70
71 '\n'.output
72
73 (new B(11)).output
74 (new B.n2).i.output
75 (new B.n3).i.output
76 (new B.n4).output
77 (new B.n5).output
78 (new B.ni(66)).output
79
80 '\n'.output
81
82 (new C(111)).output
83 #alt7#(new C.n2).output
84
85 '\n'.output
86
87 (new D(true)).output
88
89 '\n'.output
90
91 #alt8#(new Int).output
92 (new Int.z).output
93 (new Int.a).output