Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Waller <o.waller@kulawe.com>2014-09-10 21:43:02 +0400
committerspf13 <steve.francia@gmail.com>2014-11-05 03:16:07 +0300
commit6b619d2cd60365e2e8039c3d8018a516d5b4fdde (patch)
tree0a8dc02da016a9507894cd59836b1963c126d2d3 /helpers
parent57cd9539978172dcfb539aa700aa1c1faeef9045 (diff)
Added the url modules test files.
Added the new url module test file. This replaces the original helpers_test.go file. The TestUrlPrep test currently fails. The only minor change to url.go is to add some trace printf's to UrlPrep.
Diffstat (limited to 'helpers')
-rw-r--r--helpers/url.go3
-rw-r--r--helpers/url_test.go99
2 files changed, 102 insertions, 0 deletions
diff --git a/helpers/url.go b/helpers/url.go
index 94c66139d..37c53b666 100644
--- a/helpers/url.go
+++ b/helpers/url.go
@@ -81,6 +81,7 @@ func MakePermalink(host, plink string) *url.URL {
func UrlPrep(ugly bool, in string) string {
if ugly {
x := Uglify(SanitizeUrl(in))
+ fmt.Printf("Ugly case. Returning x = %q\n", x)
return x
} else {
x := PrettifyUrl(SanitizeUrl(in))
@@ -89,8 +90,10 @@ func UrlPrep(ugly bool, in string) string {
}
url, err := purell.NormalizeURLString(x, purell.FlagAddTrailingSlash)
if err != nil {
+ fmt.Printf("ERROR returned by NormalizeURLString. Returning in = %q\n", in)
return in
}
+ fmt.Printf("NO error returning url = %q\n", url)
return url
}
}
diff --git a/helpers/url_test.go b/helpers/url_test.go
new file mode 100644
index 000000000..2a0223cdc
--- /dev/null
+++ b/helpers/url_test.go
@@ -0,0 +1,99 @@
+package helpers
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestUrlize(t *testing.T) {
+ tests := []struct {
+ input string
+ expected string
+ }{
+ {" foo bar ", "foo-bar"},
+ {"foo.bar/foo_bar-foo", "foo.bar/foo_bar-foo"},
+ {"foo,bar:foo%bar", "foobarfoobar"},
+ {"foo/bar.html", "foo/bar.html"},
+ {"трям/трям", "%D1%82%D1%80%D1%8F%D0%BC/%D1%82%D1%80%D1%8F%D0%BC"},
+ }
+
+ for _, test := range tests {
+ output := Urlize(test.input)
+ if output != test.expected {
+ t.Errorf("Expected %#v, got %#v\n", test.expected, output)
+ }
+ }
+}
+
+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
+ input string
+ output string
+ }
+
+ data := []test{
+ {false, "/section/name.html", "/section/name/index.html"},
+ {true, "/section/name/index.html", "/section/name.html"},
+ }
+ for i, d := range data {
+ output := UrlPrep(d.ugly, d.input)
+ if d.output != output {
+ t.Errorf("Test #%d failed. Expected %q got %q", i, d.output, output)
+ }
+ }
+
+}
+
+func TestPretty(t *testing.T) {
+ assert.Equal(t, PrettifyPath("/section/name.html"), "/section/name/index.html")
+ assert.Equal(t, PrettifyPath("/section/sub/name.html"), "/section/sub/name/index.html")
+ assert.Equal(t, PrettifyPath("/section/name/"), "/section/name/index.html")
+ assert.Equal(t, PrettifyPath("/section/name/index.html"), "/section/name/index.html")
+ assert.Equal(t, PrettifyPath("/index.html"), "/index.html")
+ assert.Equal(t, PrettifyPath("/name.xml"), "/name/index.xml")
+ assert.Equal(t, PrettifyPath("/"), "/")
+ assert.Equal(t, PrettifyPath(""), "/")
+ assert.Equal(t, PrettifyUrl("/section/name.html"), "/section/name")
+ assert.Equal(t, PrettifyUrl("/section/sub/name.html"), "/section/sub/name")
+ assert.Equal(t, PrettifyUrl("/section/name/"), "/section/name")
+ assert.Equal(t, PrettifyUrl("/section/name/index.html"), "/section/name")
+ assert.Equal(t, PrettifyUrl("/index.html"), "/")
+ assert.Equal(t, PrettifyUrl("/name.xml"), "/name/index.xml")
+ assert.Equal(t, PrettifyUrl("/"), "/")
+ assert.Equal(t, PrettifyUrl(""), "/")
+}
+
+func TestUgly(t *testing.T) {
+ assert.Equal(t, Uglify("/section/name.html"), "/section/name.html")
+ assert.Equal(t, Uglify("/section/sub/name.html"), "/section/sub/name.html")
+ assert.Equal(t, Uglify("/section/name/"), "/section/name.html")
+ assert.Equal(t, Uglify("/section/name/index.html"), "/section/name.html")
+ assert.Equal(t, Uglify("/index.html"), "/index.html")
+ assert.Equal(t, Uglify("/name.xml"), "/name.xml")
+ assert.Equal(t, Uglify("/"), "/")
+ assert.Equal(t, Uglify(""), "/")
+}