2015-11-30 17:58:20 +03:00
|
|
|
package glob
|
2015-11-30 19:21:30 +03:00
|
|
|
|
2015-11-30 17:58:20 +03:00
|
|
|
import (
|
2016-01-13 01:26:48 +03:00
|
|
|
"bytes"
|
|
|
|
"fmt"
|
2016-01-08 20:14:31 +03:00
|
|
|
"github.com/gobwas/glob/match"
|
2016-01-13 01:26:48 +03:00
|
|
|
"math/rand"
|
2016-01-19 20:52:32 +03:00
|
|
|
"regexp"
|
2016-01-15 19:50:12 +03:00
|
|
|
"strings"
|
2015-11-30 19:21:30 +03:00
|
|
|
"testing"
|
2015-11-30 17:58:20 +03:00
|
|
|
)
|
|
|
|
|
2015-12-24 19:00:41 +03:00
|
|
|
const (
|
2016-01-20 21:05:54 +03:00
|
|
|
pattern_all = "[a-z][!a-x]*cat*[h][!b]*eyes*"
|
|
|
|
regexp_all = `^[a-z][^a-x].*cat.*[h][^b].*eyes.*$`
|
|
|
|
fixture_all_match = "my cat has very bright eyes"
|
|
|
|
fixture_all_mismatch = "my dog has very bright eyes"
|
|
|
|
|
|
|
|
pattern_plain = "google.com"
|
|
|
|
regexp_plain = `^google\.com$`
|
|
|
|
fixture_plain_match = "google.com"
|
|
|
|
fixture_plain_mismatch = "gobwas.com"
|
|
|
|
|
|
|
|
pattern_multiple = "https://*.google.*"
|
|
|
|
regexp_multiple = `^https:\/\/.*\.google\..*$`
|
|
|
|
fixture_multiple_match = "https://account.google.com"
|
|
|
|
fixture_multiple_mismatch = "https://google.com"
|
|
|
|
|
|
|
|
pattern_alternatives = "{https://*.google.*,*yandex.*,*yahoo.*,*mail.ru}"
|
|
|
|
regexp_alternatives = `^(https:\/\/.*\.google\..*|.*yandex\..*|.*yahoo\..*|.*mail\.ru)$`
|
|
|
|
fixture_alternatives_match = "http://yahoo.com"
|
|
|
|
fixture_alternatives_mismatch = "http://google.com"
|
|
|
|
|
|
|
|
pattern_alternatives_suffix = "{https://*gobwas.com,http://exclude.gobwas.com}"
|
|
|
|
regexp_alternatives_suffix = `^(https:\/\/.*gobwas\.com|http://exclude.gobwas.com)$`
|
|
|
|
fixture_alternatives_suffix_first_match = "https://safe.gobwas.com"
|
|
|
|
fixture_alternatives_suffix_first_mismatch = "http://safe.gobwas.com"
|
|
|
|
fixture_alternatives_suffix_second = "http://exclude.gobwas.com"
|
|
|
|
|
|
|
|
pattern_prefix = "abc*"
|
|
|
|
regexp_prefix = `^abc.*$`
|
|
|
|
pattern_suffix = "*def"
|
|
|
|
regexp_suffix = `^.*def$`
|
|
|
|
pattern_prefix_suffix = "ab*ef"
|
|
|
|
regexp_prefix_suffix = `^ab.*ef$`
|
|
|
|
fixture_prefix_suffix_match = "abcdef"
|
|
|
|
fixture_prefix_suffix_mismatch = "af"
|
2016-01-15 19:50:12 +03:00
|
|
|
|
|
|
|
pattern_alternatives_combine_lite = "{abc*def,abc?def,abc[zte]def}"
|
2016-01-20 17:41:22 +03:00
|
|
|
regexp_alternatives_combine_lite = `^(abc.*def|abc.def|abc[zte]def)$`
|
2016-01-15 19:50:12 +03:00
|
|
|
fixture_alternatives_combine_lite = "abczdef"
|
|
|
|
|
|
|
|
pattern_alternatives_combine_hard = "{abc*[a-c]def,abc?[d-g]def,abc[zte]?def}"
|
2016-01-20 17:41:22 +03:00
|
|
|
regexp_alternatives_combine_hard = `^(abc.*[a-c]def|abc.[d-g]def|abc[zte].def)$`
|
2016-01-15 19:50:12 +03:00
|
|
|
fixture_alternatives_combine_hard = "abczqdef"
|
2015-12-24 19:00:41 +03:00
|
|
|
)
|
|
|
|
|
2015-11-30 17:58:20 +03:00
|
|
|
type test struct {
|
|
|
|
pattern, match string
|
|
|
|
should bool
|
|
|
|
delimiters []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func glob(s bool, p, m string, d ...string) test {
|
|
|
|
return test{p, m, s, d}
|
|
|
|
}
|
|
|
|
|
2016-01-13 01:26:48 +03:00
|
|
|
func draw(pattern string, m match.Matcher) string {
|
2016-01-15 19:50:12 +03:00
|
|
|
return fmt.Sprintf(`digraph G {graph[label="%s"];%s}`, pattern, graphviz(m, fmt.Sprintf("%x", rand.Int63())))
|
2016-01-13 01:26:48 +03:00
|
|
|
}
|
|
|
|
|
2016-01-15 19:50:12 +03:00
|
|
|
func graphviz(m match.Matcher, id string) string {
|
2016-01-13 01:26:48 +03:00
|
|
|
buf := &bytes.Buffer{}
|
|
|
|
|
2016-01-15 19:50:12 +03:00
|
|
|
switch matcher := m.(type) {
|
|
|
|
case match.BTree:
|
|
|
|
fmt.Fprintf(buf, `"%s"[label="%s"];`, id, matcher.Value.String())
|
|
|
|
for _, m := range []match.Matcher{matcher.Left, matcher.Right} {
|
|
|
|
switch n := m.(type) {
|
|
|
|
case nil:
|
|
|
|
rnd := rand.Int63()
|
|
|
|
fmt.Fprintf(buf, `"%x"[label="<nil>"];`, rnd)
|
|
|
|
fmt.Fprintf(buf, `"%s"->"%x";`, id, rnd)
|
|
|
|
|
|
|
|
default:
|
|
|
|
sub := fmt.Sprintf("%x", rand.Int63())
|
|
|
|
fmt.Fprintf(buf, `"%s"->"%s";`, id, sub)
|
|
|
|
fmt.Fprintf(buf, graphviz(n, sub))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
case match.AnyOf:
|
|
|
|
fmt.Fprintf(buf, `"%s"[label="AnyOf"];`, id)
|
|
|
|
for _, m := range matcher.Matchers {
|
2016-01-13 01:26:48 +03:00
|
|
|
rnd := rand.Int63()
|
2016-01-15 19:50:12 +03:00
|
|
|
fmt.Fprintf(buf, graphviz(m, fmt.Sprintf("%x", rnd)))
|
2016-01-13 01:26:48 +03:00
|
|
|
fmt.Fprintf(buf, `"%s"->"%x";`, id, rnd)
|
2016-01-15 19:50:12 +03:00
|
|
|
}
|
2016-01-13 01:26:48 +03:00
|
|
|
|
2016-01-15 19:50:12 +03:00
|
|
|
case match.EveryOf:
|
|
|
|
fmt.Fprintf(buf, `"%s"[label="EveryOf"];`, id)
|
|
|
|
for _, m := range matcher.Matchers {
|
2016-01-13 01:26:48 +03:00
|
|
|
rnd := rand.Int63()
|
2016-01-15 19:50:12 +03:00
|
|
|
fmt.Fprintf(buf, graphviz(m, fmt.Sprintf("%x", rnd)))
|
2016-01-13 01:26:48 +03:00
|
|
|
fmt.Fprintf(buf, `"%s"->"%x";`, id, rnd)
|
|
|
|
}
|
2016-01-15 19:50:12 +03:00
|
|
|
|
|
|
|
default:
|
|
|
|
fmt.Fprintf(buf, `"%s"[label="%s"];`, id, m.String())
|
2016-01-13 01:26:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return buf.String()
|
|
|
|
}
|
|
|
|
|
2016-01-15 19:50:12 +03:00
|
|
|
func DrawPatterns(t *testing.T) {
|
2016-01-08 20:14:31 +03:00
|
|
|
for id, test := range []struct {
|
|
|
|
pattern string
|
|
|
|
sep string
|
|
|
|
}{
|
2016-01-20 21:05:54 +03:00
|
|
|
// {
|
|
|
|
// pattern: pattern_all,
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// pattern: pattern_alternatives_suffix,
|
|
|
|
// sep: separators,
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// pattern: pattern_alternatives_combine_lite,
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// pattern: pattern_alternatives_combine_hard,
|
|
|
|
// },
|
2016-01-14 21:32:02 +03:00
|
|
|
{
|
2016-01-15 19:50:12 +03:00
|
|
|
pattern: pattern_alternatives_suffix,
|
2016-01-19 20:52:32 +03:00
|
|
|
},
|
2016-01-20 21:05:54 +03:00
|
|
|
// {
|
|
|
|
// pattern: "{https://*.mail.ru,*my.mail.ru,*my.myalpha*.i.mail.ru}",
|
|
|
|
// },
|
2016-01-08 20:14:31 +03:00
|
|
|
} {
|
|
|
|
glob, err := Compile(test.pattern, test.sep)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("#%d compile pattern error: %s", id, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
matcher := glob.(match.Matcher)
|
2016-01-15 19:50:12 +03:00
|
|
|
fmt.Println(test.pattern)
|
|
|
|
fmt.Println(strings.Repeat("=", len(test.pattern)))
|
|
|
|
fmt.Println(draw(test.pattern, matcher))
|
|
|
|
fmt.Println()
|
|
|
|
fmt.Println(matcher.String())
|
|
|
|
fmt.Println()
|
2016-01-08 20:14:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-24 19:00:41 +03:00
|
|
|
func TestIndexByteNonEscaped(t *testing.T) {
|
2015-11-30 19:21:30 +03:00
|
|
|
for _, test := range []struct {
|
2016-01-08 20:14:31 +03:00
|
|
|
s string
|
2015-12-24 17:54:54 +03:00
|
|
|
n, e byte
|
2016-01-08 20:14:31 +03:00
|
|
|
i int
|
2015-11-30 17:58:20 +03:00
|
|
|
}{
|
|
|
|
{
|
2015-12-24 17:54:54 +03:00
|
|
|
"\\n_n",
|
|
|
|
'n',
|
|
|
|
'\\',
|
|
|
|
3,
|
2015-11-30 17:58:20 +03:00
|
|
|
},
|
|
|
|
{
|
2015-12-24 17:54:54 +03:00
|
|
|
"ab",
|
|
|
|
'a',
|
|
|
|
'\\',
|
2015-11-30 17:58:20 +03:00
|
|
|
0,
|
2015-12-24 17:54:54 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"ab",
|
|
|
|
'b',
|
|
|
|
'\\',
|
|
|
|
1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"",
|
|
|
|
'b',
|
|
|
|
'\\',
|
|
|
|
-1,
|
2015-11-30 17:58:20 +03:00
|
|
|
},
|
2015-12-24 19:00:41 +03:00
|
|
|
{
|
|
|
|
"\\b",
|
|
|
|
'b',
|
|
|
|
'\\',
|
|
|
|
-1,
|
|
|
|
},
|
2015-11-30 19:21:30 +03:00
|
|
|
} {
|
2015-12-24 17:54:54 +03:00
|
|
|
i := indexByteNonEscaped(test.s, test.n, test.e, 0)
|
|
|
|
if i != test.i {
|
|
|
|
t.Errorf("unexpeted index: expected %v, got %v", test.i, i)
|
2015-11-30 17:58:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGlob(t *testing.T) {
|
2015-11-30 19:21:30 +03:00
|
|
|
for _, test := range []test{
|
2016-01-09 02:34:41 +03:00
|
|
|
glob(true, "* ?at * eyes", "my cat has very bright eyes"),
|
|
|
|
|
2015-11-30 17:58:20 +03:00
|
|
|
glob(true, "abc", "abc"),
|
|
|
|
glob(true, "a*c", "abc"),
|
|
|
|
glob(true, "a*c", "a12345c"),
|
|
|
|
glob(true, "a?c", "a1c"),
|
|
|
|
glob(true, "a.b", "a.b", "."),
|
|
|
|
glob(true, "a.*", "a.b", "."),
|
|
|
|
glob(true, "a.**", "a.b.c", "."),
|
|
|
|
glob(true, "a.?.c", "a.b.c", "."),
|
|
|
|
glob(true, "a.?.?", "a.b.c", "."),
|
|
|
|
glob(true, "?at", "cat"),
|
2015-11-30 18:24:20 +03:00
|
|
|
glob(true, "?at", "fat"),
|
2015-11-30 17:58:20 +03:00
|
|
|
glob(true, "*", "abc"),
|
2015-11-30 19:01:49 +03:00
|
|
|
glob(true, `\*`, "*"),
|
2015-11-30 17:58:20 +03:00
|
|
|
glob(true, "**", "a.b.c", "."),
|
|
|
|
|
|
|
|
glob(false, "?at", "at"),
|
2015-11-30 18:24:20 +03:00
|
|
|
glob(false, "?at", "fat", "f"),
|
2015-11-30 17:58:20 +03:00
|
|
|
glob(false, "a.*", "a.b.c", "."),
|
|
|
|
glob(false, "a.?.c", "a.bb.c", "."),
|
|
|
|
glob(false, "*", "a.b.c", "."),
|
|
|
|
|
|
|
|
glob(true, "*test", "this is a test"),
|
|
|
|
glob(true, "this*", "this is a test"),
|
|
|
|
glob(true, "*is *", "this is a test"),
|
|
|
|
glob(true, "*is*a*", "this is a test"),
|
|
|
|
glob(true, "**test**", "this is a test"),
|
|
|
|
glob(true, "**is**a***test*", "this is a test"),
|
|
|
|
|
|
|
|
glob(false, "*is", "this is a test"),
|
|
|
|
glob(false, "*no*", "this is a test"),
|
2016-01-08 20:14:31 +03:00
|
|
|
glob(true, "[!a]*", "this is a test3"),
|
|
|
|
|
2016-01-09 02:34:41 +03:00
|
|
|
glob(true, "*abc", "abcabc"),
|
2016-01-08 20:14:31 +03:00
|
|
|
glob(true, "**abc", "abcabc"),
|
2016-01-09 02:34:41 +03:00
|
|
|
glob(true, "???", "abc"),
|
|
|
|
glob(true, "?*?", "abc"),
|
|
|
|
glob(true, "?*?", "ac"),
|
2015-12-24 19:00:41 +03:00
|
|
|
|
2016-01-11 10:17:19 +03:00
|
|
|
glob(true, "{abc,def}ghi", "defghi"),
|
|
|
|
glob(true, "{abc,abcd}a", "abcda"),
|
|
|
|
glob(true, "{a,ab}{bc,f}", "abc"),
|
|
|
|
glob(true, "{*,**}{a,b}", "ab"),
|
|
|
|
glob(false, "{*,**}{a,b}", "ac"),
|
|
|
|
|
2016-01-20 21:05:54 +03:00
|
|
|
glob(true, pattern_all, fixture_all_match),
|
|
|
|
glob(false, pattern_all, fixture_all_mismatch),
|
|
|
|
|
|
|
|
glob(true, pattern_plain, fixture_plain_match),
|
|
|
|
glob(false, pattern_plain, fixture_plain_mismatch),
|
|
|
|
|
|
|
|
glob(true, pattern_multiple, fixture_multiple_match),
|
|
|
|
glob(false, pattern_multiple, fixture_multiple_mismatch),
|
|
|
|
|
|
|
|
glob(true, pattern_alternatives, fixture_alternatives_match),
|
|
|
|
glob(false, pattern_alternatives, fixture_alternatives_mismatch),
|
|
|
|
|
|
|
|
glob(true, pattern_alternatives_suffix, fixture_alternatives_suffix_first_match),
|
|
|
|
glob(false, pattern_alternatives_suffix, fixture_alternatives_suffix_first_mismatch),
|
2016-01-15 19:50:12 +03:00
|
|
|
glob(true, pattern_alternatives_suffix, fixture_alternatives_suffix_second),
|
2016-01-20 21:05:54 +03:00
|
|
|
|
2016-01-15 19:50:12 +03:00
|
|
|
glob(true, pattern_alternatives_combine_hard, fixture_alternatives_combine_hard),
|
2016-01-20 21:05:54 +03:00
|
|
|
|
2016-01-15 19:50:12 +03:00
|
|
|
glob(true, pattern_alternatives_combine_lite, fixture_alternatives_combine_lite),
|
2016-01-20 21:05:54 +03:00
|
|
|
|
|
|
|
glob(true, pattern_prefix, fixture_prefix_suffix_match),
|
|
|
|
glob(false, pattern_prefix, fixture_prefix_suffix_mismatch),
|
|
|
|
|
|
|
|
glob(true, pattern_suffix, fixture_prefix_suffix_match),
|
|
|
|
glob(false, pattern_suffix, fixture_prefix_suffix_mismatch),
|
|
|
|
|
|
|
|
glob(true, pattern_prefix_suffix, fixture_prefix_suffix_match),
|
|
|
|
glob(false, pattern_prefix_suffix, fixture_prefix_suffix_mismatch),
|
2015-11-30 19:21:30 +03:00
|
|
|
} {
|
2016-01-08 20:14:31 +03:00
|
|
|
g, err := Compile(test.pattern, test.delimiters...)
|
2015-12-24 17:54:54 +03:00
|
|
|
if err != nil {
|
2015-12-24 19:00:41 +03:00
|
|
|
t.Errorf("parsing pattern %q error: %s", test.pattern, err)
|
2015-12-24 17:54:54 +03:00
|
|
|
continue
|
|
|
|
}
|
2015-11-30 17:58:20 +03:00
|
|
|
|
|
|
|
result := g.Match(test.match)
|
|
|
|
if result != test.should {
|
2016-01-11 10:17:19 +03:00
|
|
|
t.Errorf("pattern %q matching %q should be %v but got %v\n%s", test.pattern, test.match, test.should, result, g)
|
2015-11-30 17:58:20 +03:00
|
|
|
}
|
2016-01-20 21:05:54 +03:00
|
|
|
|
|
|
|
// if len(test.delimiters) == 0 || (len(test.delimiters) == 1 && test.delimiters[0] == string(filepath.Separator)) {
|
|
|
|
// result, err = filepath.Match(test.pattern, test.match)
|
|
|
|
// if err != nil {
|
|
|
|
// t.Errorf("[filepath] error matching pattern %q: %s", test.pattern, err)
|
|
|
|
// continue
|
|
|
|
// }
|
|
|
|
// if result != test.should {
|
|
|
|
// t.Errorf("[filepath] pattern %q matching %q should be %v but got %v\n%s", test.pattern, test.match, test.should, result, g)
|
|
|
|
// }
|
|
|
|
// }
|
2015-11-30 17:58:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-20 21:05:54 +03:00
|
|
|
func BenchmarkParseGlob(b *testing.B) {
|
2015-12-01 17:22:17 +03:00
|
|
|
for i := 0; i < b.N; i++ {
|
2016-01-08 20:14:31 +03:00
|
|
|
Compile(pattern_all)
|
2015-12-01 17:22:17 +03:00
|
|
|
}
|
|
|
|
}
|
2016-01-19 20:52:32 +03:00
|
|
|
func BenchmarkParseRegexp(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
regexp.MustCompile(regexp_all)
|
|
|
|
}
|
|
|
|
}
|
2015-11-30 17:58:20 +03:00
|
|
|
|
2016-01-20 21:05:54 +03:00
|
|
|
func BenchmarkAllGlobMatch(b *testing.B) {
|
|
|
|
m, _ := Compile(pattern_all)
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
_ = m.Match(fixture_all_match)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func BenchmarkAllRegexpMatch(b *testing.B) {
|
|
|
|
m := regexp.MustCompile(regexp_all)
|
|
|
|
f := []byte(fixture_all_match)
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
_ = m.Match(f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func BenchmarkAllGlobMismatch(b *testing.B) {
|
2016-01-08 20:14:31 +03:00
|
|
|
m, _ := Compile(pattern_all)
|
2015-11-30 17:58:20 +03:00
|
|
|
|
2015-11-30 18:24:20 +03:00
|
|
|
for i := 0; i < b.N; i++ {
|
2016-01-20 21:05:54 +03:00
|
|
|
_ = m.Match(fixture_all_mismatch)
|
2015-11-30 17:58:20 +03:00
|
|
|
}
|
|
|
|
}
|
2016-01-20 21:05:54 +03:00
|
|
|
func BenchmarkAllRegexpMismatch(b *testing.B) {
|
2016-01-19 20:52:32 +03:00
|
|
|
m := regexp.MustCompile(regexp_all)
|
2016-01-20 21:05:54 +03:00
|
|
|
f := []byte(fixture_all_mismatch)
|
2016-01-19 20:52:32 +03:00
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
_ = m.Match(f)
|
|
|
|
}
|
|
|
|
}
|
2015-12-01 17:22:17 +03:00
|
|
|
|
2016-01-20 21:05:54 +03:00
|
|
|
func BenchmarkMultipleGlobMatch(b *testing.B) {
|
|
|
|
m, _ := Compile(pattern_multiple)
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
_ = m.Match(fixture_multiple_match)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func BenchmarkMultipleRegexpMatch(b *testing.B) {
|
|
|
|
m := regexp.MustCompile(regexp_multiple)
|
|
|
|
f := []byte(fixture_multiple_match)
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
_ = m.Match(f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func BenchmarkMultipleGlobMismatch(b *testing.B) {
|
2016-01-08 20:14:31 +03:00
|
|
|
m, _ := Compile(pattern_multiple)
|
2015-12-01 17:22:17 +03:00
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
2016-01-20 21:05:54 +03:00
|
|
|
_ = m.Match(fixture_multiple_mismatch)
|
2015-12-01 17:22:17 +03:00
|
|
|
}
|
|
|
|
}
|
2016-01-20 21:05:54 +03:00
|
|
|
func BenchmarkMultipleRegexpMismatch(b *testing.B) {
|
2016-01-19 20:52:32 +03:00
|
|
|
m := regexp.MustCompile(regexp_multiple)
|
2016-01-20 21:05:54 +03:00
|
|
|
f := []byte(fixture_multiple_mismatch)
|
2016-01-19 20:52:32 +03:00
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
_ = m.Match(f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-20 21:05:54 +03:00
|
|
|
func BenchmarkAlternativesGlobMatch(b *testing.B) {
|
2016-01-09 02:34:41 +03:00
|
|
|
m, _ := Compile(pattern_alternatives)
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
2016-01-20 21:05:54 +03:00
|
|
|
_ = m.Match(fixture_alternatives_match)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func BenchmarkAlternativesGlobMismatch(b *testing.B) {
|
|
|
|
m, _ := Compile(pattern_alternatives)
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
_ = m.Match(fixture_alternatives_mismatch)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func BenchmarkAlternativesRegexpMatch(b *testing.B) {
|
|
|
|
m := regexp.MustCompile(regexp_alternatives)
|
|
|
|
f := []byte(fixture_alternatives_match)
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
_ = m.Match(f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func BenchmarkAlternativesRegexpMismatch(b *testing.B) {
|
|
|
|
m := regexp.MustCompile(regexp_alternatives)
|
|
|
|
f := []byte(fixture_alternatives_mismatch)
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
_ = m.Match(f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkAlternativesSuffixFirstGlobMatch(b *testing.B) {
|
|
|
|
m, _ := Compile(pattern_alternatives_suffix)
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
_ = m.Match(fixture_alternatives_suffix_first_match)
|
2016-01-09 02:34:41 +03:00
|
|
|
}
|
|
|
|
}
|
2016-01-20 21:05:54 +03:00
|
|
|
func BenchmarkAlternativesSuffixFirstGlobMismatch(b *testing.B) {
|
2016-01-15 19:50:12 +03:00
|
|
|
m, _ := Compile(pattern_alternatives_suffix)
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
2016-01-20 21:05:54 +03:00
|
|
|
_ = m.Match(fixture_alternatives_suffix_first_mismatch)
|
2016-01-15 19:50:12 +03:00
|
|
|
}
|
|
|
|
}
|
2016-01-20 21:05:54 +03:00
|
|
|
func BenchmarkAlternativesSuffixSecondGlobMatch(b *testing.B) {
|
2016-01-15 19:50:12 +03:00
|
|
|
m, _ := Compile(pattern_alternatives_suffix)
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
_ = m.Match(fixture_alternatives_suffix_second)
|
|
|
|
}
|
|
|
|
}
|
2016-01-20 21:05:54 +03:00
|
|
|
func BenchmarkAlternativesCombineLiteGlobMatch(b *testing.B) {
|
2016-01-15 19:50:12 +03:00
|
|
|
m, _ := Compile(pattern_alternatives_combine_lite)
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
_ = m.Match(fixture_alternatives_combine_lite)
|
|
|
|
}
|
|
|
|
}
|
2016-01-20 21:05:54 +03:00
|
|
|
func BenchmarkAlternativesCombineHardGlobMatch(b *testing.B) {
|
2016-01-15 19:50:12 +03:00
|
|
|
m, _ := Compile(pattern_alternatives_combine_hard)
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
_ = m.Match(fixture_alternatives_combine_hard)
|
|
|
|
}
|
|
|
|
}
|
2016-01-20 21:05:54 +03:00
|
|
|
func BenchmarkAlternativesSuffixFirstRegexpMatch(b *testing.B) {
|
|
|
|
m := regexp.MustCompile(regexp_alternatives_suffix)
|
|
|
|
f := []byte(fixture_alternatives_suffix_first_match)
|
2016-01-19 20:52:32 +03:00
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
_ = m.Match(f)
|
|
|
|
}
|
|
|
|
}
|
2016-01-20 21:05:54 +03:00
|
|
|
func BenchmarkAlternativesSuffixFirstRegexpMismatch(b *testing.B) {
|
2016-01-19 20:52:32 +03:00
|
|
|
m := regexp.MustCompile(regexp_alternatives_suffix)
|
2016-01-20 21:05:54 +03:00
|
|
|
f := []byte(fixture_alternatives_suffix_first_mismatch)
|
2016-01-19 20:52:32 +03:00
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
_ = m.Match(f)
|
|
|
|
}
|
|
|
|
}
|
2016-01-20 21:05:54 +03:00
|
|
|
func BenchmarkAlternativesSuffixSecondRegexpMatch(b *testing.B) {
|
2016-01-19 20:52:32 +03:00
|
|
|
m := regexp.MustCompile(regexp_alternatives_suffix)
|
|
|
|
f := []byte(fixture_alternatives_suffix_second)
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
_ = m.Match(f)
|
|
|
|
}
|
|
|
|
}
|
2016-01-20 21:05:54 +03:00
|
|
|
func BenchmarkAlternativesCombineLiteRegexpMatch(b *testing.B) {
|
2016-01-19 20:52:32 +03:00
|
|
|
m := regexp.MustCompile(regexp_alternatives_combine_lite)
|
|
|
|
f := []byte(fixture_alternatives_combine_lite)
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
_ = m.Match(f)
|
|
|
|
}
|
|
|
|
}
|
2016-01-20 21:05:54 +03:00
|
|
|
func BenchmarkAlternativesCombineHardRegexpMatch(b *testing.B) {
|
2016-01-19 20:52:32 +03:00
|
|
|
m := regexp.MustCompile(regexp_alternatives_combine_hard)
|
|
|
|
f := []byte(fixture_alternatives_combine_hard)
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
_ = m.Match(f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-20 21:05:54 +03:00
|
|
|
func BenchmarkPlainGlobMatch(b *testing.B) {
|
2016-01-08 20:14:31 +03:00
|
|
|
m, _ := Compile(pattern_plain)
|
2015-12-01 17:22:17 +03:00
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
2016-01-20 21:05:54 +03:00
|
|
|
_ = m.Match(fixture_plain_match)
|
2015-12-01 17:22:17 +03:00
|
|
|
}
|
|
|
|
}
|
2016-01-20 21:05:54 +03:00
|
|
|
func BenchmarkPlainRegexpMatch(b *testing.B) {
|
2016-01-19 20:52:32 +03:00
|
|
|
m := regexp.MustCompile(regexp_plain)
|
2016-01-20 21:05:54 +03:00
|
|
|
f := []byte(fixture_plain_match)
|
2016-01-19 20:52:32 +03:00
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
_ = m.Match(f)
|
|
|
|
}
|
|
|
|
}
|
2016-01-20 21:05:54 +03:00
|
|
|
func BenchmarkPlainGlobMismatch(b *testing.B) {
|
|
|
|
m, _ := Compile(pattern_plain)
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
_ = m.Match(fixture_plain_mismatch)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func BenchmarkPlainRegexpMismatch(b *testing.B) {
|
|
|
|
m := regexp.MustCompile(regexp_plain)
|
|
|
|
f := []byte(fixture_plain_mismatch)
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
_ = m.Match(f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkPrefixGlobMatch(b *testing.B) {
|
|
|
|
m, _ := Compile(pattern_prefix)
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
_ = m.Match(fixture_prefix_suffix_match)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func BenchmarkPrefixRegexpMatch(b *testing.B) {
|
|
|
|
m := regexp.MustCompile(regexp_prefix)
|
|
|
|
f := []byte(fixture_prefix_suffix_match)
|
2016-01-19 20:52:32 +03:00
|
|
|
|
2016-01-20 21:05:54 +03:00
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
_ = m.Match(f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func BenchmarkPrefixGlobMismatch(b *testing.B) {
|
2016-01-08 20:14:31 +03:00
|
|
|
m, _ := Compile(pattern_prefix)
|
2015-12-01 17:22:17 +03:00
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
2016-01-20 21:05:54 +03:00
|
|
|
_ = m.Match(fixture_prefix_suffix_mismatch)
|
2015-12-01 17:22:17 +03:00
|
|
|
}
|
|
|
|
}
|
2016-01-20 21:05:54 +03:00
|
|
|
func BenchmarkPrefixRegexpMismatch(b *testing.B) {
|
2016-01-19 20:52:32 +03:00
|
|
|
m := regexp.MustCompile(regexp_prefix)
|
2016-01-20 21:05:54 +03:00
|
|
|
f := []byte(fixture_prefix_suffix_mismatch)
|
2016-01-19 20:52:32 +03:00
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
_ = m.Match(f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-20 21:05:54 +03:00
|
|
|
func BenchmarkSuffixGlobMatch(b *testing.B) {
|
2016-01-08 20:14:31 +03:00
|
|
|
m, _ := Compile(pattern_suffix)
|
2015-11-30 17:58:20 +03:00
|
|
|
|
2015-12-01 17:22:17 +03:00
|
|
|
for i := 0; i < b.N; i++ {
|
2016-01-20 21:05:54 +03:00
|
|
|
_ = m.Match(fixture_prefix_suffix_match)
|
2015-12-01 17:22:17 +03:00
|
|
|
}
|
|
|
|
}
|
2016-01-20 21:05:54 +03:00
|
|
|
func BenchmarkSuffixRegexpMatch(b *testing.B) {
|
2016-01-19 20:52:32 +03:00
|
|
|
m := regexp.MustCompile(regexp_suffix)
|
2016-01-20 21:05:54 +03:00
|
|
|
f := []byte(fixture_prefix_suffix_match)
|
2016-01-19 20:52:32 +03:00
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
_ = m.Match(f)
|
|
|
|
}
|
|
|
|
}
|
2016-01-20 21:05:54 +03:00
|
|
|
func BenchmarkSuffixGlobMismatch(b *testing.B) {
|
|
|
|
m, _ := Compile(pattern_suffix)
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
_ = m.Match(fixture_prefix_suffix_mismatch)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func BenchmarkSuffixRegexpMismatch(b *testing.B) {
|
|
|
|
m := regexp.MustCompile(regexp_suffix)
|
|
|
|
f := []byte(fixture_prefix_suffix_mismatch)
|
2016-01-19 20:52:32 +03:00
|
|
|
|
2016-01-20 21:05:54 +03:00
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
_ = m.Match(f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkPrefixSuffixGlobMatch(b *testing.B) {
|
2016-01-08 20:14:31 +03:00
|
|
|
m, _ := Compile(pattern_prefix_suffix)
|
2015-12-01 17:22:17 +03:00
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
2016-01-20 21:05:54 +03:00
|
|
|
_ = m.Match(fixture_prefix_suffix_match)
|
2015-12-01 17:22:17 +03:00
|
|
|
}
|
2016-01-08 20:14:31 +03:00
|
|
|
}
|
2016-01-20 21:05:54 +03:00
|
|
|
func BenchmarkPrefixSuffixRegexpMatch(b *testing.B) {
|
2016-01-19 20:52:32 +03:00
|
|
|
m := regexp.MustCompile(regexp_prefix_suffix)
|
2016-01-20 21:05:54 +03:00
|
|
|
f := []byte(fixture_prefix_suffix_match)
|
2016-01-19 20:52:32 +03:00
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
_ = m.Match(f)
|
|
|
|
}
|
|
|
|
}
|
2016-01-20 21:05:54 +03:00
|
|
|
func BenchmarkPrefixSuffixGlobMismatch(b *testing.B) {
|
|
|
|
m, _ := Compile(pattern_prefix_suffix)
|
2016-01-09 02:34:41 +03:00
|
|
|
|
2016-01-20 21:05:54 +03:00
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
_ = m.Match(fixture_prefix_suffix_mismatch)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func BenchmarkPrefixSuffixRegexpMismatch(b *testing.B) {
|
|
|
|
m := regexp.MustCompile(regexp_prefix_suffix)
|
|
|
|
f := []byte(fixture_prefix_suffix_mismatch)
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
_ = m.Match(f)
|
|
|
|
}
|
|
|
|
}
|