shithub: hugo

Download patch

ref: 8a96234b1fd3e3724609425f03b60fba32003f92
parent: befa26b152e79ffc47dfac5ad7e681ab948c00da
author: Takuya Wakisaka <[email protected]>
date: Sat May 9 15:12:30 EDT 2015

Add Page tests with UTF8 paths

See #988

--- a/hugolib/page_test.go
+++ b/hugolib/page_test.go
@@ -223,6 +223,47 @@
 
 fourth line.
 `
+
+	SIMPLE_PAGE_WITH_URL = `---
+title: Simple
+url: simple/url/
+---
+Simple Page With URL`
+
+	SIMPLE_PAGE_WITH_SLUG = `---
+title: Simple
+slug: simple-slug
+---
+Simple Page With Slug`
+
+	SIMPLE_PAGE_WITH_DATE = `---
+title: Simple
+date: '2013-10-15T06:16:13'
+---
+Simple Page With Date`
+
+	UTF8_PAGE = `---
+title: ラーメン
+---
+UTF8 Page`
+
+	UTF8_PAGE_WITH_URL = `---
+title: ラーメン
+url: ラーメン/url/
+---
+UTF8 Page With URL`
+
+	UTF8_PAGE_WITH_SLUG = `---
+title: ラーメン
+slug: ラーメン-slug
+---
+UTF8 Page With Slug`
+
+	UTF8_PAGE_WITH_DATE = `---
+title: ラーメン
+date: '2013-10-15T06:16:13'
+---
+UTF8 Page With Date`
 )
 
 var PAGE_WITH_VARIOUS_FRONTMATTER_TYPES = `+++
@@ -618,6 +659,43 @@
 			if val != test.expected[i] {
 				t.Errorf("Case mismatch. Expected %s, got %s", test.expected[i], res[i])
 			}
+		}
+	}
+}
+
+func TestTargetPath(t *testing.T) {
+	site_permalinks_setting := PermalinkOverrides{
+		"post": ":year/:month/:day/:title/",
+	}
+
+	tests := []struct {
+		content        string
+		path           string
+		hasPermalink   bool
+		expected       string
+	}{
+		{SIMPLE_PAGE, "content/post/x.md", false, "content/post/x.html"},
+		{SIMPLE_PAGE_WITH_URL, "content/post/x.md", false, "simple/url/index.html"},
+		{SIMPLE_PAGE_WITH_SLUG, "content/post/x.md", false, "content/post/simple-slug.html"},
+		{SIMPLE_PAGE_WITH_DATE, "content/post/x.md", true, "2013/10/15/simple/index.html"},
+		{UTF8_PAGE, "content/post/x.md", false, "content/post/x.html"},
+		{UTF8_PAGE_WITH_URL, "content/post/x.md", false, "ラーメン/url/index.html"},
+		{UTF8_PAGE_WITH_SLUG, "content/post/x.md", false, "content/post/ラーメン-slug.html"},
+		{UTF8_PAGE_WITH_DATE, "content/post/x.md", true, "2013/10/15/ラーメン/index.html"},
+	}
+
+	for _, test := range tests {
+		p, _ := NewPageFrom(strings.NewReader(test.content), filepath.FromSlash(test.path))
+		p.Node.Site = &SiteInfo{}
+
+		if test.hasPermalink {
+			p.Node.Site.Permalinks = site_permalinks_setting
+		}
+
+		expected := filepath.FromSlash(test.expected)
+
+		if p.TargetPath() != expected {
+			t.Errorf("%s => TargetPath  expected: '%s', got: '%s'", test.content, expected, p.TargetPath())
 		}
 	}
 }
--- a/hugolib/site_test.go
+++ b/hugolib/site_test.go
@@ -212,39 +212,6 @@
 	}
 }
 
-func TestTargetPath(t *testing.T) {
-	tests := []struct {
-		doc             string
-		content         string
-		expectedOutFile string
-		expectedSection string
-	}{
-		{"content/a/file.md", PAGE_URL_SPECIFIED, "mycategory/my-whatever-content/index.html", "a"},
-		{"content/x/y/deepfile.md", SIMPLE_PAGE, "x/y/deepfile.html", "x/y"},
-		{"content/x/y/z/deeperfile.md", SIMPLE_PAGE, "x/y/z/deeperfile.html", "x/y/z"},
-		{"content/b/file.md", SIMPLE_PAGE, "b/file.html", "b"},
-		{"a/file.md", SIMPLE_PAGE, "a/file.html", "a"},
-		{"file.md", SIMPLE_PAGE, "file.html", ""},
-	}
-
-	if true {
-		return
-	}
-
-	for _, test := range tests {
-		p := pageMust(NewPageFrom(strings.NewReader(test.content), helpers.AbsPathify(filepath.FromSlash(test.doc))))
-
-		expected := filepath.FromSlash(test.expectedOutFile)
-
-		if p.TargetPath() != expected {
-			t.Errorf("%s => OutFile  expected: '%s', got: '%s'", test.doc, expected, p.TargetPath())
-		}
-
-		if p.Section() != test.expectedSection {
-			t.Errorf("%s => p.Section expected: %s, got: %s", test.doc, test.expectedSection, p.Section())
-		}
-	}
-}
 
 func TestDraftAndFutureRender(t *testing.T) {
 	hugofs.DestinationFS = new(afero.MemMapFs)