-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathselection_test.go
More file actions
46 lines (37 loc) · 1.82 KB
/
selection_test.go
File metadata and controls
46 lines (37 loc) · 1.82 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
package wig
import (
"testing"
"github.com/firstrow/wig/testutils"
"github.com/stretchr/testify/assert"
)
func TestSelectionCursorInRange(t *testing.T) {
tests := []struct {
sel Selection
c Cursor
want bool
}{
{sel: Selection{Start: Cursor{Line: 1, Char: 10}, End: Cursor{Line: 2, Char: 20}}, c: Cursor{Line: 1, Char: 10}, want: true},
{sel: Selection{Start: Cursor{Line: 1, Char: 10}, End: Cursor{Line: 2, Char: 20}}, c: Cursor{Line: 2, Char: 20}, want: true},
{sel: Selection{Start: Cursor{Line: 1, Char: 10}, End: Cursor{Line: 2, Char: 20}}, c: Cursor{Line: 0, Char: 0}, want: false},
{sel: Selection{Start: Cursor{Line: 1, Char: 10}, End: Cursor{Line: 2, Char: 20}}, c: Cursor{Line: 3, Char: 30}, want: false},
{sel: Selection{Start: Cursor{Line: 1, Char: 10}, End: Cursor{Line: 2, Char: 20}}, c: Cursor{Line: 1, Char: 25}, want: true},
{sel: Selection{Start: Cursor{Line: 1, Char: 10}, End: Cursor{Line: 2, Char: 20}}, c: Cursor{Line: 2, Char: 15}, want: true},
}
for _, tt := range tests {
if got := SelectionCursorInRange(&tt.sel, tt.c); got != tt.want {
t.Errorf("SelectionCursorInRange(%v, %v) = %t, want %t", tt.sel, tt.c, got, tt.want)
}
}
}
func TestSelectionToString(t *testing.T) {
buf, err := BufferReadFile(testutils.Filepath("buffer_test.txt"))
if err != nil {
t.Errorf("expected nil, got %v", err)
}
buf.Selection = &Selection{Start: Cursor{Line: 2, Char: 1}, End: Cursor{Line: 2, Char: 8}}
assert.Equal(t, "ine thre", SelectionToString(buf, buf.Selection))
buf.Selection = &Selection{Start: Cursor{Line: 0, Char: 0}, End: Cursor{Line: 0, Char: 1111}}
assert.Equal(t, "line one\n", SelectionToString(buf, buf.Selection))
buf.Selection = &Selection{Start: Cursor{Line: 1, Char: 0}, End: Cursor{Line: 2, Char: 3}}
assert.Equal(t, "line two\nline", SelectionToString(buf, buf.Selection))
}