mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-12 20:13:59 +02:00
@@ -49,6 +49,37 @@ func TestAbsURL(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRelURL(t *testing.T) {
|
||||
defer viper.Set("canonifyURLs", viper.GetBool("canonifyURLs"))
|
||||
tests := []struct {
|
||||
input string
|
||||
baseURL string
|
||||
canonify bool
|
||||
expected string
|
||||
}{
|
||||
{"/test/foo", "http://base/", false, "/test/foo"},
|
||||
{"test.css", "http://base/sub", false, "/sub/test.css"},
|
||||
{"test.css", "http://base/sub", true, "/test.css"},
|
||||
{"/test/", "http://base/", false, "/test/"},
|
||||
{"/test/", "http://base/sub/", false, "/sub/test/"},
|
||||
{"/test/", "http://base/sub/", true, "/test/"},
|
||||
{"", "http://base/ace/", false, "/ace/"},
|
||||
{"", "http://base/ace", false, "/ace"},
|
||||
{"http://abs", "http://base/", false, "http://abs"},
|
||||
{"//schemaless", "http://base/", false, "//schemaless"},
|
||||
}
|
||||
|
||||
for i, test := range tests {
|
||||
viper.Set("BaseURL", test.baseURL)
|
||||
viper.Set("canonifyURLs", test.canonify)
|
||||
|
||||
output := RelURL(test.input)
|
||||
if output != test.expected {
|
||||
t.Errorf("[%d][%t] Expected %#v, got %#v\n", i, test.canonify, test.expected, output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSanitizeURL(t *testing.T) {
|
||||
tests := []struct {
|
||||
input string
|
||||
|
Reference in New Issue
Block a user