diff options
Diffstat (limited to 'resources/page/pagemeta/pagemeta_integration_test.go')
-rw-r--r-- | resources/page/pagemeta/pagemeta_integration_test.go | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/resources/page/pagemeta/pagemeta_integration_test.go b/resources/page/pagemeta/pagemeta_integration_test.go index 4d195b7f0..9d8f1b92f 100644 --- a/resources/page/pagemeta/pagemeta_integration_test.go +++ b/resources/page/pagemeta/pagemeta_integration_test.go @@ -14,6 +14,7 @@ package pagemeta_test import ( + "strings" "testing" "github.com/gohugoio/hugo/hugolib" @@ -43,3 +44,55 @@ Lastmod: 2024-03-13 06:00:00 +0000 GMT Eq: true `) } + +func TestDateValidation(t *testing.T) { + t.Parallel() + + files := ` +-- hugo.toml -- +disableKinds = ['page','rss','section','sitemap','taxonomy','term'] +-- content/_index.md -- ++++ +date = DATE ++++ +-- layouts/index.html -- +{{ .Date.UTC.Format "2006-01-02" }} +-- +` + errorMsg := `ERROR the "date" front matter field is not a parsable date` + + // Valid (TOML) + f := strings.ReplaceAll(files, "DATE", "2024-10-01") + b := hugolib.Test(t, f) + b.AssertFileContent("public/index.html", "2024-10-01") + + // Valid (string) + f = strings.ReplaceAll(files, "DATE", `"2024-10-01"`) + b = hugolib.Test(t, f) + b.AssertFileContent("public/index.html", "2024-10-01") + + // Valid (empty string) + f = strings.ReplaceAll(files, "DATE", `""`) + b = hugolib.Test(t, f) + b.AssertFileContent("public/index.html", "0001-01-01") + + // Valid (int) + f = strings.ReplaceAll(files, "DATE", "0") + b = hugolib.Test(t, f) + b.AssertFileContent("public/index.html", "1970-01-01") + + // Invalid (string) + f = strings.ReplaceAll(files, "DATE", `"2024-42-42"`) + b, _ = hugolib.TestE(t, f) + b.AssertLogContains(errorMsg) + + // Invalid (bool) + f = strings.ReplaceAll(files, "DATE", "true") + b, _ = hugolib.TestE(t, f) + b.AssertLogContains(errorMsg) + + // Invalid (float) + f = strings.ReplaceAll(files, "DATE", "6.7") + b, _ = hugolib.TestE(t, f) + b.AssertLogContains(errorMsg) +} |