syntax: 'meth' -> 'fun', 'attr' -> 'var'
[nit.git] / tests / test_operators.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2004-2008 Jean Privat <jean@pryen.org>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17
18 class A
19 fun +(a: A): A
20 do
21 2.output
22 return self
23 end
24 fun -: A
25 do
26 1.output
27 return self
28 end
29 fun -(a: A): A
30 do
31 6.output
32 return self
33 end
34 fun *(a: A): A
35 do
36 3.output
37 return self
38 end
39 fun /(a: A): A
40 do
41 4.output
42 return self
43 end
44 fun %(a: A): A
45 do
46 5.output
47 return self
48 end
49 redef fun ==(a: nullable Object): Bool
50 do
51 7.output
52 return true
53 end
54 fun <(a: A): Bool
55 do
56 9.output
57 return true
58 end
59 fun >(a: A): Bool
60 do
61 10.output
62 return true
63 end
64 fun <=(a: A): Bool
65 do
66 11.output
67 return true
68 end
69 fun >=(a: A): Bool
70 do
71 12.output
72 return true
73 end
74 fun <=>(a: A): Int
75 do
76 13.output
77 return 0
78 end
79
80 init do end
81 end
82
83 var a = new A
84 var a2 = new A
85 var b : Bool
86 var i: Int
87 a = a + -a - a * a / a % a
88 b = a == a2 and a < a and a > a and a <= a and a >= a
89 i = a <=> a