github.com/Uhtred009/v2ray-core-1@v4.31.2+incompatible/common/strmatcher/matchers_test.go (about)

     1  package strmatcher_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"v2ray.com/core/common"
     7  	. "v2ray.com/core/common/strmatcher"
     8  )
     9  
    10  func TestMatcher(t *testing.T) {
    11  	cases := []struct {
    12  		pattern string
    13  		mType   Type
    14  		input   string
    15  		output  bool
    16  	}{
    17  		{
    18  			pattern: "v2ray.com",
    19  			mType:   Domain,
    20  			input:   "www.v2ray.com",
    21  			output:  true,
    22  		},
    23  		{
    24  			pattern: "v2ray.com",
    25  			mType:   Domain,
    26  			input:   "v2ray.com",
    27  			output:  true,
    28  		},
    29  		{
    30  			pattern: "v2ray.com",
    31  			mType:   Domain,
    32  			input:   "www.v3ray.com",
    33  			output:  false,
    34  		},
    35  		{
    36  			pattern: "v2ray.com",
    37  			mType:   Domain,
    38  			input:   "2ray.com",
    39  			output:  false,
    40  		},
    41  		{
    42  			pattern: "v2ray.com",
    43  			mType:   Domain,
    44  			input:   "xv2ray.com",
    45  			output:  false,
    46  		},
    47  		{
    48  			pattern: "v2ray.com",
    49  			mType:   Full,
    50  			input:   "v2ray.com",
    51  			output:  true,
    52  		},
    53  		{
    54  			pattern: "v2ray.com",
    55  			mType:   Full,
    56  			input:   "xv2ray.com",
    57  			output:  false,
    58  		},
    59  		{
    60  			pattern: "v2ray.com",
    61  			mType:   Regex,
    62  			input:   "v2rayxcom",
    63  			output:  true,
    64  		},
    65  	}
    66  	for _, test := range cases {
    67  		matcher, err := test.mType.New(test.pattern)
    68  		common.Must(err)
    69  		if m := matcher.Match(test.input); m != test.output {
    70  			t.Error("unexpected output: ", m, " for test case ", test)
    71  		}
    72  	}
    73  }