github.com/xraypb/xray-core@v1.6.6/common/strmatcher/full_matcher_test.go (about)

     1  package strmatcher_test
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  
     7  	. "github.com/xraypb/xray-core/common/strmatcher"
     8  )
     9  
    10  func TestFullMatcherGroup(t *testing.T) {
    11  	g := new(FullMatcherGroup)
    12  	g.Add("example.com", 1)
    13  	g.Add("google.com", 2)
    14  	g.Add("x.a.com", 3)
    15  	g.Add("x.y.com", 4)
    16  	g.Add("x.y.com", 6)
    17  
    18  	testCases := []struct {
    19  		Domain string
    20  		Result []uint32
    21  	}{
    22  		{
    23  			Domain: "example.com",
    24  			Result: []uint32{1},
    25  		},
    26  		{
    27  			Domain: "y.com",
    28  			Result: nil,
    29  		},
    30  		{
    31  			Domain: "x.y.com",
    32  			Result: []uint32{4, 6},
    33  		},
    34  	}
    35  
    36  	for _, testCase := range testCases {
    37  		r := g.Match(testCase.Domain)
    38  		if !reflect.DeepEqual(r, testCase.Result) {
    39  			t.Error("Failed to match domain: ", testCase.Domain, ", expect ", testCase.Result, ", but got ", r)
    40  		}
    41  	}
    42  }
    43  
    44  func TestEmptyFullMatcherGroup(t *testing.T) {
    45  	g := new(FullMatcherGroup)
    46  	r := g.Match("example.com")
    47  	if len(r) != 0 {
    48  		t.Error("Expect [], but ", r)
    49  	}
    50  }