-
Notifications
You must be signed in to change notification settings - Fork 34
/
wind_test.go
115 lines (104 loc) · 2.81 KB
/
wind_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
115
package main
import (
"image"
"reflect"
"testing"
"github.com/rjkroege/edwood/edwoodtest"
"github.com/rjkroege/edwood/file"
)
func TestSetTag1(t *testing.T) {
const (
defaultSuffix = " Del Snarf | Look Edit "
extraSuffix = "|fmt g setTag1 Ldef"
)
for _, name := range []string{
"/home/gopher/src/hello.go",
"/home/ゴーファー/src/エドウード.txt",
"/home/ゴーファー/src/",
} {
display := edwoodtest.NewDisplay(image.Rectangle{})
global.configureGlobals(display)
w := NewWindow().initHeadless(nil)
w.display = display
w.body = Text{
display: display,
fr: &MockFrame{},
file: file.MakeObservableEditableBuffer(name, nil),
}
w.tag = Text{
display: display,
fr: &MockFrame{},
file: file.MakeObservableEditableBuffer("", nil),
}
w.col = &Column{
safe: true,
}
w.setTag1()
got := w.tag.file.String()
want := name + defaultSuffix
if got != want {
t.Errorf("bad initial tag for file %q:\n got: %q\nwant: %q", name, got, want)
}
w.tag.file.InsertAt(w.tag.file.Nr(), []rune(extraSuffix))
w.setTag1()
got = w.tag.file.String()
want = name + defaultSuffix + extraSuffix
if got != want {
t.Errorf("bad replacement tag for file %q:\n got: %q\nwant: %q", name, got, want)
}
}
}
func TestWindowClampAddr(t *testing.T) {
const hello_世界 = "Hello, 世界"
runic_hello_世界 := []rune(hello_世界)
for _, tc := range []struct {
addr, want Range
}{
{Range{-1, -1}, Range{0, 0}},
{Range{100, 100}, Range{len(runic_hello_世界), len(runic_hello_世界)}},
} {
w := &Window{
addr: tc.addr,
body: Text{
file: file.MakeObservableEditableBuffer("", runic_hello_世界),
},
}
w.ClampAddr()
if got := w.addr; !reflect.DeepEqual(got, tc.want) {
t.Errorf("got addr %v; want %v", got, tc.want)
}
}
}
func TestWindowParseTag(t *testing.T) {
for _, tc := range []struct {
tag string
filename string
}{
{"/foo/bar.txt Del Snarf | Look", "/foo/bar.txt"},
{"'/foo/bar quux.txt' Del Snarf | Look", "'/foo/bar quux.txt'"},
{"/foo/bar.txt", "/foo/bar.txt"},
{"/foo/bar.txt | Look", "/foo/bar.txt"},
{"/foo/bar.txt Del Snarf\t| Look", "/foo/bar.txt"},
{"/foo/bar.txt Del Snarf Del Snarf", "/foo/bar.txt"},
{"'/foo/bar.txt ' Del Snarf", "'/foo/bar.txt '"},
{"'/foo/b|ar.txt ' Del Snarf", "'/foo/b|ar.txt '"},
} {
if got, want := parsetaghelper(tc.tag), tc.filename; got != want {
t.Errorf("tag %q has filename %q; want %q", tc.tag, got, want)
}
}
}
func TestWindowClearTag(t *testing.T) {
tag := "/foo bar/test.txt Del Snarf Undo Put | Look |fmt mk"
want := "/foo bar/test.txt Del Snarf Undo Put |"
w := &Window{
tag: Text{
file: file.MakeObservableEditableBuffer("", []rune(tag)),
},
}
w.ClearTag()
got := w.tag.file.String()
if got != want {
t.Errorf("got %q; want %q", got, want)
}
}