1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-10 14:26:26 -05:00
v2fly/common/strmatcher/matchergroup_full_test.go

72 lines
1.2 KiB
Go
Raw Normal View History

2018-08-20 03:57:06 -04:00
package strmatcher_test
import (
"reflect"
2018-08-20 03:57:06 -04:00
"testing"
. "github.com/v2fly/v2ray-core/v5/common/strmatcher"
2018-08-20 03:57:06 -04:00
)
func TestFullMatcherGroup(t *testing.T) {
patterns := []struct {
Pattern string
Value uint32
}{
{
Pattern: "v2fly.org",
Value: 1,
},
{
Pattern: "google.com",
Value: 2,
},
{
Pattern: "x.a.com",
Value: 3,
},
{
Pattern: "x.y.com",
Value: 4,
},
{
Pattern: "x.y.com",
Value: 6,
},
}
2018-08-20 03:57:06 -04:00
testCases := []struct {
Domain string
Result []uint32
2018-08-20 03:57:06 -04:00
}{
{
2021-02-16 15:31:50 -05:00
Domain: "v2fly.org",
Result: []uint32{1},
2018-08-20 03:57:06 -04:00
},
{
Domain: "y.com",
Result: nil,
},
{
Domain: "x.y.com",
Result: []uint32{4, 6},
2018-08-20 03:57:06 -04:00
},
}
g := NewFullMatcherGroup()
for _, pattern := range patterns {
AddMatcherToGroup(g, FullMatcher(pattern.Pattern), pattern.Value)
}
2018-08-20 03:57:06 -04:00
for _, testCase := range testCases {
r := g.Match(testCase.Domain)
if !reflect.DeepEqual(r, testCase.Result) {
2018-08-20 03:57:06 -04:00
t.Error("Failed to match domain: ", testCase.Domain, ", expect ", testCase.Result, ", but got ", r)
}
}
}
func TestEmptyFullMatcherGroup(t *testing.T) {
g := NewFullMatcherGroup()
2021-02-16 15:31:50 -05:00
r := g.Match("v2fly.org")
if len(r) != 0 {
t.Error("Expect [], but ", r)
2018-08-20 03:57:06 -04:00
}
}