-
Notifications
You must be signed in to change notification settings - Fork 6
/
indexof_test.go
70 lines (64 loc) · 1.52 KB
/
indexof_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
package frame
import (
"image"
"testing"
)
func TestIndexOfWrap(t *testing.T) {}
func TestIndexOf(t *testing.T) {
tab := []pointTest{
{"hello1", 0, 0, image.Pt(0, 0)},
{"hello2", 0, 1, image.Pt(7, 0)},
{"he\nsaid2", 0, 3, image.Pt(0, 16)},
{"he\n\n\n\nsaid2", 0, 4, image.Pt(0, 32)},
{"\n", 0, 0, image.Pt(0, 0*8)},
{"\n", 100, 0, image.Pt(0, 1*8)},
{"\n\n", 0, 1, image.Pt(0, 2*8)},
{"\n\n\n", 0, 1, image.Pt(0, 3*8)},
}
for _, v := range tab {
h, _, _, _ := abtestbg(R)
h.Insert([]byte(v.insert), v.p0)
have := h.IndexOf(v.pt)
want := v.c0
if have != want {
t.Logf("%q: have %d, want %d", v.insert, have, want)
t.Fail()
}
}
}
func TestIndexOfMultiInsert(t *testing.T) {
t.Skip("not finished")
type pointTest struct {
s string
p0 int64
pt image.Point
}
prog := `package main
import "fmt"
func main(){
fmt.Println("take me to your leader")
}
`
tab := []pointTest{
{"package(sp)", 0, image.Pt(0, 0)},
{"package(sp)", 1, image.Pt(7, 0)},
{"package(ep)", 7, image.Pt(7*7, 0)},
{"main(sp)", 7 + 1, image.Pt(7*(7+1), 0)},
{"main(ep)", 7 + 1 + 4, image.Pt(7*(7+1+4), 0)},
{"nl(1)", 7 + 1 + 4 + 1, image.Pt(0, 16)},
{"import(sp)", 7 + 1 + 4 + 1 + 1, image.Pt(0, 16)},
{"import(sp+1)", 7 + 1 + 4 + 1 + 1 + 1, image.Pt(0, 16)},
}
for _, v := range tab {
h, _, _, _ := abtestbg(R)
for i, c := range []byte(prog) {
h.Insert([]byte{c}, int64(i))
}
have := h.IndexOf(v.pt)
want := v.p0
if have != want {
t.Logf("%q: have %d, want %d", v.s, have, want)
t.Fail()
}
}
}