0
mirror of https://github.com/XTLS/Xray-core.git synced 2025-06-20 06:58:38 +03:00

Refactor: GeoSite & GeoIP

This commit is contained in:
JimhHan
2021-03-24 23:01:20 +08:00
parent 8382b29922
commit b11429eaee
54 changed files with 2110 additions and 1633 deletions

View File

@ -0,0 +1,73 @@
package str_test
import (
"testing"
"github.com/xtls/xray-core/common"
. "github.com/xtls/xray-core/common/matcher/str"
)
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)
}
}
}