Fix nilpointer on ToC heading · gohugoio/hugo@4f2d2b2 (original) (raw)

Original file line number Diff line number Diff line change
@@ -22,13 +22,29 @@ import (
22 22 qt "github.com/frankban/quicktest"
23 23 )
24 24
25 +type zeroStruct struct {
26 +zero bool
27 +}
28 +
29 +func (z zeroStruct) IsZero() bool {
30 +return z.zero
31 +}
32 +
25 33 func TestIsTruthful(t *testing.T) {
26 34 c := qt.New(t)
27 35
36 +var nilpointerZero *zeroStruct
37 +
28 38 c.Assert(IsTruthful(true), qt.Equals, true)
29 39 c.Assert(IsTruthful(false), qt.Equals, false)
30 40 c.Assert(IsTruthful(time.Now()), qt.Equals, true)
31 41 c.Assert(IsTruthful(time.Time{}), qt.Equals, false)
42 +c.Assert(IsTruthful(&zeroStruct{zero: false}), qt.Equals, true)
43 +c.Assert(IsTruthful(&zeroStruct{zero: true}), qt.Equals, false)
44 +c.Assert(IsTruthful(zeroStruct{zero: false}), qt.Equals, true)
45 +c.Assert(IsTruthful(zeroStruct{zero: true}), qt.Equals, false)
46 +c.Assert(IsTruthful(nil), qt.Equals, false)
47 +c.Assert(IsTruthful(nilpointerZero), qt.Equals, false)
32 48 }
33 49
34 50 func TestGetMethodByName(t *testing.T) {