Merge: doc: fixed some typos and other misc. corrections
[nit.git] / tests / base_arg_default_autoinit.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 core::kernel
16
17 class A
18 var mandatory: Int
19 var optional: nullable Int
20
21 fun foo
22 do
23 '-'.output
24 '\n'.output
25 mandatory.output
26 if optional == null then
27 ' '.output
28 '\n'.output
29 else
30 optional.output
31 end
32 end
33 end
34
35 class B
36 super A
37 var optional_b: nullable Int
38 var mandatory_b: Int
39 redef fun foo
40 do
41 super
42 if optional_b == null then
43 ' '.output
44 '\n'.output
45 else
46 optional_b.output
47 end
48 mandatory_b.output
49 end
50 end
51
52 class C
53 super B
54 autoinit optional_b, mandatory_b, mandatory
55 end
56
57 var a
58
59 #alt1#a = new A
60 #alt1#a.foo
61
62 a = new A(1)
63 a.foo
64
65 a = new A(1,2)
66 a.foo
67
68 #alt1#a = new A(1,2,3)
69 #alt1#a.foo
70
71 #alt1#a = new B(1)
72 #alt1#a.foo
73
74 #alt1#a = new B(1,4)
75 #alt1#a.foo
76
77 #alt1#a = new B(1,2,4)
78 #alt1#a.foo
79
80 a = new B(1,2,3,4)
81 a.foo
82
83 #alt1#a = new B(1,2,3,4,5)
84 #alt1#a.foo
85
86 #alt1#a = new C(1)
87 #alt1#a.foo
88
89 #alt1#a = new C(4,1)
90 #alt1#a.foo
91
92 a = new C(3,4,1)
93 a.foo
94
95 #alt1#a = new C(1,2,3,4)
96 #alt1#a.foo