Files

35 lines
605 B
Go
Raw Permalink Normal View History

2023-11-26 12:00:15 +00:00
package validate
import (
"errors"
2024-07-18 06:53:20 +01:00
"fmt"
2023-11-26 12:00:15 +00:00
"testing"
)
2024-07-18 06:53:20 +01:00
func ExampleURL() {
fmt.Println(URL("not a url"))
// Output: invalid URL
}
2023-11-26 12:00:15 +00:00
func TestURL(t *testing.T) {
2024-07-18 06:53:20 +01:00
testCases := map[string]error{
"http://example.com": nil,
"http://subdomain.example.com": nil,
"http://www.example.com/some-page.html": nil,
2023-11-26 12:00:15 +00:00
2024-07-18 06:53:20 +01:00
"not a url": ErrInvalidURL,
"subdomain.com": ErrInvalidURL,
2023-11-26 12:00:15 +00:00
}
2024-07-18 06:53:20 +01:00
for input, want := range testCases {
t.Run(input, func(t *testing.T) {
got := URL(input)
2023-11-26 12:00:15 +00:00
2024-07-18 06:53:20 +01:00
if !errors.Is(got, want) {
t.Error("got", got)
t.Error("want", want)
}
})
2023-11-26 12:00:15 +00:00
}
}