common/collections: Fix append regression to allow appending nil

Closes #11180
This commit is contained in:
khayyam
2023-06-28 03:41:36 -04:00
committed by GitHub
parent 793e38f5ce
commit b74b8d6478
3 changed files with 72 additions and 1 deletions

View File

@@ -104,3 +104,63 @@ func TestAppendSliceToASliceOfSlices(t *testing.T) {
}
}
func TestAppendNilToSlice(t *testing.T) {
t.Parallel()
files := `
-- hugo.toml --
-- layouts/index.html --
{{ $obj := (slice "a") }}
{{ $obj = $obj | append nil }}
{{ $obj }}
`
for i := 0; i < 4; i++ {
b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b.AssertFileContent("public/index.html", "[a &lt;nil&gt;]")
}
}
func TestAppendNilsToSliceWithNils(t *testing.T) {
t.Parallel()
files := `
-- hugo.toml --
-- layouts/index.html --
{{ $obj := (slice "a" nil "c") }}
{{ $obj = $obj | append nil }}
{{ $obj }}
`
for i := 0; i < 4; i++ {
b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b.AssertFileContent("public/index.html", "[a &lt;nil&gt; c &lt;nil&gt;]")
}
}