-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtext_object_test.go
More file actions
114 lines (99 loc) · 2.08 KB
/
text_object_test.go
File metadata and controls
114 lines (99 loc) · 2.08 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package wig
import (
"strings"
"testing"
"github.com/firstrow/wig/testutils"
"github.com/stretchr/testify/require"
)
func TestTextObjects(t *testing.T) {
return
e := NewEditor(
testutils.Viewport,
nil,
)
buf := NewBuffer()
input := "( ok )"
buf.Append(input)
cur := CursorGet(e, buf)
cur.Line = 0
cur.Char = 2
e.Buffers = append(e.Buffers, buf)
type test struct {
cursor Cursor
lines string
ch rune
include bool
found bool
expected *Selection
}
tcases := []test{
{
cursor: Cursor{Line: 0, Char: 3},
lines: "(ok)",
ch: '(',
include: true,
found: true,
expected: &Selection{
Start: Cursor{0, 0, 0, 0},
End: Cursor{0, 3, 0, 0},
},
},
{
cursor: Cursor{Line: 1, Char: 0},
lines: "ok)\n)",
ch: '(',
include: true,
found: false,
expected: nil,
},
{
cursor: Cursor{Line: 0, Char: 0},
lines: "()",
ch: '(',
include: true,
found: true,
expected: &Selection{
Start: Cursor{0, 0, 0, 0},
End: Cursor{0, 1, 0, 0},
},
},
{
cursor: Cursor{Line: 0, Char: 0},
lines: "()",
ch: '(',
include: false,
found: true,
expected: nil,
},
{
cursor: Cursor{Line: 0, Char: 6},
lines: "( ( ) )",
ch: '(',
include: false,
found: true,
expected: &Selection{
Start: Cursor{0, 1, 0, 0},
End: Cursor{0, 6, 0, 0},
},
},
}
for _, c := range tcases {
buf.ResetLines()
lines := strings.Split(c.lines, "\n")
for _, line := range lines {
buf.Append(line)
}
require.Equal(t, c.lines, buf.String())
cur := c.cursor
found, sel, _ := TextObjectBlock(buf, c.ch, c.include)
require.Equal(t, c.found, found, c)
require.Equal(t, c.cursor.Char, cur.Char)
require.Equal(t, c.cursor.Line, cur.Line)
if found && c.expected != nil {
require.Equal(t, c.expected.Start.Line, sel.Start.Line, c)
require.Equal(t, c.expected.Start.Char, sel.Start.Char, c)
require.Equal(t, c.expected.End.Line, sel.End.Line, c)
require.Equal(t, c.expected.End.Char, sel.End.Char, c)
}
}
}