You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
762 B

  1. package weed_server
  2. import (
  3. "github.com/stretchr/testify/assert"
  4. "github.com/viant/ptrie"
  5. "testing"
  6. )
  7. func TestPtrie(t *testing.T) {
  8. b := []byte("/topics/abc/dev")
  9. excludedTrie := ptrie.New[bool]()
  10. excludedTrie.Put([]byte("/topics/abc/d"), true)
  11. excludedTrie.Put([]byte("/topics/abc"), true)
  12. assert.True(t, excludedTrie.MatchPrefix(b, func(key []byte, value bool) bool {
  13. println("matched1", string(key))
  14. return true
  15. }))
  16. assert.True(t, excludedTrie.MatchAll(b, func(key []byte, value bool) bool {
  17. println("matched2", string(key))
  18. return true
  19. }))
  20. assert.False(t, excludedTrie.MatchAll([]byte("/topics/ab"), func(key []byte, value bool) bool {
  21. println("matched3", string(key))
  22. return true
  23. }))
  24. assert.False(t, excludedTrie.Has(b))
  25. }