diff options
author | Bjørn Erik Pedersen <[email protected]> | 2021-06-18 10:27:27 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2021-06-18 10:55:00 +0200 |
commit | 93aad3c543828efca2adeb7f96cf50ae29878593 (patch) | |
tree | 6a3dd4f6f878f8f36be9cef03a15b78b19d1f3da /helpers/url_test.go | |
parent | 5af045ebab109d3e5501b8b6d9fd448840c96c9a (diff) | |
download | hugo-93aad3c543828efca2adeb7f96cf50ae29878593.tar.gz hugo-93aad3c543828efca2adeb7f96cf50ae29878593.zip |
Split out the puthe path/filepath functions into common/paths
So they can be used from the config package without cyclic troubles.
Updates #8654
Diffstat (limited to 'helpers/url_test.go')
-rw-r--r-- | helpers/url_test.go | 108 |
1 files changed, 3 insertions, 105 deletions
diff --git a/helpers/url_test.go b/helpers/url_test.go index 4c16208f1..f899e1cdb 100644 --- a/helpers/url_test.go +++ b/helpers/url_test.go @@ -17,7 +17,6 @@ import ( "strings" "testing" - qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/hugofs" "github.com/gohugoio/hugo/langs" ) @@ -93,9 +92,8 @@ func doTestAbsURL(t *testing.T, defaultInSubDir, addLanguage, multilingual bool, {"/" + lang + "test", "http://base/", "http://base/" + lang + "/" + lang + "test"}, } - for _, test := range newTests { - tests = append(tests, test) - } + tests = append(tests, newTests...) + } for _, test := range tests { @@ -121,24 +119,6 @@ func doTestAbsURL(t *testing.T, defaultInSubDir, addLanguage, multilingual bool, } } -func TestIsAbsURL(t *testing.T) { - c := qt.New(t) - - for _, this := range []struct { - a string - b bool - }{ - {"http://gohugo.io", true}, - {"https://gohugo.io", true}, - {"//gohugo.io", true}, - {"http//gohugo.io", false}, - {"/content", false}, - {"content", false}, - } { - c.Assert(IsAbsURL(this.a) == this.b, qt.Equals, true) - } -} - func TestRelURL(t *testing.T) { for _, defaultInSubDir := range []bool{true, false} { for _, addLanguage := range []bool{true, false} { @@ -187,10 +167,7 @@ func doTestRelURL(t *testing.T, defaultInSubDir, addLanguage, multilingual bool, {lang + "test", "http://base/", false, "/" + lang + "/" + lang + "test"}, {"/" + lang + "test", "http://base/", false, "/" + lang + "/" + lang + "test"}, } - - for _, test := range newTests { - tests = append(tests, test) - } + tests = append(tests, newTests...) } for i, test := range tests { @@ -247,28 +224,6 @@ func TestSanitizeURL(t *testing.T) { } } -func TestMakePermalink(t *testing.T) { - type test struct { - host, link, output string - } - - data := []test{ - {"http://abc.com/foo", "post/bar", "http://abc.com/foo/post/bar"}, - {"http://abc.com/foo/", "post/bar", "http://abc.com/foo/post/bar"}, - {"http://abc.com", "post/bar", "http://abc.com/post/bar"}, - {"http://abc.com", "bar", "http://abc.com/bar"}, - {"http://abc.com/foo/bar", "post/bar", "http://abc.com/foo/bar/post/bar"}, - {"http://abc.com/foo/bar", "post/bar/", "http://abc.com/foo/bar/post/bar/"}, - } - - for i, d := range data { - output := MakePermalink(d.host, d.link).String() - if d.output != output { - t.Errorf("Test #%d failed. Expected %q got %q", i, d.output, output) - } - } -} - func TestURLPrep(t *testing.T) { type test struct { ugly bool @@ -293,60 +248,3 @@ func TestURLPrep(t *testing.T) { } } } - -func TestAddContextRoot(t *testing.T) { - tests := []struct { - baseURL string - url string - expected string - }{ - {"http://example.com/sub/", "/foo", "/sub/foo"}, - {"http://example.com/sub/", "/foo/index.html", "/sub/foo/index.html"}, - {"http://example.com/sub1/sub2", "/foo", "/sub1/sub2/foo"}, - {"http://example.com", "/foo", "/foo"}, - // cannot guess that the context root is already added int the example below - {"http://example.com/sub/", "/sub/foo", "/sub/sub/foo"}, - {"http://example.com/тря", "/трям/", "/тря/трям/"}, - {"http://example.com", "/", "/"}, - {"http://example.com/bar", "//", "/bar/"}, - } - - for _, test := range tests { - output := AddContextRoot(test.baseURL, test.url) - if output != test.expected { - t.Errorf("Expected %#v, got %#v\n", test.expected, output) - } - } -} - -func TestPretty(t *testing.T) { - c := qt.New(t) - c.Assert("/section/name/index.html", qt.Equals, PrettifyURLPath("/section/name.html")) - c.Assert("/section/sub/name/index.html", qt.Equals, PrettifyURLPath("/section/sub/name.html")) - c.Assert("/section/name/index.html", qt.Equals, PrettifyURLPath("/section/name/")) - c.Assert("/section/name/index.html", qt.Equals, PrettifyURLPath("/section/name/index.html")) - c.Assert("/index.html", qt.Equals, PrettifyURLPath("/index.html")) - c.Assert("/name/index.xml", qt.Equals, PrettifyURLPath("/name.xml")) - c.Assert("/", qt.Equals, PrettifyURLPath("/")) - c.Assert("/", qt.Equals, PrettifyURLPath("")) - c.Assert("/section/name", qt.Equals, PrettifyURL("/section/name.html")) - c.Assert("/section/sub/name", qt.Equals, PrettifyURL("/section/sub/name.html")) - c.Assert("/section/name", qt.Equals, PrettifyURL("/section/name/")) - c.Assert("/section/name", qt.Equals, PrettifyURL("/section/name/index.html")) - c.Assert("/", qt.Equals, PrettifyURL("/index.html")) - c.Assert("/name/index.xml", qt.Equals, PrettifyURL("/name.xml")) - c.Assert("/", qt.Equals, PrettifyURL("/")) - c.Assert("/", qt.Equals, PrettifyURL("")) -} - -func TestUgly(t *testing.T) { - c := qt.New(t) - c.Assert("/section/name.html", qt.Equals, Uglify("/section/name.html")) - c.Assert("/section/sub/name.html", qt.Equals, Uglify("/section/sub/name.html")) - c.Assert("/section/name.html", qt.Equals, Uglify("/section/name/")) - c.Assert("/section/name.html", qt.Equals, Uglify("/section/name/index.html")) - c.Assert("/index.html", qt.Equals, Uglify("/index.html")) - c.Assert("/name.xml", qt.Equals, Uglify("/name.xml")) - c.Assert("/", qt.Equals, Uglify("/")) - c.Assert("/", qt.Equals, Uglify("")) -} |