forked from aarzilli/nucular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
strinsdel_test.go
66 lines (54 loc) · 1.38 KB
/
strinsdel_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
package nucular
import (
"testing"
)
func asserteq(t *testing.T, s []rune, tgt []rune) {
if len(s) != len(tgt) {
t.Fatalf("mismatched length %d %d", len(s), len(tgt))
}
for i := range s {
if s[i] != tgt[i] {
t.Fatalf("mismatch at character %d output: %q target: %q", i, string(s), string(tgt))
}
}
}
func TestInsertEnd(t *testing.T) {
s := []rune("something")
s = strInsertText(s, len(s), []rune("zap"))
asserteq(t, s, []rune("somethingzap"))
}
func TestInsertMid(t *testing.T) {
s := []rune("something")
s = strInsertText(s, 3, []rune("zap"))
asserteq(t, s, []rune("somzapething"))
}
func TestInsertStart(t *testing.T) {
s := []rune("something")
s = strInsertText(s, 0, []rune("zap"))
asserteq(t, s, []rune("zapsomething"))
}
func TestDeleteEnd(t *testing.T) {
s := []rune("something")
s = strDeleteText(s, len(s)-3, 3)
asserteq(t, s, []rune("someth"))
}
func TestDeleteMid(t *testing.T) {
s := []rune("something")
s = strDeleteText(s, 3, 2)
asserteq(t, s, []rune("somhing"))
}
func TestDeleteStart(t *testing.T) {
s := []rune("something")
s = strDeleteText(s, 0, 2)
asserteq(t, s, []rune("mething"))
}
func TestInsertFromNone(t *testing.T) {
s := []rune{}
s = strInsertText(s, 0, []rune("something"))
asserteq(t, s, []rune("something"))
}
func TestDeleteAll(t *testing.T) {
s := []rune("something")
s = strDeleteText(s, 0, len(s))
asserteq(t, s, []rune{})
}