model: introduce `name` in MEntity according to it's documentation
[nit.git] / tests / base_at_cached.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 class Base
18 var foo: Int = 10
19 fun -: Int do return foo + 20
20 fun bar: Int do return -self + 40
21 end
22
23 class CMinus
24 super Base
25
26 redef fun - is cached do return foo + 1
27 end
28
29 class CBar
30 super Base
31
32 redef fun bar is cached do return -self + 2
33 end
34
35 fun test(b: Base)
36 do
37 b.foo.output
38 (-b).output
39 b.bar.output
40 b.foo = 110
41 b.foo.output
42 (-b).output
43 b.bar.output
44 '\n'.output
45 end
46
47 test(new Base)
48 test(new CMinus)
49 test(new CBar)