domain_matcher_test.go 753 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package strmatcher_test
  2. import (
  3. "testing"
  4. . "v2ray.com/core/common/strmatcher"
  5. )
  6. func TestDomainMatcherGroup(t *testing.T) {
  7. g := new(DomainMatcherGroup)
  8. g.Add("v2ray.com", 1)
  9. g.Add("google.com", 2)
  10. g.Add("x.a.com", 3)
  11. testCases := []struct {
  12. Domain string
  13. Result uint32
  14. }{
  15. {
  16. Domain: "x.v2ray.com",
  17. Result: 1,
  18. },
  19. {
  20. Domain: "y.com",
  21. Result: 0,
  22. },
  23. }
  24. for _, testCase := range testCases {
  25. r := g.Match(testCase.Domain)
  26. if r != testCase.Result {
  27. t.Error("Failed to match domain: ", testCase.Domain, ", expect ", testCase.Result, ", but got ", r)
  28. }
  29. }
  30. }
  31. func TestEmptyDomainMatcherGroup(t *testing.T) {
  32. g := new(DomainMatcherGroup)
  33. r := g.Match("v2ray.com")
  34. if r != 0 {
  35. t.Error("Expect 0, but ", r)
  36. }
  37. }