1
0
Fork 0

Adding upstream version 2.2.2.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-05-16 22:45:16 +02:00
parent a6909e3829
commit 02ef45af86
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
19 changed files with 3024 additions and 0 deletions

121
pattern_test.go Normal file
View file

@ -0,0 +1,121 @@
package gocache
import "testing"
func TestMatchPattern(t *testing.T) {
scenarios := []struct {
pattern string
key string
expectedToMatch bool
}{
{
pattern: "*",
key: "livingroom_123",
expectedToMatch: true,
},
{
pattern: "*",
key: "livingroom_123",
expectedToMatch: true,
},
{
pattern: "**",
key: "livingroom_123",
expectedToMatch: true,
},
{
pattern: "living*",
key: "livingroom_123",
expectedToMatch: true,
},
{
pattern: "*living*",
key: "livingroom_123",
expectedToMatch: true,
},
{
pattern: "*123",
key: "livingroom_123",
expectedToMatch: true,
},
{
pattern: "*_*",
key: "livingroom_123",
expectedToMatch: true,
},
{
pattern: "living*_*3",
key: "livingroom_123",
expectedToMatch: true,
},
{
pattern: "living*room_*3",
key: "livingroom_123",
expectedToMatch: true,
},
{
pattern: "living*room_*3",
key: "livingroom_123",
expectedToMatch: true,
},
{
pattern: "*vin*om*2*",
key: "livingroom_123",
expectedToMatch: true,
},
{
pattern: "livingroom_123",
key: "livingroom_123",
expectedToMatch: true,
},
{
pattern: "*livingroom_123*",
key: "livingroom_123",
expectedToMatch: true,
},
{
pattern: "livingroom",
key: "livingroom_123",
expectedToMatch: false,
},
{
pattern: "livingroom123",
key: "livingroom_123",
expectedToMatch: false,
},
{
pattern: "what",
key: "livingroom_123",
expectedToMatch: false,
},
{
pattern: "*what*",
key: "livingroom_123",
expectedToMatch: false,
},
{
pattern: "*.*",
key: "livingroom_123",
expectedToMatch: false,
},
{
pattern: "room*123",
key: "livingroom_123",
expectedToMatch: false,
},
}
for _, scenario := range scenarios {
t.Run(scenario.pattern+"---"+scenario.key, func(t *testing.T) {
matched := MatchPattern(scenario.pattern, scenario.key)
if scenario.expectedToMatch {
if !matched {
t.Errorf("%s should've matched pattern '%s'", scenario.key, scenario.pattern)
}
} else {
if matched {
t.Errorf("%s shouldn't have matched pattern '%s'", scenario.key, scenario.pattern)
}
}
})
}
}