-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstring_iterator_test.go
73 lines (64 loc) · 1.65 KB
/
string_iterator_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
package etxt
import "testing"
func testFailRunes(t *testing.T, expected rune, got rune) {
t.Fatalf("expected '%s', got '%s'", string(expected), string(got))
}
func TestRtlStringIterator(t *testing.T) {
var iter rtlStringIterator
testString := "abcd"
iter.Init(testString)
for _, expected := range []rune{'d', 'c', 'b', 'a', -1, -1, -1} {
got := iter.Next(testString)
if got != expected {
testFailRunes(t, expected, got)
}
}
testString = "a"
iter.Init(testString)
for _, expected := range []rune{'a', -1, -1, -1} {
got := iter.Next(testString)
if got != expected {
testFailRunes(t, expected, got)
}
}
testString = ""
iter.Init(testString)
for _, expected := range []rune{-1, -1, -1} {
got := iter.Next(testString)
if got != expected {
testFailRunes(t, expected, got)
}
}
testString = "\n"
iter.Init(testString)
for _, expected := range []rune{'\n', -1, -1, -1} {
got := iter.Next(testString)
if got != expected {
testFailRunes(t, expected, got)
}
}
testString = "\n\n"
iter.Init(testString)
for _, expected := range []rune{'\n', '\n', -1, -1, -1} {
got := iter.Next(testString)
if got != expected {
testFailRunes(t, expected, got)
}
}
testString = "\na\nb\n"
iter.Init(testString)
for _, expected := range []rune{'\n', 'a', '\n', 'b', '\n', -1, -1, -1} {
got := iter.Next(testString)
if got != expected {
testFailRunes(t, expected, got)
}
}
testString = "hello\nworld\n"
iter.Init(testString)
for _, expected := range []rune{'o', 'l', 'l', 'e', 'h', '\n', 'd', 'l', 'r', 'o', 'w', '\n', -1, -1, -1} {
got := iter.Next(testString)
if got != expected {
testFailRunes(t, expected, got)
}
}
}