full_matcher_test.go 909 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package strmatcher_test
  2. import (
  3. "reflect"
  4. "testing"
  5. . "github.com/xtls/xray-core/common/strmatcher"
  6. )
  7. func TestFullMatcherGroup(t *testing.T) {
  8. g := new(FullMatcherGroup)
  9. g.Add("example.com", 1)
  10. g.Add("google.com", 2)
  11. g.Add("x.a.com", 3)
  12. g.Add("x.y.com", 4)
  13. g.Add("x.y.com", 6)
  14. testCases := []struct {
  15. Domain string
  16. Result []uint32
  17. }{
  18. {
  19. Domain: "example.com",
  20. Result: []uint32{1},
  21. },
  22. {
  23. Domain: "y.com",
  24. Result: nil,
  25. },
  26. {
  27. Domain: "x.y.com",
  28. Result: []uint32{4, 6},
  29. },
  30. }
  31. for _, testCase := range testCases {
  32. r := g.Match(testCase.Domain)
  33. if !reflect.DeepEqual(r, testCase.Result) {
  34. t.Error("Failed to match domain: ", testCase.Domain, ", expect ", testCase.Result, ", but got ", r)
  35. }
  36. }
  37. }
  38. func TestEmptyFullMatcherGroup(t *testing.T) {
  39. g := new(FullMatcherGroup)
  40. r := g.Match("example.com")
  41. if len(r) != 0 {
  42. t.Error("Expect [], but ", r)
  43. }
  44. }