mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-30 01:08:33 +00:00
v1.0.0
This commit is contained in:
parent
47d23e9972
commit
c7f7c08ead
711 changed files with 82154 additions and 2 deletions
50
common/strmatcher/full_matcher_test.go
Normal file
50
common/strmatcher/full_matcher_test.go
Normal file
|
@ -0,0 +1,50 @@
|
|||
package strmatcher_test
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
. "github.com/xtls/xray-core/v1/common/strmatcher"
|
||||
)
|
||||
|
||||
func TestFullMatcherGroup(t *testing.T) {
|
||||
g := new(FullMatcherGroup)
|
||||
g.Add("example.com", 1)
|
||||
g.Add("google.com", 2)
|
||||
g.Add("x.a.com", 3)
|
||||
g.Add("x.y.com", 4)
|
||||
g.Add("x.y.com", 6)
|
||||
|
||||
testCases := []struct {
|
||||
Domain string
|
||||
Result []uint32
|
||||
}{
|
||||
{
|
||||
Domain: "example.com",
|
||||
Result: []uint32{1},
|
||||
},
|
||||
{
|
||||
Domain: "y.com",
|
||||
Result: nil,
|
||||
},
|
||||
{
|
||||
Domain: "x.y.com",
|
||||
Result: []uint32{4, 6},
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
r := g.Match(testCase.Domain)
|
||||
if !reflect.DeepEqual(r, testCase.Result) {
|
||||
t.Error("Failed to match domain: ", testCase.Domain, ", expect ", testCase.Result, ", but got ", r)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestEmptyFullMatcherGroup(t *testing.T) {
|
||||
g := new(FullMatcherGroup)
|
||||
r := g.Match("example.com")
|
||||
if len(r) != 0 {
|
||||
t.Error("Expect [], but ", r)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue