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
|
package ui
import "testing"
func TestDeleteWord(t *testing.T) {
tests := []struct {
name string
text string
expected string
}{
{
name: "hello-world",
text: "hello world",
expected: "hello ",
},
{
name: "empty",
text: "",
expected: "",
},
{
name: "quoted",
text: `"hello"`,
expected: `"hello`,
},
{
name: "hello-and-space",
text: "hello ",
expected: "",
},
{
name: "space-and-hello",
text: " hello",
expected: " ",
},
{
name: "only-quote",
text: `"`,
expected: "",
},
{
name: "only-space",
text: " ",
expected: "",
},
{
name: "space-and-quoted",
text: " 'hello",
expected: " '",
},
{
name: "paths",
text: "foo/bar/baz",
expected: "foo/bar/",
},
{
name: "space-and-paths",
text: " /foo",
expected: " /",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
textinput := NewTextInput(test.text, nil)
textinput.deleteWord()
if string(textinput.text) != test.expected {
t.Errorf("word was deleted incorrectly: got %s but expected %s", string(textinput.text), test.expected)
}
})
}
}
|