-
Notifications
You must be signed in to change notification settings - Fork 0
/
buffer_test.go
114 lines (108 loc) · 2.82 KB
/
buffer_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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetSelection(t *testing.T) {
testData := map[string]struct {
buf *buffer
expectedLowerY int
expectedLowerX int
expectedHigherY int
expectedHigherX int
}{
"simple": {
buf: &buffer{startY: 0, startX: 23, endY: 3, endX: 42},
expectedLowerY: 0,
expectedLowerX: 23,
expectedHigherY: 3,
expectedHigherX: 42,
},
"reversed": {
buf: &buffer{startY: 3, startX: 23, endY: 0, endX: 42},
expectedLowerY: 0,
expectedLowerX: 42,
expectedHigherY: 3,
expectedHigherX: 23,
},
"same-line-reversed": {
buf: &buffer{startY: 0, startX: 15, endY: 0, endX: 3},
expectedLowerY: 0,
expectedLowerX: 3,
expectedHigherY: 0,
expectedHigherX: 15,
},
}
for testName, tt := range testData {
t.Run(testName, func(t *testing.T) {
lowerY, lowerX, higherY, higherX := tt.buf.getSelection()
assert.Equal(t, tt.expectedLowerY, lowerY)
assert.Equal(t, tt.expectedLowerX, lowerX)
assert.Equal(t, tt.expectedHigherY, higherY)
assert.Equal(t, tt.expectedHigherX, higherX)
})
}
}
func TestIsWithinSelectedText(t *testing.T) {
testData := map[string]struct {
buf *buffer
y int
x int
expectedResult bool
}{
"simple": {
buf: &buffer{startY: 1, startX: 5, endY: 3, endX: 10},
y: 2,
x: 3,
expectedResult: true,
},
"simple-first-line": {
buf: &buffer{startY: 1, startX: 5, endY: 3, endX: 10},
y: 1,
x: 10,
expectedResult: true,
},
"simple-last-line": {
buf: &buffer{startY: 1, startX: 5, endY: 3, endX: 10},
y: 3,
x: 7,
expectedResult: true,
},
"outside-first-line": {
buf: &buffer{startY: 1, startX: 5, endY: 3, endX: 10},
y: 1,
x: 0,
expectedResult: false,
},
"outside-last-line": {
buf: &buffer{startY: 1, startX: 5, endY: 3, endX: 10},
y: 3,
x: 20,
expectedResult: false,
},
"outside-before-first-line": {
buf: &buffer{startY: 1, startX: 5, endY: 3, endX: 10},
y: 0,
x: 20,
expectedResult: false,
},
"outside-after-last-line": {
buf: &buffer{startY: 1, startX: 5, endY: 3, endX: 10},
y: 5,
x: 3,
expectedResult: false,
},
"empty-selection": {
buf: &buffer{startY: 1, startX: 5, endY: 1, endX: 5},
y: 1,
x: 5,
expectedResult: false,
},
}
for testName, tt := range testData {
t.Run(testName, func(t *testing.T) {
result := tt.buf.isWithinSelectedText(tt.y, tt.x)
assert.Equal(t, tt.expectedResult, result)
})
}
}