Skip to content

Commit

Permalink
url check test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
nothub committed Feb 10, 2024
1 parent 0364f56 commit 624e899
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions web/url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,43 @@ func TestIsValidHttpUrl(t *testing.T) {
}

cases := []testCase{
{url: "C:\\Foo\\Bar", want: false},
{url: "C://Foo//Bar", want: false},
{url: "http://example.org", want: true},
{url: "http://example.org/path/to/page", want: true},
{url: "http://example.org:8080", want: true},
{url: "http://example.org:8080/path/to/page", want: true},

{url: "https://example.org", want: true},
{url: "https://example.org\n", want: false},
{url: "https://example.org/foo/bar", want: true},
{url: "https://example.org/foo/bar?x=y", want: true},
{url: "https://example.org:8080", want: true},
{url: "https://example.org:8080/path/to/page", want: true},
{url: "https://example.org\n", want: false},

{url: "example.org", want: false},

{url: "ftp://example.org", want: false},

{url: "relative/unix/path", want: false},
{url: "relative/unix/path/", want: false},
{url: "relative/unix/path/file.txt", want: false},

{url: "relative\\windows\\path", want: false},
{url: "relative\\windows\\path\\", want: false},
{url: "relative\\windows\\path\\file.txt", want: false},

{url: "/absolute/unix/path", want: false},
{url: "/absolute/unix/path/", want: false},
{url: "/absolute/unix/path/file.txt", want: false},

{url: "C:\\absolute\\windows\\path", want: false},
{url: "C:\\absolute\\windows\\path\\", want: false},
{url: "C:\\absolute\\windows\\path\\file.txt", want: false},
}

for _, c := range cases {
t.Run(c.url, func(t *testing.T) {
if got := IsValidHttpUrl(c.url); got != c.want {
t.Errorf("IsValidUrl() = %v, want %v", got, c.want)
for _, tc := range cases {
t.Run(tc.url, func(t *testing.T) {
if got := IsValidHttpUrl(tc.url); got != tc.want {
t.Errorf("IsValidUrl() = %v, want %v", got, tc.want)
}
})
}
Expand Down

0 comments on commit 624e899

Please sign in to comment.