mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-03 07:56:42 -05:00
d4da365c5f
* Reorganize strmatcher's package structure * Rename types in strmatcher package according to their file names * Stablize strmatcher's Matcher interface * Implement []matcherEntry as SimpleMatcherGroup * Implement mph algorithm extracted from MphIndexMatcher as MphMatcherGroup * Implement AddMatcher/AddFullMatcher/AddDomainMatcher/AddSubstrMatcher for each MatcherGroup * Stablize strmatcher's MatcherGroup interface * Stablize strmatcher's IndexMatcher interface * Update strmatcher's benchmark * Compatibility fix for app/router's DomainMatcher condition * Fix code quality issue * Fix basic matcher issues * Update priority specification for Substr matcher
74 lines
1.2 KiB
Go
74 lines
1.2 KiB
Go
package strmatcher_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/v2fly/v2ray-core/v4/common"
|
|
. "github.com/v2fly/v2ray-core/v4/common/strmatcher"
|
|
)
|
|
|
|
func TestMatcher(t *testing.T) {
|
|
cases := []struct {
|
|
pattern string
|
|
mType Type
|
|
input string
|
|
output bool
|
|
}{
|
|
{
|
|
pattern: "v2fly.org",
|
|
mType: Domain,
|
|
input: "www.v2fly.org",
|
|
output: true,
|
|
},
|
|
{
|
|
pattern: "v2fly.org",
|
|
mType: Domain,
|
|
input: "v2fly.org",
|
|
output: true,
|
|
},
|
|
{
|
|
pattern: "v2fly.org",
|
|
mType: Domain,
|
|
input: "www.v3fly.org",
|
|
output: false,
|
|
},
|
|
{
|
|
pattern: "v2fly.org",
|
|
mType: Domain,
|
|
input: "2fly.org",
|
|
output: false,
|
|
},
|
|
{
|
|
pattern: "v2fly.org",
|
|
mType: Domain,
|
|
input: "xv2fly.org",
|
|
output: false,
|
|
},
|
|
{
|
|
pattern: "v2fly.org",
|
|
mType: Full,
|
|
input: "v2fly.org",
|
|
output: true,
|
|
},
|
|
{
|
|
pattern: "v2fly.org",
|
|
mType: Full,
|
|
input: "xv2fly.org",
|
|
output: false,
|
|
},
|
|
{
|
|
pattern: "v2fly.org",
|
|
mType: Regex,
|
|
input: "v2flyxorg",
|
|
output: true,
|
|
},
|
|
}
|
|
for _, test := range cases {
|
|
matcher, err := test.mType.New(test.pattern)
|
|
common.Must(err)
|
|
if m := matcher.Match(test.input); m != test.output {
|
|
t.Error("unexpected output: ", m, " for test case ", test)
|
|
}
|
|
}
|
|
}
|