-
Notifications
You must be signed in to change notification settings - Fork 2
/
main_test.go
157 lines (132 loc) · 3.17 KB
/
main_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
package main
import (
"io"
"strings"
"testing"
. "github.com/hymkor/binview/internal/large"
)
func _insert(exp string) func(*Application) error {
return func(app *Application) error {
return app.InsertExp(exp)
}
}
func _append(exp string) func(*Application) error {
return func(app *Application) error {
return app.AppendExp(exp)
}
}
func try(
t *testing.T,
source string,
expect string,
funcs ...func(app *Application) error) {
ALLOC_SIZE = 4
app, err := NewApplication(strings.NewReader(source), io.Discard, "dummy")
if err != nil {
t.Fatal(err.Error())
return
}
for _, f := range funcs {
if err := f(app); err != nil {
app.Close()
t.Fatal(err.Error())
return
}
}
var output strings.Builder
app.buffer.WriteTo(&output)
app.Close()
if outputStr := output.String(); outputStr != expect {
t.Fatalf("expect '%s' but '%s'", expect, outputStr)
}
}
func TestNoModify(t *testing.T) {
const sample = "1234567890"
try(t, sample, sample)
}
func TestKeyFuncRemoveByte(t *testing.T) {
try(t, "1234567890", "234567890",
keyFuncRemoveByte)
}
func TestKeyFuncInsertByte(t *testing.T) {
try(t, "1234567890", "\0001234567890",
_insert("0x00"))
}
func TestForwardAndRemove(t *testing.T) {
try(t, "1234567890", "134567890",
keyFuncForward,
keyFuncRemoveByte)
}
func TestRemoveEOF(t *testing.T) {
try(t, "1234567890", "123456789",
keyFuncGoEndOfFile,
keyFuncRemoveByte)
}
func TestRemoveEndOfLine(t *testing.T) {
try(t, "0123456789ABCDEFG", "0123456789ABCDEG",
keyFuncGoEndOfLine,
keyFuncRemoveByte)
}
func TestEndOfLine2Backward2Delete(t *testing.T) {
try(t, "0123456789ABCDEFG", "0123456789ABCDFG",
keyFuncGoEndOfLine,
keyFuncBackword,
keyFuncRemoveByte)
}
func TestKeyFuncNext(t *testing.T) {
try(t, "0123456789ABCDEFGHI", "0123456789ABCDEFHI",
keyFuncNext,
keyFuncRemoveByte)
}
func TestCutAndPasteAfter(t *testing.T) {
try(t, "0123456789ABCDEFGHI", "1023456789ABCDEFGHI",
keyFuncRemoveByte,
keyFuncPasteAfter)
}
func TestCutAndPasteBefore(t *testing.T) {
try(t, "0123456789ABCDEFGHI", "F0123456789ABCDEGHI",
keyFuncGoEndOfLine,
keyFuncRemoveByte,
keyFuncGoBeginOfFile,
keyFuncPasteBefore)
}
func TestKeyFuncPrevious(t *testing.T) {
try(t, "0123456789ABCDEF"+"GHIJ", "01J23456789ABCDEFGHI",
keyFuncGoEndOfFile,
keyFuncRemoveByte,
keyFuncPrevious,
keyFuncPasteBefore)
}
func TestKeyFuncBeginOfLine(t *testing.T) {
try(t, "0123456789ABCDEF"+"GHIJ", "0123456789ABCDEF"+"HIJ",
keyFuncGoEndOfFile,
keyFuncGoBeginOfLine,
keyFuncRemoveByte)
}
func TestKeyFuncAddByte(t *testing.T) {
try(t, "0123456789ABCDEF", "0\000123456789ABCDEF",
_append("0x00"))
}
func TestEmptyData(t *testing.T) {
_, err := NewApplication(strings.NewReader(""), io.Discard, "dummy")
if err == nil {
t.Fatal("with empty data,NewApplication must return error, but it did not")
return
}
}
func TestEndOfLineOnShortData(t *testing.T) {
try(t, "012345", "01234\0005",
keyFuncGoEndOfLine,
_insert("0x00"))
}
func TestInsertAndUndo(t *testing.T) {
try(t, "012345", "012345",
_insert(`"abcdef"`),
keyFuncUndo)
}
func TestAppendAndUndo(t *testing.T) {
try(t, "012345", "012345",
keyFuncGoEndOfLine,
_append(`"abcdef"`),
keyFuncUndo)
}