-
Notifications
You must be signed in to change notification settings - Fork 34
/
ecmd_test.go
206 lines (181 loc) · 4.59 KB
/
ecmd_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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
package main
import (
"os"
"path/filepath"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/rjkroege/edwood/dumpfile"
"github.com/rjkroege/edwood/file"
)
// Test for https://github.com/rjkroege/edwood/issues/291
// {gh issue view 291}
func DISABLED_TestXCmdPipeMultipleWindows(t *testing.T) {
global.cedit = make(chan int)
global.ccommand = make(chan *Command)
global.cwait = make(chan ProcessState)
newWindow := func(name string) *Window {
w := NewWindow()
w.body.file = file.MakeObservableEditableBuffer(name, nil)
w.body.w = w
w.body.fr = &MockFrame{}
w.body.file.AddObserver(&w.body)
w.tag.file = file.MakeObservableEditableBuffer("", nil)
w.tag.w = w
w.tag.fr = &MockFrame{}
w.tag.file.AddObserver(&w.tag)
w.editoutlk = make(chan bool, 1)
return w
}
global.row = Row{
col: []*Column{
{
w: []*Window{
newWindow("one.txt"),
newWindow("two.txt"),
},
},
},
}
defer func() {
global.cedit = nil
global.ccommand = nil
global.cwait = nil
global.row = Row{}
warningsMu.Lock()
defer warningsMu.Unlock()
// remove fsysmount failure warning
warnings = []*Warning{}
}()
// All middle button commands including Edit run inside a lock discipline
// set up by MovedMouse.
global.row.lk.Lock()
defer global.row.lk.Unlock()
cp := &cmdParser{
buf: []rune("X |cat\n"),
pos: 0,
}
cmd, err := cp.parse(0)
if err != nil {
t.Fatalf("failed to parse command: %v", err)
}
X_cmd(nil, cmd)
}
func edit_sPerf(t testing.TB, g *globals) {
t.Helper()
firstwin := g.row.col[0].w[0]
// Lock discipline?
// TODO(rjk): figure out how to change this with less global dependency.
global.row.lk.Lock()
firstwin.Lock('M')
global.seq++
action := ", s/fox/gopher/g"
editcmd(&firstwin.body, []rune(action))
firstwin.Unlock()
global.row.lk.Unlock()
}
func edit_xPerf(t testing.TB, g *globals) {
t.Helper()
firstwin := g.row.col[0].w[0]
// Lock discipline?
// TODO(rjk): figure out how to change this with less global dependency.
global.row.lk.Lock()
firstwin.Lock('M')
global.seq++
action := ",x/fox/ c/gopher/"
editcmd(&firstwin.body, []rune(action))
firstwin.Unlock()
global.row.lk.Unlock()
}
func BenchmarkLargeEditTargets10(t *testing.B) { benchmarkLargeEditTargetsImpl(t, 10) }
func BenchmarkLargeEditTargets109(t *testing.B) { benchmarkLargeEditTargetsImpl(t, 100) }
func BenchmarkLargeEditTargets1000(t *testing.B) { benchmarkLargeEditTargetsImpl(t, 1000) }
func BenchmarkLargeEditTargets10000(t *testing.B) { benchmarkLargeEditTargetsImpl(t, 10000) }
func benchmarkLargeEditTargetsImpl(t *testing.B, nl int) {
dir := t.TempDir()
firstfilename := filepath.Join(dir, "bigfile")
cwd, err := os.Getwd()
if err != nil {
t.Fatalf("failed to get current working directory: %v", err)
}
tests := []struct {
name string
fn func(t testing.TB, g *globals)
want *dumpfile.Content
}{
{
name: "edit_xPerf",
fn: edit_xPerf,
want: &dumpfile.Content{
CurrentDir: cwd,
VarFont: defaultVarFont,
FixedFont: defaultFixedFont,
Columns: []dumpfile.Column{
{},
},
Windows: []*dumpfile.Window{
{
Type: dumpfile.Unsaved,
Column: 0,
Tag: dumpfile.Text{
Buffer: firstfilename + " Del Snarf Undo Put | Look Edit ",
},
Body: dumpfile.Text{
Buffer: Repeating(nl, "the quick brown gopher"),
Q0: nl*(len("the quick brown gopher")+1) - 7,
Q1: nl*(len("the quick brown gopher")+1) - 1,
},
},
},
},
},
{
name: "edit_sPerf",
fn: edit_sPerf,
want: &dumpfile.Content{
CurrentDir: cwd,
VarFont: defaultVarFont,
FixedFont: defaultFixedFont,
Columns: []dumpfile.Column{
{},
},
Windows: []*dumpfile.Window{
{
Type: dumpfile.Unsaved,
Column: 0,
Tag: dumpfile.Text{
Buffer: firstfilename + " Del Snarf Undo Put | Look Edit ",
},
Body: dumpfile.Text{
Buffer: Repeating(nl, "the quick brown gopher"),
Q0: 0,
Q1: nl * (len("the quick brown gopher") + 1),
},
},
},
},
},
}
for _, tc := range tests {
t.Run(tc.name, func(b *testing.B) {
b.StopTimer()
for i := 0; i < b.N; i++ {
FlexiblyMakeWindowScaffold(
b,
ScWin("bigfile"),
ScDir(dir, "bigfile"),
ScBody("bigfile", Repeating(nl, "the quick brown fox")),
)
b.StartTimer()
tc.fn(b, global)
b.StopTimer()
got, err := global.row.dump()
if err != nil {
b.Fatalf("dump failed: %v", err)
}
if diff := cmp.Diff(tc.want, got); diff != "" {
b.Errorf("dump mismatch (-want +got):\n%s", diff)
}
}
})
}
}