Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

glob_test.go 1.0KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright (c) 2020 Shivaram Lingamneni <slingamn@cs.stanford.edu>
  2. // released under the MIT license
  3. package utils
  4. import (
  5. "regexp"
  6. "testing"
  7. )
  8. func globMustCompile(glob string) *regexp.Regexp {
  9. re, err := CompileGlob(glob)
  10. if err != nil {
  11. panic(err)
  12. }
  13. return re
  14. }
  15. func assertMatches(glob, str string, match bool, t *testing.T) {
  16. re := globMustCompile(glob)
  17. if re.MatchString(str) != match {
  18. t.Errorf("should %s match %s? %t, but got %t instead", glob, str, match, !match)
  19. }
  20. }
  21. func TestGlob(t *testing.T) {
  22. assertMatches("https://testnet.oragono.io", "https://testnet.oragono.io", true, t)
  23. assertMatches("https://*.oragono.io", "https://testnet.oragono.io", true, t)
  24. assertMatches("*://*.oragono.io", "https://testnet.oragono.io", true, t)
  25. assertMatches("*://*.oragono.io", "https://oragono.io", false, t)
  26. assertMatches("*://*.oragono.io", "https://githubusercontent.com", false, t)
  27. assertMatches("", "", true, t)
  28. assertMatches("", "x", false, t)
  29. assertMatches("*", "", true, t)
  30. assertMatches("*", "x", true, t)
  31. }