@@ -9,17 +9,20 @@ func TestRegexp(t *testing.T) {
9
9
db .Set ("card:1:black_lotus" , "Black Lotus" )
10
10
db .Set ("card:2:mox_pearl" , "Mox Pearl" )
11
11
12
+ // feed in some bad regexp to MatchKeys
12
13
badRegexp := "card[0-9"
13
14
_ , err := db .MatchKeys (badRegexp )
14
15
if err == nil {
15
16
t .Errorf ("expected error, got nil" )
16
17
}
17
18
19
+ // feed in some bad regexp to MatchValues
18
20
_ , err = db .MatchValues (badRegexp )
19
21
if err == nil {
20
22
t .Errorf ("expected error, got nil" )
21
23
}
22
24
25
+ // fetch both cards by key
23
26
keys , err := db .MatchKeys ("card:[0-9]:." )
24
27
if err != nil {
25
28
t .Error (err )
@@ -28,6 +31,7 @@ func TestRegexp(t *testing.T) {
28
31
t .Errorf ("expected %d, got %d" , 2 , len (keys ))
29
32
}
30
33
34
+ // fetch both cards by value
31
35
values , err := db .MatchValues ("card:[0-9]:." )
32
36
if err != nil {
33
37
t .Error (err )
@@ -42,6 +46,7 @@ func TestPrefix(t *testing.T) {
42
46
db .Set ("card:1:black_lotus" , "Black Lotus" )
43
47
db .Set ("card:2:mox_pearl" , "Mox Pearl" )
44
48
49
+ // fetch one card by prefix exact match
45
50
keys , err := db .Prefix ("card:2:mox_pearl" )
46
51
if err != nil {
47
52
t .Error (err )
@@ -51,6 +56,7 @@ func TestPrefix(t *testing.T) {
51
56
t .Errorf ("expected %d, got %d" , 1 , len (keys ))
52
57
}
53
58
59
+ // fetch both cards by prefix using wildcards
54
60
keys , err = db .Prefix ("*:?:*" )
55
61
if err != nil {
56
62
t .Error (err )
@@ -60,7 +66,8 @@ func TestPrefix(t *testing.T) {
60
66
t .Errorf ("expected %d, got %d" , 2 , len (keys ))
61
67
}
62
68
63
- keysChan := db .PrefixChan ("c?" )
69
+ // fetch both cards by prefix to a channel using wildcards
70
+ keysChan := db .PrefixChan ("*:?:*" )
64
71
count := 0
65
72
for range keysChan {
66
73
count ++
0 commit comments