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