Xray-core/common/matcher/str/full_matcher_test.go

51 lines
903 B
Go
Raw Normal View History

2021-03-24 15:01:20 +00:00
package str_test
2020-11-25 11:01:53 +00:00
import (
"reflect"
"testing"
2021-03-24 15:01:20 +00:00
. "github.com/xtls/xray-core/common/matcher/str"
2020-11-25 11:01:53 +00:00
)
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)
}
}