2018-06-26 15:57:41 -04:00
|
|
|
package strmatcher_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"v2ray.com/core/common"
|
|
|
|
. "v2ray.com/core/common/strmatcher"
|
|
|
|
ast "v2ray.com/ext/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMatcher(t *testing.T) {
|
|
|
|
assert := ast.With(t)
|
|
|
|
|
|
|
|
cases := []struct {
|
|
|
|
pattern string
|
|
|
|
mType Type
|
|
|
|
input string
|
|
|
|
output bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
pattern: "v2ray.com",
|
|
|
|
mType: Domain,
|
|
|
|
input: "www.v2ray.com",
|
|
|
|
output: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "v2ray.com",
|
|
|
|
mType: Domain,
|
|
|
|
input: "v2ray.com",
|
|
|
|
output: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "v2ray.com",
|
|
|
|
mType: Domain,
|
|
|
|
input: "www.v3ray.com",
|
|
|
|
output: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "v2ray.com",
|
|
|
|
mType: Domain,
|
|
|
|
input: "2ray.com",
|
|
|
|
output: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "v2ray.com",
|
|
|
|
mType: Domain,
|
|
|
|
input: "xv2ray.com",
|
|
|
|
output: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "v2ray.com",
|
|
|
|
mType: Full,
|
|
|
|
input: "v2ray.com",
|
|
|
|
output: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "v2ray.com",
|
|
|
|
mType: Full,
|
|
|
|
input: "xv2ray.com",
|
|
|
|
output: false,
|
|
|
|
},
|
2018-08-20 09:39:58 -04:00
|
|
|
{
|
|
|
|
pattern: "v2ray.com",
|
|
|
|
mType: Regex,
|
|
|
|
input: "v2rayxcom",
|
|
|
|
output: true,
|
|
|
|
},
|
2018-06-26 15:57:41 -04:00
|
|
|
}
|
|
|
|
for _, test := range cases {
|
|
|
|
matcher, err := test.mType.New(test.pattern)
|
|
|
|
common.Must(err)
|
|
|
|
assert(matcher.Match(test.input) == test.output, ast.IsTrue)
|
|
|
|
}
|
|
|
|
}
|