1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 01:57:12 -05:00
v2fly/common/strmatcher/matchergroup_simple_test.go
Ye Zhihao d4da365c5f
Refactor: strmatcher module (#1333)
* 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
2021-10-31 18:01:13 +08:00

70 lines
1.2 KiB
Go

package strmatcher_test
import (
"reflect"
"testing"
"github.com/v2fly/v2ray-core/v4/common"
. "github.com/v2fly/v2ray-core/v4/common/strmatcher"
)
func TestSimpleMatcherGroup(t *testing.T) {
patterns := []struct {
pattern string
mType Type
}{
{
pattern: "v2fly.org",
mType: Domain,
},
{
pattern: "v2fly.org",
mType: Full,
},
{
pattern: "v2fly.org",
mType: Regex,
},
}
cases := []struct {
input string
output []uint32
}{
{
input: "www.v2fly.org",
output: []uint32{0, 2},
},
{
input: "v2fly.org",
output: []uint32{0, 1, 2},
},
{
input: "www.v3fly.org",
output: []uint32{},
},
{
input: "2fly.org",
output: []uint32{},
},
{
input: "xv2fly.org",
output: []uint32{2},
},
{
input: "v2flyxorg",
output: []uint32{2},
},
}
matcherGroup := &SimpleMatcherGroup{}
for id, entry := range patterns {
matcher, err := entry.mType.New(entry.pattern)
common.Must(err)
common.Must(AddMatcherToGroup(matcherGroup, matcher, uint32(id)))
}
for _, test := range cases {
if r := matcherGroup.Match(test.input); !reflect.DeepEqual(r, test.output) {
t.Error("unexpected output: ", r, " for test case ", test)
}
}
}