mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-26 22:04:32 +02:00
common/collections: Fix append regression to allow appending nil
Closes #11180
This commit is contained in:
@@ -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 <nil>]")
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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 <nil> c <nil>]")
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user