-
Notifications
You must be signed in to change notification settings - Fork 25
/
text_edit_test.go
91 lines (76 loc) · 1.3 KB
/
text_edit_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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package wui
import (
"strings"
"testing"
"github.com/gonutz/check"
)
func extractCursor(s string) (string, int) {
cursor := strings.Index(s, "|")
s = strings.Replace(s, "|", "", 1)
return s, cursor
}
func TestExtractCursor(t *testing.T) {
var s string
var cursor int
s, cursor = extractCursor("|")
check.Eq(t, s, "")
check.Eq(t, cursor, 0)
s, cursor = extractCursor("abc|")
check.Eq(t, s, "abc")
check.Eq(t, cursor, 3)
s, cursor = extractCursor("abc|def")
check.Eq(t, s, "abcdef")
check.Eq(t, cursor, 3)
}
func TestDeleteLastWordAtCursor(t *testing.T) {
del := func(have, want string) {
have, haveCursor := extractCursor(have)
want, wantCursor := extractCursor(want)
got, gotCursor := deleteWordBeforeCursor([]rune(have), haveCursor)
check.Eq(t, got, want)
check.Eq(t, gotCursor, wantCursor)
}
del("|", "|")
del("a|", "|")
del("ab|", "|")
del("abc|", "|")
del("abc |", "|")
del("abc |", "|")
del(" |", "|")
del(" |", "|")
del(
"abc def|",
"abc |",
)
del(
"abc de|f",
"abc |f",
)
del(
"abc d|ef",
"abc |ef",
)
del(
"abc |def",
"|def",
)
del(
"abc| def",
"| def",
)
del(
"ab|c def",
"|c def",
)
del(
"a|bc def",
"|bc def",
)
del(
"|abc def",
"|abc def",
)
del("a b \t |", "a |")
del("\r\n|", "|")
del("\r\n\r\n|", "\r\n|")
}