mirror of https://github.com/gobwas/glob.git
fix tests
This commit is contained in:
parent
fa2b8d5017
commit
cd9e75ee86
|
@ -267,14 +267,6 @@ func BenchmarkAllRegexpMatch(b *testing.B) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAllGlobMismatch(t *testing.T) {
|
|
||||||
m := MustCompile(pattern_all)
|
|
||||||
fmt.Println("====")
|
|
||||||
fmt.Println(match.Graphviz(pattern_all, m.(match.Matcher)))
|
|
||||||
fmt.Println("====")
|
|
||||||
m.Match(fixture_all_mismatch)
|
|
||||||
}
|
|
||||||
|
|
||||||
func BenchmarkAllGlobMismatch(b *testing.B) {
|
func BenchmarkAllGlobMismatch(b *testing.B) {
|
||||||
m := MustCompile(pattern_all)
|
m := MustCompile(pattern_all)
|
||||||
fmt.Println(match.Graphviz(pattern_all, m.(match.Matcher)))
|
fmt.Println(match.Graphviz(pattern_all, m.(match.Matcher)))
|
||||||
|
|
|
@ -275,21 +275,25 @@ func glueMatchersAsEvery(ms []Matcher) Matcher {
|
||||||
type result struct {
|
type result struct {
|
||||||
ms []Matcher
|
ms []Matcher
|
||||||
matchers int
|
matchers int
|
||||||
minLen int
|
maxMinLen int
|
||||||
|
sumMinLen int
|
||||||
nesting int
|
nesting int
|
||||||
}
|
}
|
||||||
|
|
||||||
func compareResult(a, b result) int {
|
func compareResult(a, b result) int {
|
||||||
if x := b.minLen - a.minLen; x != 0 {
|
if x := b.sumMinLen - a.sumMinLen; x != 0 {
|
||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
if x := a.matchers - b.matchers; x != 0 {
|
if x := len(a.ms) - len(b.ms); x != 0 {
|
||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
if x := a.nesting - b.nesting; x != 0 {
|
if x := a.nesting - b.nesting; x != 0 {
|
||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
if x := len(a.ms) - len(b.ms); x != 0 {
|
if x := a.matchers - b.matchers; x != 0 {
|
||||||
|
return x
|
||||||
|
}
|
||||||
|
if x := b.maxMinLen - a.maxMinLen; x != 0 {
|
||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
|
@ -343,6 +347,13 @@ func maxMinLen(ms []Matcher) (max int) {
|
||||||
return max
|
return max
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func sumMinLen(ms []Matcher) (sum int) {
|
||||||
|
for _, m := range ms {
|
||||||
|
sum += m.MinLen()
|
||||||
|
}
|
||||||
|
return sum
|
||||||
|
}
|
||||||
|
|
||||||
func maxNestingDepth(ms []Matcher) (max int) {
|
func maxNestingDepth(ms []Matcher) (max int) {
|
||||||
for _, m := range ms {
|
for _, m := range ms {
|
||||||
if n := nestingDepth(m); n > max {
|
if n := nestingDepth(m); n > max {
|
||||||
|
@ -368,13 +379,14 @@ func minimize(ms []Matcher, i, j int, best *result) *result {
|
||||||
r := result{
|
r := result{
|
||||||
ms: cp,
|
ms: cp,
|
||||||
matchers: matchersCount(cp),
|
matchers: matchersCount(cp),
|
||||||
minLen: maxMinLen(cp),
|
sumMinLen: sumMinLen(cp),
|
||||||
|
maxMinLen: maxMinLen(cp),
|
||||||
nesting: maxNestingDepth(cp),
|
nesting: maxNestingDepth(cp),
|
||||||
}
|
}
|
||||||
if debug.Enabled {
|
if debug.Enabled {
|
||||||
debug.EnterPrefix(
|
debug.EnterPrefix(
|
||||||
"intermediate: %s (matchers:%d, minlen:%d, nesting:%d)",
|
"intermediate: %s (matchers:%d, summinlen:%d, maxminlen:%d, nesting:%d)",
|
||||||
cp, r.matchers, r.minLen, r.nesting,
|
cp, r.matchers, r.sumMinLen, r.maxMinLen, r.nesting,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if best == nil {
|
if best == nil {
|
||||||
|
|
|
@ -61,9 +61,9 @@ func TestCompile(t *testing.T) {
|
||||||
NewTree(
|
NewTree(
|
||||||
NewSingle(separators),
|
NewSingle(separators),
|
||||||
NewSuper(),
|
NewSuper(),
|
||||||
nil,
|
Nothing{},
|
||||||
),
|
),
|
||||||
nil,
|
Nothing{},
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,7 +19,7 @@ func TestTree(t *testing.T) {
|
||||||
{
|
{
|
||||||
NewTree(NewText("a"), NewSingle(nil), NewSingle(nil)),
|
NewTree(NewText("a"), NewSingle(nil), NewSingle(nil)),
|
||||||
"aaa",
|
"aaa",
|
||||||
false,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
NewTree(NewText("abc"), NewSuper(), NewSuper()),
|
NewTree(NewText("abc"), NewSuper(), NewSuper()),
|
||||||
|
@ -32,7 +32,7 @@ func TestTree(t *testing.T) {
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
NewTree(NewText("b"), NewSingle(nil), nil),
|
NewTree(NewText("b"), NewSingle(nil), Nothing{}),
|
||||||
"bbb",
|
"bbb",
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
|
@ -42,9 +42,9 @@ func TestTree(t *testing.T) {
|
||||||
NewTree(
|
NewTree(
|
||||||
NewSingle(nil),
|
NewSingle(nil),
|
||||||
NewSuper(),
|
NewSuper(),
|
||||||
nil,
|
Nothing{},
|
||||||
),
|
),
|
||||||
nil,
|
Nothing{},
|
||||||
),
|
),
|
||||||
"abc",
|
"abc",
|
||||||
true,
|
true,
|
||||||
|
|
Loading…
Reference in New Issue