mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-30 17:38:41 +00:00
v1.0.0
This commit is contained in:
parent
47d23e9972
commit
c7f7c08ead
711 changed files with 82154 additions and 2 deletions
73
common/strmatcher/matchers_test.go
Normal file
73
common/strmatcher/matchers_test.go
Normal file
|
@ -0,0 +1,73 @@
|
|||
package strmatcher_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/xtls/xray-core/v1/common"
|
||||
. "github.com/xtls/xray-core/v1/common/strmatcher"
|
||||
)
|
||||
|
||||
func TestMatcher(t *testing.T) {
|
||||
cases := []struct {
|
||||
pattern string
|
||||
mType Type
|
||||
input string
|
||||
output bool
|
||||
}{
|
||||
{
|
||||
pattern: "example.com",
|
||||
mType: Domain,
|
||||
input: "www.example.com",
|
||||
output: true,
|
||||
},
|
||||
{
|
||||
pattern: "example.com",
|
||||
mType: Domain,
|
||||
input: "example.com",
|
||||
output: true,
|
||||
},
|
||||
{
|
||||
pattern: "example.com",
|
||||
mType: Domain,
|
||||
input: "www.fxample.com",
|
||||
output: false,
|
||||
},
|
||||
{
|
||||
pattern: "example.com",
|
||||
mType: Domain,
|
||||
input: "xample.com",
|
||||
output: false,
|
||||
},
|
||||
{
|
||||
pattern: "example.com",
|
||||
mType: Domain,
|
||||
input: "xexample.com",
|
||||
output: false,
|
||||
},
|
||||
{
|
||||
pattern: "example.com",
|
||||
mType: Full,
|
||||
input: "example.com",
|
||||
output: true,
|
||||
},
|
||||
{
|
||||
pattern: "example.com",
|
||||
mType: Full,
|
||||
input: "xexample.com",
|
||||
output: false,
|
||||
},
|
||||
{
|
||||
pattern: "example.com",
|
||||
mType: Regex,
|
||||
input: "examplexcom",
|
||||
output: true,
|
||||
},
|
||||
}
|
||||
for _, test := range cases {
|
||||
matcher, err := test.mType.New(test.pattern)
|
||||
common.Must(err)
|
||||
if m := matcher.Match(test.input); m != test.output {
|
||||
t.Error("unexpected output: ", m, " for test case ", test)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue