url_test.go 605 B

12345678910111213141516171819202122232425262728293031323334
  1. package validate
  2. import (
  3. "errors"
  4. "fmt"
  5. "testing"
  6. )
  7. func ExampleURL() {
  8. fmt.Println(URL("not a url"))
  9. // Output: invalid URL
  10. }
  11. func TestURL(t *testing.T) {
  12. testCases := map[string]error{
  13. "http://example.com": nil,
  14. "http://subdomain.example.com": nil,
  15. "http://www.example.com/some-page.html": nil,
  16. "not a url": ErrInvalidURL,
  17. "subdomain.com": ErrInvalidURL,
  18. }
  19. for input, want := range testCases {
  20. t.Run(input, func(t *testing.T) {
  21. got := URL(input)
  22. if !errors.Is(got, want) {
  23. t.Error("got", got)
  24. t.Error("want", want)
  25. }
  26. })
  27. }
  28. }