diff options
author | bep <[email protected]> | 2015-05-11 13:59:06 +0200 |
---|---|---|
committer | bep <[email protected]> | 2015-05-11 13:59:02 +0200 |
commit | bec839e652838a1804bf0dfa3879d69fa9c1f130 (patch) | |
tree | 8cc7ab44316301edc81414555f14584f2dd0740d /helpers/url_test.go | |
parent | be0cbeee7fb9b6e8af12745971ff80e86e0d3d32 (diff) | |
download | hugo-bec839e652838a1804bf0dfa3879d69fa9c1f130.tar.gz hugo-bec839e652838a1804bf0dfa3879d69fa9c1f130.zip |
Add relURL template func
Fixes #1126
Diffstat (limited to 'helpers/url_test.go')
-rw-r--r-- | helpers/url_test.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/helpers/url_test.go b/helpers/url_test.go index 3286c0f37..bfd211b89 100644 --- a/helpers/url_test.go +++ b/helpers/url_test.go @@ -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 |