2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-09-05 17:10:35 +01:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package redis
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestEscapeMatch(t *testing.T) {
|
|
|
|
type escaped struct{ unescaped, escaped string }
|
|
|
|
var examples = []escaped{
|
|
|
|
{`h?llo`, `h\?llo`},
|
|
|
|
{`h*llo`, `h\*llo`},
|
|
|
|
{`h[ae]llo`, `h\[ae\]llo`},
|
|
|
|
{`h[^e]llo`, `h\[^e\]llo`},
|
|
|
|
{`h[a-b]llo`, `h\[a-b\]llo`},
|
|
|
|
{`h\[a-b\]llo`, `h\\\[a-b\\\]llo`},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, example := range examples {
|
|
|
|
got := escapeMatch([]byte(example.unescaped))
|
|
|
|
if !bytes.Equal(got, []byte(example.escaped)) {
|
|
|
|
t.Errorf("fail %q got %q expected %q", example.unescaped, got, example.escaped)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|