2021-10-14 05:13:19 +00:00
|
|
|
package yqlib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDeepMatch(t *testing.T) {
|
|
|
|
var tests = []struct {
|
|
|
|
name string
|
|
|
|
pattern string
|
|
|
|
ok bool
|
|
|
|
}{
|
|
|
|
{"", "", true},
|
2024-02-09 06:24:59 +00:00
|
|
|
{"<<", "<<", true},
|
2021-10-14 05:13:19 +00:00
|
|
|
{"", "x", false},
|
|
|
|
{"x", "", false},
|
|
|
|
{"abc", "abc", true},
|
|
|
|
{"abc", "*", true},
|
|
|
|
{"abc", "*c", true},
|
|
|
|
{"abc", "*b", false},
|
|
|
|
{"abc", "a*", true},
|
|
|
|
{"abc", "b*", false},
|
|
|
|
{"a", "a*", true},
|
|
|
|
{"a", "*a", true},
|
|
|
|
{"axbxcxdxe", "a*b*c*d*e*", true},
|
|
|
|
{"axbxcxdxexxx", "a*b*c*d*e*", true},
|
|
|
|
{"abxbbxdbxebxczzx", "a*b?c*x", true},
|
|
|
|
{"abxbbxdbxebxczzy", "a*b?c*x", false},
|
|
|
|
{strings.Repeat("a", 100), "a*a*a*a*b", false},
|
|
|
|
{"xxx", "*x", true},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name+" "+tt.pattern, func(t *testing.T) {
|
|
|
|
if want, got := tt.ok, deepMatch(tt.name, tt.pattern); want != got {
|
|
|
|
t.Errorf("Expected %v got %v", want, got)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|