-
Notifications
You must be signed in to change notification settings - Fork 6
/
delete_test.go
60 lines (52 loc) · 1.33 KB
/
delete_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
package frame
import (
"image"
"image/draw"
"testing"
"github.com/as/etch"
"github.com/as/font"
)
var (
R = image.Rect(0, 0, 232, 232)
fsize = 11
)
func tconf() *Config {
return &Config{
Face: font.NewGoMono(fsize),
Color: A,
}
}
func abtest(r image.Rectangle) (fr0, fr1 *Frame, a, b *image.RGBA) {
a = image.NewRGBA(r)
b = image.NewRGBA(r)
fr0 = New(a, a.Bounds(), tconf())
fr1 = New(b, b.Bounds(), tconf())
return fr0, fr1, a, b
}
func abtestbg(r image.Rectangle) (fa, fb *Frame, a, b *image.RGBA) {
fa, fb, a, b = abtest(r)
draw.Draw(a, a.Bounds(), fa.Color.Back, image.ZP, draw.Src)
draw.Draw(b, b.Bounds(), fb.Color.Back, image.ZP, draw.Src)
return fa, fb, a, b
}
func TestDeleteOneChar(t *testing.T) {
h, w, have, want := abtestbg(R)
h.Insert([]byte("1"), 0)
h.Delete(0, h.Len())
h.Untick()
w.Untick()
etch.Assert(t, have, want, "TestDelete.png")
}
func TestDeleteLastLineNoNL(t *testing.T) {
w, h, want, have := abtestbg(R)
draw.Draw(want, want.Bounds(), w.Color.Back, image.ZP, draw.Src)
draw.Draw(have, have.Bounds(), h.Color.Back, image.ZP, draw.Src)
w.Insert([]byte("1234\ncccc\ndddd\n"), 0)
h.Insert([]byte("1234\ncccc\ndddd"), 0)
h.Delete(5, 10)
w.Delete(5, 10)
// We can untick because have has an extra newline
h.Untick()
w.Untick()
etch.Assert(t, have, want, "TestDeleteLastLineNoNL.png")
}