github.com/v2fly/v2ray-core/v5@v5.16.2-0.20240507031116-8191faa6e095/common/strmatcher/matchergroup_simple_test.go (about) 1 package strmatcher_test 2 3 import ( 4 "reflect" 5 "testing" 6 7 "github.com/v2fly/v2ray-core/v5/common" 8 . "github.com/v2fly/v2ray-core/v5/common/strmatcher" 9 ) 10 11 func TestSimpleMatcherGroup(t *testing.T) { 12 patterns := []struct { 13 pattern string 14 mType Type 15 }{ 16 { 17 pattern: "v2fly.org", 18 mType: Domain, 19 }, 20 { 21 pattern: "v2fly.org", 22 mType: Full, 23 }, 24 { 25 pattern: "v2fly.org", 26 mType: Regex, 27 }, 28 } 29 cases := []struct { 30 input string 31 output []uint32 32 }{ 33 { 34 input: "www.v2fly.org", 35 output: []uint32{0, 2}, 36 }, 37 { 38 input: "v2fly.org", 39 output: []uint32{0, 1, 2}, 40 }, 41 { 42 input: "www.v3fly.org", 43 output: []uint32{}, 44 }, 45 { 46 input: "2fly.org", 47 output: []uint32{}, 48 }, 49 { 50 input: "xv2fly.org", 51 output: []uint32{2}, 52 }, 53 { 54 input: "v2flyxorg", 55 output: []uint32{2}, 56 }, 57 } 58 matcherGroup := &SimpleMatcherGroup{} 59 for id, entry := range patterns { 60 matcher, err := entry.mType.New(entry.pattern) 61 common.Must(err) 62 common.Must(AddMatcherToGroup(matcherGroup, matcher, uint32(id))) 63 } 64 for _, test := range cases { 65 if r := matcherGroup.Match(test.input); !reflect.DeepEqual(r, test.output) { 66 t.Error("unexpected output: ", r, " for test case ", test) 67 } 68 } 69 }