-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcache_test.go
More file actions
103 lines (82 loc) · 2.12 KB
/
cache_test.go
File metadata and controls
103 lines (82 loc) · 2.12 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package readline
import (
"fmt"
"testing"
)
// string
func TestCacheStringMethods(t *testing.T) {
rl := NewInstance()
rl.MaxCacheSize = 10
c := new(cacheString)
c.Init(rl)
for i := 0; i < 20; i++ {
sLine := fmt.Sprintf("line %d", i)
rLine := []rune(sLine)
sValue := fmt.Sprintf("value %d", i)
r := c.Get(rLine)
if string(r) == sValue {
t.Fatalf(`Pre-Append error: c.Get(%s) == "%s"`, sLine, string(r))
}
c.Append(rLine, sValue)
r = c.Get(rLine)
if string(r) != sValue {
t.Fatalf(`Post-Append error: c.Get(%s) == "%s"`, sLine, string(r))
}
}
c.Init(rl)
if c.size != 0 || len(c.values["line 1"]) > 0 {
t.Error("cacheString failed to reinitialize correctly")
t.Logf(" size: %d", c.size)
t.Logf(` c.values["line 1"]: "%s"`, string(c.values["line 1"]))
}
}
func TestCacheStringOutOfBounds(t *testing.T) {
rl := NewInstance()
rl.MaxCacheSize = 10
c := new(cacheString)
c.Init(rl)
for i := 0; i < 20; i++ {
line := []rune(fmt.Sprintf("line %d", i))
value := fmt.Sprintf("value %d", i)
c.Append(line, value)
}
}
// []rune
func TestCacheSliceRuneMethods(t *testing.T) {
rl := NewInstance()
rl.MaxCacheSize = 10
c := new(cacheSliceRune)
c.Init(rl)
for i := 0; i < 20; i++ {
sLine := fmt.Sprintf("line %d", i)
rLine := []rune(sLine)
sValue := fmt.Sprintf("value %d", i)
rValue := []rune(sValue)
r := c.Get(rLine)
if string(r) == sValue {
t.Fatalf(`Pre-Append error: c.Get(%s) == "%s"`, sLine, string(r))
}
c.Append(rLine, rValue)
r = c.Get(rLine)
if string(r) != sValue {
t.Fatalf(`Post-Append error: c.Get(%s) == "%s"`, sLine, string(r))
}
}
c.Init(rl)
if c.size != 0 || len(c.values["line 1"]) > 0 {
t.Error("cacheString failed to reinitialize correctly")
t.Logf(" size: %d", c.size)
t.Logf(` c.values["line 1"]: "%s"`, string(c.values["line 1"]))
}
}
func TestCacheSlineRuneOutOfBounds(t *testing.T) {
rl := NewInstance()
rl.MaxCacheSize = 10
c := new(cacheSliceRune)
c.Init(rl)
for i := 0; i < 20; i++ {
line := []rune(fmt.Sprintf("line %d", i))
value := []rune(fmt.Sprintf("value %d", i))
c.Append(line, value)
}
}