qt "github.com/frankban/quicktest"
)
+type zeroStruct struct {
+ zero bool
+}
+
+func (z zeroStruct) IsZero() bool {
+ return z.zero
+}
+
func TestIsTruthful(t *testing.T) {
c := qt.New(t)
+ var nilpointerZero *zeroStruct
+
c.Assert(IsTruthful(true), qt.Equals, true)
c.Assert(IsTruthful(false), qt.Equals, false)
c.Assert(IsTruthful(time.Now()), qt.Equals, true)
c.Assert(IsTruthful(time.Time{}), qt.Equals, false)
+ c.Assert(IsTruthful(&zeroStruct{zero: false}), qt.Equals, true)
+ c.Assert(IsTruthful(&zeroStruct{zero: true}), qt.Equals, false)
+ c.Assert(IsTruthful(zeroStruct{zero: false}), qt.Equals, true)
+ c.Assert(IsTruthful(zeroStruct{zero: true}), qt.Equals, false)
+ c.Assert(IsTruthful(nil), qt.Equals, false)
+ c.Assert(IsTruthful(nilpointerZero), qt.Equals, false)
}
func TestGetMethodByName(t *testing.T) {
b, _ = hugolib.TestE(t, files)
b.AssertLogMatches(`error calling ToHTML: startLevel: unable to cast "x" of type string`)
}
+
+func TestHeadingsNilpointerIssue11843(t *testing.T) {
+ t.Parallel()
+ files := `
+-- hugo.toml --
+-- layouts/home.html --
+{{ $h := index .Fragments.HeadingsMap "bad_id" }}
+{{ if not $h }}OK{{ end }}
+`
+ b := hugolib.Test(t, files)
+
+ b.AssertFileContent("public/index.html", "OK")
+}