-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtest_java_lang.nim
60 lines (52 loc) · 1.64 KB
/
test_java_lang.nim
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
import ../jnim,
../jnim/java/lang,
common,
unittest,
encodings
suite "javaapi.core":
setup:
if not isJNIThreadInitialized():
initJNIForTests()
test "java.lang.Object":
let o1 = Object.new
let o2 = Object.new
check: not o1.toString.equals(o2.toString)
check: not o1.equals(o2)
check: o1.getClass.equals(o2.getClass)
test "java.lang.String":
let s1 = String.new("Hi")
let s2 = String.new("Hi")
let s3 = String.new("Hello")
# Check inheritance
check: s1 of String
check: s1 of Object
# Check operations
check: $s1 == "Hi"
check: s1.equals(s2)
check: not s2.equals(s3)
let s = String.new("Привет!")
check: String.new(s.getBytes("CP1251"), "CP1251") == s
jclass ExceptionTestClass of Object:
proc throwEx(msg: string) {.`static`.}
test "java.lang.Exception":
expect(JavaException):
ExceptionTestClass.throwEx("test")
try:
ExceptionTestClass.throwEx("test")
except JavaException:
let ex = getCurrentJVMException()
check: ex.getStackTrace.len == 1
test "java.lang - Numbers":
check: Byte.MIN_VALUE == low(int8)
check: Byte.MAX_VALUE == high(int8)
check: Byte.SIZE == 8
check: $Byte.TYPE == "byte"
check: Byte.new(100).byteValue == Byte.new("100").byteValue
expect JavaException:
discard Byte.new("1000")
check: Short.MIN_VALUE == low(int16)
check: Short.MAX_VALUE == high(int16)
check: Integer.new(1) == Integer.new(1)
test "java.lang - Booleans":
check: Boolean.new(JVM_TRUE).booleanValue == JVM_TRUE
check: Boolean.new(JVM_FALSE).booleanValue == JVM_FALSE