github.com/EagleQL/Xray-core@v1.4.3/common/strmatcher/matchers_test.go (about) 1 package strmatcher_test 2 3 import ( 4 "testing" 5 6 "github.com/xtls/xray-core/common" 7 . "github.com/xtls/xray-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: "example.com", 19 mType: Domain, 20 input: "www.example.com", 21 output: true, 22 }, 23 { 24 pattern: "example.com", 25 mType: Domain, 26 input: "example.com", 27 output: true, 28 }, 29 { 30 pattern: "example.com", 31 mType: Domain, 32 input: "www.fxample.com", 33 output: false, 34 }, 35 { 36 pattern: "example.com", 37 mType: Domain, 38 input: "xample.com", 39 output: false, 40 }, 41 { 42 pattern: "example.com", 43 mType: Domain, 44 input: "xexample.com", 45 output: false, 46 }, 47 { 48 pattern: "example.com", 49 mType: Full, 50 input: "example.com", 51 output: true, 52 }, 53 { 54 pattern: "example.com", 55 mType: Full, 56 input: "xexample.com", 57 output: false, 58 }, 59 { 60 pattern: "example.com", 61 mType: Regex, 62 input: "examplexcom", 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 }