tpl/collections: Fix apply when function have Context as first arg

As introduced in `partial` and `partialCached` in Hugo 0.93.0.

Fixes #9585
This commit is contained in:
Bjørn Erik Pedersen
2022-03-01 11:30:11 +01:00
parent 41b5bc9637
commit 376704d382
4 changed files with 65 additions and 12 deletions

View File

@@ -73,21 +73,23 @@ func TestApply(t *testing.T) {
strings := []interface{}{"a\n", "b\n"}
result, err := ns.Apply(strings, "print", "a", "b", "c")
ctx := context.Background()
result, err := ns.Apply(ctx, strings, "print", "a", "b", "c")
c.Assert(err, qt.IsNil)
c.Assert(result, qt.DeepEquals, []interface{}{"abc", "abc"})
_, err = ns.Apply(strings, "apply", ".")
_, err = ns.Apply(ctx, strings, "apply", ".")
c.Assert(err, qt.Not(qt.IsNil))
var nilErr *error
_, err = ns.Apply(nilErr, "chomp", ".")
_, err = ns.Apply(ctx, nilErr, "chomp", ".")
c.Assert(err, qt.Not(qt.IsNil))
_, err = ns.Apply(strings, "dobedobedo", ".")
_, err = ns.Apply(ctx, strings, "dobedobedo", ".")
c.Assert(err, qt.Not(qt.IsNil))
_, err = ns.Apply(strings, "foo.Chomp", "c\n")
_, err = ns.Apply(ctx, strings, "foo.Chomp", "c\n")
if err == nil {
t.Errorf("apply with unknown func should fail")
}