Add Page tests with UTF8 paths

See #988
This commit is contained in:
Takuya Wakisaka
2015-05-09 19:12:30 +09:00
committed by bep
parent befa26b152
commit 8a96234b1f
2 changed files with 78 additions and 33 deletions

View File

@@ -223,6 +223,47 @@ second line.
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 = `+++
@@ -622,6 +663,43 @@ func TestSliceToLower(t *testing.T) {
}
}
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())
}
}
}
func listEqual(left, right []string) bool {
if len(left) != len(right) {
return false