forked from inkyblackness/imgui-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WrapperConverter_test.go
65 lines (59 loc) · 1.55 KB
/
WrapperConverter_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
package imgui // nolint: testpackage
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestStringBufferAllocation(t *testing.T) {
tt := []struct {
initialValue string
expectedSize int
}{
{initialValue: "", expectedSize: 1},
{initialValue: "a", expectedSize: 2},
{initialValue: "123456789", expectedSize: 10},
}
for _, tc := range tt {
td := tc
t.Run(fmt.Sprintf("<%s>", td.initialValue), func(t *testing.T) {
buf := newStringBuffer(td.initialValue)
defer buf.free()
assert.Equal(t, td.expectedSize, buf.size)
})
}
}
func TestStringBufferStorage(t *testing.T) {
tt := []string{"", "a", "ab", "SomeLongerText"}
for _, tc := range tt {
td := tc
t.Run("Value <"+td+">", func(t *testing.T) {
buf := newStringBuffer(td)
require.NotNil(t, buf, "buffer expected")
defer buf.free()
result := buf.toGo()
assert.Equal(t, td, result)
})
}
}
func TestStringBufferResize(t *testing.T) {
tt := []struct {
initialValue string
newSize int
expectedValue string
}{
{initialValue: "", newSize: 10, expectedValue: ""},
{initialValue: "abcd", newSize: 10, expectedValue: "abcd"},
{initialValue: "abcd", newSize: 3, expectedValue: "ab"},
{initialValue: "efgh", newSize: 0, expectedValue: ""},
}
for _, tc := range tt {
td := tc
t.Run(fmt.Sprintf("<%s> -> %d", td.initialValue, tc.newSize), func(t *testing.T) {
buf := newStringBuffer(td.initialValue)
defer buf.free()
buf.resizeTo(td.newSize)
assert.Equal(t, td.expectedValue, buf.toGo())
})
}
}