-
Notifications
You must be signed in to change notification settings - Fork 0
/
tuple_test.v
62 lines (50 loc) · 1.14 KB
/
tuple_test.v
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
module py
fn testsuite_begin() {
C.Py_Initialize()
}
fn testsuite_end() {
}
fn test_tuple_check() {
t := C.PyTuple_New(3)
assert C.PyTuple_Check(t) == 1
assert C.PyTuple_CheckExact(t) == 1
C.Py_XDECREF(t)
}
fn test_tuple_size() {
size := 3
t := C.PyTuple_New(size)
assert int(C.PyTuple_Size(t)) == size
C.Py_XDECREF(t)
}
fn test_tuple_get_set() {
t := C.PyTuple_New(3)
set_0 := C.PyLong_FromLong(42)
set_1 := C.PyBool_FromLong(1)
C.PyTuple_SetItem(t, 0, set_0)
C.PyTuple_SetItem(t, 1, set_1)
get_0 := C.PyTuple_GetItem(t, 0)
get_1 := C.PyTuple_GetItem(t, 1)
assert get_0.ptr() == set_0.ptr()
assert get_1.ptr() == set_1.ptr()
C.Py_XDECREF(t)
}
fn test_tuple_slice() {
t := C.PyTuple_New(3)
items := [
C.PyBool_FromLong(0),
C.PyLong_FromLong(42),
C.PyBool_FromLong(1)
]
for i in 0..3 {
C.PyTuple_SetItem(t, i, items[i])
}
s := C.PyTuple_GetSlice(t, 1, 3)
assert C.PyTuple_Check(s) == 1
first := C.PyTuple_GetItem(s, 0)
assert C.PyLong_Check(first) == 1
v := C.PyLong_AsLong(first)
assert v == 42
C.Py_XDECREF(first)
C.Py_XDECREF(s)
C.Py_XDECREF(t)
}