summaryrefslogtreecommitdiffstats
path: root/hugolib/frontmatter_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-01-16 16:29:42 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-01-17 08:58:05 +0100
commit21af5b359f020ed19558141ffa309fd2ff381c6c (patch)
treeaac7fce3a348c285217f3434a54f9ed38d021c4e /hugolib/frontmatter_test.go
parentf38a2fbd2e4de7f095a833b448cb8bc053955ce2 (diff)
Preserve front matter slice value types (e.g. int)
Fixes #10624
Diffstat (limited to 'hugolib/frontmatter_test.go')
-rw-r--r--hugolib/frontmatter_test.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/hugolib/frontmatter_test.go b/hugolib/frontmatter_test.go
new file mode 100644
index 000000000..ade779c38
--- /dev/null
+++ b/hugolib/frontmatter_test.go
@@ -0,0 +1,47 @@
+// Copyright 2022 The Hugo Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package hugolib
+
+import "testing"
+
+// Issue 10624
+func TestFrontmatterPreserveDatatypesForSlices(t *testing.T) {
+ t.Parallel()
+
+ files := `
+-- content/post/one.md --
+---
+ints: [1, 2, 3]
+mixed: ["1", 2, 3]
+strings: ["1", "2","3"]
+---
+-- layouts/_default/single.html --
+Ints: {{ printf "%T" .Params.ints }} {{ range .Params.ints }}Int: {{ fmt.Printf "%[1]v (%[1]T)" . }}|{{ end }}
+Mixed: {{ printf "%T" .Params.mixed }} {{ range .Params.mixed }}Mixed: {{ fmt.Printf "%[1]v (%[1]T)" . }}|{{ end }}
+Strings: {{ printf "%T" .Params.strings }} {{ range .Params.strings }}Strings: {{ fmt.Printf "%[1]v (%[1]T)" . }}|{{ end }}
+`
+ b := NewIntegrationTestBuilder(
+ IntegrationTestConfig{
+ T: t,
+ TxtarString: files,
+ },
+ )
+
+ b.Build()
+
+ b.AssertFileContent("public/post/one/index.html", "Ints: []interface {} Int: 1 (int)|Int: 2 (int)|Int: 3 (int)|")
+ b.AssertFileContent("public/post/one/index.html", "Mixed: []interface {} Mixed: 1 (string)|Mixed: 2 (int)|Mixed: 3 (int)|")
+ b.AssertFileContent("public/post/one/index.html", "Strings: []string Strings: 1 (string)|Strings: 2 (string)|Strings: 3 (string)|")
+
+}