resource_name_test.go 751 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package util_test
  2. import (
  3. "testing"
  4. "github.com/usememos/memos/internal/util"
  5. )
  6. func TestUIDMatcher(t *testing.T) {
  7. tests := []struct {
  8. input string
  9. expected bool
  10. }{
  11. {"", false},
  12. {"-abc123", false},
  13. {"012345678901234567890123456789", true},
  14. {"1abc-123", true},
  15. {"A123B456C789", true},
  16. {"a", true},
  17. {"ab", true},
  18. {"a*b&c", false},
  19. {"a--b", true},
  20. {"a-1b-2c", true},
  21. {"a1234567890123456789012345678901", true},
  22. {"abc123", true},
  23. {"abc123-", false},
  24. }
  25. for _, test := range tests {
  26. t.Run(test.input, func(*testing.T) {
  27. result := util.UIDMatcher.MatchString(test.input)
  28. if result != test.expected {
  29. t.Errorf("For input '%s', expected %v but got %v", test.input, test.expected, result)
  30. }
  31. })
  32. }
  33. }