summaryrefslogtreecommitdiffstats
path: root/common/maps/scratch_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-10-27 11:10:39 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-10-27 15:05:40 +0200
commitdac7092a9cb22d59db28fb15af15f7b14ff47588 (patch)
treee001634ebe4e108abe710a24efe22a85e4568bbf /common/maps/scratch_test.go
parentb27ccf34bf4e5ee618a66fa11c68a9690e395034 (diff)
common/collections: Allow a mix of slice types in append/Scratch.Add
The type handling in these was improved in Hugo 0.49, but this also meant that it was no longer possible to start out with a string slice and later append `Page` etc. to it. This commit makes sure that the old behaviour is now possible again by falling back to a `[]interface{}` as a last resort. Fixes #5361
Diffstat (limited to 'common/maps/scratch_test.go')
-rw-r--r--common/maps/scratch_test.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/common/maps/scratch_test.go b/common/maps/scratch_test.go
index bf37d79df..4550a22c5 100644
--- a/common/maps/scratch_test.go
+++ b/common/maps/scratch_test.go
@@ -96,6 +96,20 @@ func TestScratchAddTypedSliceToInterfaceSlice(t *testing.T) {
}
+// https://github.com/gohugoio/hugo/issues/5361
+func TestScratchAddDifferentTypedSliceToInterfaceSlice(t *testing.T) {
+ t.Parallel()
+ assert := require.New(t)
+
+ scratch := NewScratch()
+ scratch.Set("slice", []string{"foo"})
+
+ _, err := scratch.Add("slice", []int{1, 2})
+ assert.NoError(err)
+ assert.Equal([]interface{}{"foo", 1, 2}, scratch.Get("slice"))
+
+}
+
func TestScratchSet(t *testing.T) {
t.Parallel()
assert := require.New(t)