syntax: 'meth' -> 'fun', 'attr' -> 'var'
[nit.git] / tests / base_eq.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2006-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 import kernel
18
19 class A
20 readable var _a: Int
21
22 init(a: Int)
23 do
24 _a = a
25 end
26 end
27
28 class B
29 special A
30 redef fun ==(a: nullable Object): Bool
31 do
32 if not a isa B then
33 return false
34 end
35 assert a isa B
36 return a.a is _a
37 end
38
39 init(b: Int)
40 do
41 _a = b
42 end
43 end
44
45 var a1 = new A(1)
46 var a2 = a1
47 var a3 = new A(1)
48 var b1 = new B(1)
49 var b2 = new B(1)
50 var b3 = new B(2)
51
52 a1.is_same_type(a1).output
53 a1.is_same_type(a2).output
54 a1.is_same_type(a3).output
55 (not a1.is_same_type(b1)).output
56 (not a1.is_same_type(b2)).output
57 (not a1.is_same_type(b3)).output
58 (not b1.is_same_type(a1)).output
59 (not b1.is_same_type(a2)).output
60 (not b1.is_same_type(a3)).output
61 b1.is_same_type(b1).output
62 b1.is_same_type(b2).output
63 b1.is_same_type(b2).output
64
65 '\n'.output
66
67 (a1 is a1).output
68 (a1 is a2).output
69 (not a1 is a3).output
70 (not a1 is b1).output
71 (not b1 is b2).output
72 (not b1 is b3).output
73
74 '\n'.output
75
76 (a1 == a1).output
77 (a1 == a2).output
78 (not a1 == a3).output
79 (not a1 == b1).output
80 (b1 == b1).output
81 (b1 == b2).output
82 (not b1 == b3).output
83