First NIT release and new clean mercurial repository
[nit.git] / tests / test_gen.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 Toto[E]
19 attr _item: E
20 meth set(e: E)
21 do _item = e end
22 meth get: E
23 do return _item end
24 redef meth to_s: String
25 do return _item.to_s end
26
27 init do end
28 end
29
30 class TestNative
31 special ArrayCapable[Int]
32
33 init
34 do
35 var a: Array[Int]
36 var b: NativeArray[Int]
37 var u: Object
38 a = [10, 20, 30]
39 a[1] = 2
40 print(a[0])
41 print(a[1])
42 b = calloc_array(5)
43 b[0]=200
44 b[1]=300
45 print(b[0])
46 print(b[1])
47 end
48 end
49
50
51
52 meth test_toto
53 do
54 var t = new Toto[Int]
55 t.set(5)
56 print(t)
57 end
58
59 meth test_array
60 do
61 var a = new Array[Int].with_capacity(3)
62 a.add(1)
63 a.add(2)
64 a.add(3)
65 a.add(4)
66 a.add(5)
67 print(a[0])
68 print(a)
69 var i = a.iterator
70 while i.is_ok do
71 print(i.index)
72 print(i.item)
73 i.next
74 end
75 end
76
77 test_toto
78 print("-")
79 var n = new TestNative
80 print("-")
81 test_array