-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtextbox_test.go
76 lines (63 loc) · 1.54 KB
/
textbox_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
69
70
71
72
73
74
75
76
package glmenu
import (
"github.com/4ydx/gltext"
"github.com/4ydx/gltext/v4.1"
"github.com/go-gl/gl/v4.1-core/gl"
"github.com/go-gl/glfw/v3.2/glfw"
"runtime"
"testing"
)
var window *glfw.Window
func openGLContext() {
useStrictCoreProfile := (runtime.GOOS == "darwin")
runtime.LockOSThread()
err := glfw.Init()
if err != nil {
panic("glfw error")
}
defer glfw.Terminate()
glfw.WindowHint(glfw.Resizable, glfw.False)
glfw.WindowHint(glfw.ContextVersionMajor, 3)
glfw.WindowHint(glfw.ContextVersionMinor, 3)
if useStrictCoreProfile {
glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)
glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
}
glfw.WindowHint(glfw.OpenGLDebugContext, glfw.True)
window, err = glfw.CreateWindow(640, 480, "Testing", nil, nil)
if err != nil {
panic(err)
}
window.MakeContextCurrent()
if err := gl.Init(); err != nil {
panic(err)
}
}
func TestTextBoxBackspace(t *testing.T) {
openGLContext()
tb := TextBox{}
f := &v41.Font{}
f.Config = &gltext.FontConfig{}
text := &v41.Text{}
text.Font = f
text.SetString("testing")
tb.Text = text
text = &v41.Text{}
text.Font = f
text.SetString("|")
tb.Cursor = text
tb.CursorIndex = 1
tb.Backspace()
if text.String != "esting" && tb.CursorIndex != 0 {
t.Error(tb.Text.String, tb.CursorIndex)
}
tb.CursorIndex = 6
tb.Backspace()
if text.String != "estin" && tb.CursorIndex != 5 {
t.Error(tb.Text.String, tb.CursorIndex)
}
tb.Backspace()
if text.String != "esti" && tb.CursorIndex != 4 {
t.Error(tb.Text.String, tb.CursorIndex)
}
}