-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathbuf_test.go
48 lines (45 loc) · 1.19 KB
/
buf_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
package main
import (
"testing"
)
// Let's make sure our test fixture has the right form.
func TestBufferDelete(t *testing.T) {
tab := []struct {
q0, q1 int
tb Buffer
expected string
}{
{0, 5, Buffer([]rune("0123456789")), "56789"},
{0, 0, Buffer([]rune("0123456789")), "0123456789"},
{0, 10, Buffer([]rune("0123456789")), ""},
{1, 5, Buffer([]rune("0123456789")), "056789"},
{8, 10, Buffer([]rune("0123456789")), "01234567"},
}
for _, test := range tab {
tb := test.tb
tb.Delete(test.q0, test.q1)
if string(tb) != test.expected {
t.Errorf("Delete Failed. Expected %v, got %v", test.expected, string(tb))
}
}
}
func TestBufferInsert(t *testing.T) {
tab := []struct {
q0 int
tb Buffer
insert string
expected string
}{
{5, Buffer([]rune("01234")), "56789", "0123456789"},
{0, Buffer([]rune("56789")), "01234", "0123456789"},
{1, Buffer([]rune("06789")), "12345", "0123456789"},
{5, Buffer([]rune("01234")), "56789", "0123456789"},
}
for _, test := range tab {
tb := test.tb
tb.Insert(test.q0, []rune(test.insert))
if string(tb) != test.expected {
t.Errorf("Insert Failed. Expected %v, got %v", test.expected, string(tb))
}
}
}