tests: adds native interface tests
[nit.git] / tests / test_ni_operators.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2011 Alexis Laferrière <alexis.laf@xymus.net>
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 var value : Int
20
21 init ( value : Int ) do self.value = value
22
23 fun +( other : A ) : A is extern import value, A
24
25 fun -( other : A ) : A is extern import value, A
26
27 fun *( by : Int ) : A is extern import value, A
28
29 fun /( by : Int ) : A is extern import value, A
30
31 redef fun ==( other ) is extern import value, nullable Object as(A)
32
33 fun %( other : A ) : A is extern import value, A
34
35 # fun +=( other : A ) : A is extern import value, value=, A `{
36 # int new_val = A_value( recv ) + A_value( other );
37 # A_value__assign( recv, new_val );
38 # return new_A( new_val );
39 # `}
40
41 # fun -=( other : A ) : A is extern import +=, A, value `{
42 # A inv_other = new_A( -1*A_value( other ) );
43 # return A__plus_equal( recv, int_other );
44 # `}
45
46 fun <=>( other : A ) : A is extern import value, A
47
48 # fun @( other : A ) : A is extern import value, A `{
49 # return new_A( A_value( recv )* 1000 );
50 # `}
51
52 fun >( other : A ) : Bool is extern import value
53
54 fun <( other : A ) : Bool is extern import value
55
56 fun >=( other : A ) : Bool is extern import value
57
58 fun <=( other : A ) : Bool is extern import value
59
60 fun >>( other : A ) is extern import value, value=, A
61
62 fun <<( other : A ) is extern import value, A
63
64 fun []( index : Int ) : A is extern import A
65
66 fun []=( index : Int, value : A ) : A is extern import A
67
68 redef fun to_s do return value.to_s
69 end
70
71 print new A( 1 ) + new A( 10 ) # 11
72 print new A( 10 ) - new A( 1 ) # 9
73
74 print new A( 2 ) * 11 # 22
75 print new A( 33 ) / 11 # 3
76
77 print new A( 44 ) == null # false
78 print new A( 55 ) == 55 # false
79 print new A( 33 ) == new A( 11 ) # false
80 print new A( 22 ) == new A( 77 ) # false
81 print new A( 11 ) == new A( 11 ) # true
82
83 print new A( 147 ) % new A( 12 ) # 3
84 print new A( 4 ) <=> new A( 123 ) # 4096
85
86 print new A( 1 ) < new A( 100 ) # true
87 print new A( 100 ) < new A( 100 ) # false
88 print new A( 100 ) < new A( 1 ) # false
89
90 print new A( 1 ) > new A( 100 ) # false
91 print new A( 100 ) > new A( 100 ) # false
92 print new A( 100 ) > new A( 1 ) # true
93
94 print new A( 1 ) <= new A( 100 ) # true
95 print new A( 100 ) <= new A( 100 ) # true
96 print new A( 100 ) <= new A( 1 ) # false
97
98 print new A( 1 ) >= new A( 100 ) # false
99 print new A( 100 ) >= new A( 100 ) # true
100 print new A( 100 ) >= new A( 1 ) # true
101
102 #var x = new A( 1 )
103 #x << new A( 5 )
104 #print x # 16
105
106 #var y = new A( 32 )
107 #y >> new A( 2 )
108 #print y # 8
109
110 var a = new A( 456 )
111 print a[ 52 ] # 52
112
113 a[ 74 ] = new A( 96 )
114 print a # 96