-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadap_go_test.go
60 lines (54 loc) · 1.17 KB
/
adap_go_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
package gp
import (
"testing"
)
func TestAllocCStr(t *testing.T) {
setupTest(t)
tests := []struct {
name string
input string
want string
}{
{"empty string", "", ""},
{"ascii string", "hello", "hello"},
{"unicode string", "hello 世界", "hello 世界"},
}
for _, tt := range tests {
cstr := AllocCStr(tt.input)
got := GoString(cstr)
if got != tt.want {
t.Errorf("AllocCStr() = %v, want %v", got, tt.want)
}
}
}
func TestGoStringN(t *testing.T) {
setupTest(t)
tests := []struct {
name string
input string
n int
want string
}{
{"empty string", "", 0, ""},
{"partial string", "hello", 3, "hel"},
{"full string", "hello", 5, "hello"},
{"unicode partial", "hello 世界", 6, "hello "},
{"unicode full", "hello 世界", 12, "hello 世界"},
}
for _, tt := range tests {
cstr := AllocCStr(tt.input)
got := GoStringN(cstr, tt.n)
if got != tt.want {
t.Errorf("GoStringN() = %v, want %v", got, tt.want)
}
}
}
func TestAllocCStrDontFree(t *testing.T) {
setupTest(t)
input := "test string"
cstr := AllocCStrDontFree(input)
got := GoString(cstr)
if got != input {
t.Errorf("AllocCStrDontFree() = %v, want %v", got, input)
}
}