/
nativeinterop.b17
100 lines (83 loc) · 3.3 KB
/
nativeinterop.b17
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
module lang.unittest.spec.nativeinterop
if native Platform == Java then
val h_class = native Class "com.babel17.java.JavaInteropUnittestHelper"
#assert h_class.getCanonicalName () == "com.babel17.java.JavaInteropUnittestHelper"
val h = native New (h_class,
"hello world", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
val g = native New ("com.babel17.java.JavaInteropUnittestHelper",
"hello world", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
#assert h.msg () == g.msg ()
#assert h <> g
#assert h.getClass () == h_class
#assert h.a == 2
#assert h.msg <> "hello world"
#assert h.msg () == "hello world"
#catch DomainError try: h.msg ("another param",)
#catch DomainError try: h.msg "another param"
#assert h.pick (4, 6, 8) == (5, 7, 9)
#assert h.pick [] == ()
#assert h.pick () == []
#assert h.pick () == ()
#assert h.pick 5 <> 6
#assert h.pick 5 == (6,)
#assert h.b <> 2
#assert h.b () == 3
#assert h.nothing () == nil
def test_num (f, numbits, signed, limited) =
begin
val g = f h
val bits = numbits - 1
val maxnum = if signed then 2^bits - 1 else 2^numbits-1 end
val minnum = if signed then -2^bits else 0 end
#assert g maxnum == maxnum
#assert g minnum == minnum
if (limited) then
#catch DomainError try: g (maxnum+1) == maxnum+1
#catch DomainError try: g (minnum-1) == minnum-1
end
end
def test_num (f, numbits) = test_num (f, numbits, true, true)
test_num (h => h.id_byte, 8)
test_num (h => h.id_short, 16)
test_num (h => h.id_int, 32)
test_num (h => h.id_long, 64)
test_num (h => h.id_bigint, 1024, true, false)
test_num (h => h.id_char, 16, false, true)
#assert h.id_char " " == 32
#assert h.nil_string "blub" == nil
#catch DomainError try: h.id_int nil
#assert h.id_integer nil == h.id_bigint nil == nil
#assert h.id_bigint 5 == h.id_int 5 == h.id_integer 5 == 5
#assert h.id_boolean true == (not h.id_boolean false) == true
#assert h.inner.q == 12
begin
val d = h.inner.direction
#assert d.north <> d.south
#assert d.north == d.north
#assert
match d.north
case val d.south => false
case val d.north => true
end
begin
val i = 0
for direction in d.values () do
#assert direction.ordinal () == i
i = i + 1
end
end
#assert d.valueof "SOUTH" == d.south
end
#catch NativeError(RuntimeException s) if
s.contains "crash, please catch it"
try: h.crash ()
#assert h.ambi_int nil == "Integer: null"
#assert h.ambi_int 2 == "Integer: 2"
#assert h.test_a () == "test_a"
#assert h.test_A () == "test_a"
#assert h.a_mul 7 == 7 * h.a
#assert h_class.a_mul 7 == 7 * h_class.a
else
#assert false
end
end