mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
parent
befa26b152
commit
8a96234b1f
2 changed files with 78 additions and 33 deletions
|
@ -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
|
||||
|
|
|
@ -212,39 +212,6 @@ func TestRenderThingOrDefault(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue