forked from go-python/cpy3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_test.go
68 lines (44 loc) · 1.33 KB
/
list_test.go
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
package python3
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestList(t *testing.T) {
Py_Initialize()
list := PyList_New(0)
assert.True(t, PyList_Check(list))
assert.True(t, PyList_CheckExact(list))
defer list.DecRef()
s := PyUnicode_FromString("hello")
assert.NotNil(t, s)
i := PyLong_FromGoInt(123)
assert.NotNil(t, i)
f := PyFloat_FromDouble(123.4)
assert.NotNil(t, f)
assert.Zero(t, PyList_Append(list, i))
assert.Zero(t, PyList_Insert(list, 0, s))
assert.Equal(t, 2, PyList_Size(list))
assert.Zero(t, PyList_SetItem(list, 0, f))
assert.Equal(t, f, PyList_GetItem(list, 0))
assert.Zero(t, PyList_Sort(list))
assert.Equal(t, i, PyList_GetItem(list, 0))
assert.Zero(t, PyList_Reverse(list))
assert.Equal(t, f, PyList_GetItem(list, 0))
s = PyUnicode_FromString("world")
assert.NotNil(t, s)
list2 := PyList_New(1)
defer list2.DecRef()
assert.Zero(t, PyList_SetItem(list2, 0, s))
assert.Zero(t, PyList_SetSlice(list, 0, 1, list2))
list3 := PyList_GetSlice(list, 0, 1)
assert.NotNil(t, list3)
defer list3.DecRef()
assert.Equal(t, 1, list2.RichCompareBool(list3, Py_EQ))
tuple := PyList_AsTuple(list)
assert.NotNil(t, tuple)
defer tuple.DecRef()
world := PyTuple_GetItem(tuple, 0)
assert.NotNil(t, world)
assert.Equal(t, "world", PyUnicode_AsUTF8(world))
PyList_ClearFreeList()
}