matchers_test.go 1.1 KB

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