diff options
Diffstat (limited to 'tpl')
57 files changed, 876 insertions, 842 deletions
diff --git a/tpl/cast/cast_test.go b/tpl/cast/cast_test.go index fc20934f8..c6219728b 100644 --- a/tpl/cast/cast_test.go +++ b/tpl/cast/cast_test.go @@ -14,16 +14,15 @@ package cast import ( - "fmt" "html/template" "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + qt "github.com/frankban/quicktest" ) func TestToInt(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New() @@ -40,23 +39,23 @@ func TestToInt(t *testing.T) { {"a", false}, {t, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test.v) + errMsg := qt.Commentf("[%d] %v", i, test.v) result, err := ns.ToInt(test.v) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil), errMsg) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil, errMsg) + c.Assert(result, qt.Equals, test.expect, errMsg) } } func TestToString(t *testing.T) { t.Parallel() - + c := qt.New(t) ns := New() for i, test := range []struct { @@ -68,23 +67,23 @@ func TestToString(t *testing.T) { {"a", "a"}, {t, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test.v) + errMsg := qt.Commentf("[%d] %v", i, test.v) result, err := ns.ToString(test.v) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil), errMsg) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil, errMsg) + c.Assert(result, qt.Equals, test.expect, errMsg) } } func TestToFloat(t *testing.T) { t.Parallel() - + c := qt.New(t) ns := New() for i, test := range []struct { @@ -105,16 +104,16 @@ func TestToFloat(t *testing.T) { {2, 2.0}, {t, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test.v) + errMsg := qt.Commentf("[%d] %v", i, test.v) result, err := ns.ToFloat(test.v) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil), errMsg) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil, errMsg) + c.Assert(result, qt.Equals, test.expect, errMsg) } } diff --git a/tpl/cast/init_test.go b/tpl/cast/init_test.go index 47cbd3d0b..73d9d5adc 100644 --- a/tpl/cast/init_test.go +++ b/tpl/cast/init_test.go @@ -16,12 +16,15 @@ package cast import ( "testing" + "github.com/gohugoio/hugo/htesting/hqt" + + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/tpl/internal" - "github.com/stretchr/testify/require" ) func TestInit(t *testing.T) { + c := qt.New(t) var found bool var ns *internal.TemplateFuncsNamespace @@ -33,6 +36,7 @@ func TestInit(t *testing.T) { } } - require.True(t, found) - require.IsType(t, &Namespace{}, ns.Context()) + c.Assert(found, qt.Equals, true) + c.Assert(ns.Context(), hqt.IsSameType, &Namespace{}) + } diff --git a/tpl/collections/append_test.go b/tpl/collections/append_test.go index f886aca22..a254601b4 100644 --- a/tpl/collections/append_test.go +++ b/tpl/collections/append_test.go @@ -14,17 +14,17 @@ package collections import ( - "fmt" "reflect" "testing" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" - "github.com/stretchr/testify/require" ) // Also see tests in common/collection. func TestAppend(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New(&deps.Deps{}) @@ -45,18 +45,18 @@ func TestAppend(t *testing.T) { false}, } { - errMsg := fmt.Sprintf("[%d]", i) + errMsg := qt.Commentf("[%d]", i) args := append(test.addend, test.start) result, err := ns.Append(args...) if b, ok := test.expected.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil), errMsg) continue } - require.NoError(t, err, errMsg) + c.Assert(err, qt.IsNil, errMsg) if !reflect.DeepEqual(test.expected, result) { t.Fatalf("%s got\n%T: %v\nexpected\n%T: %v", errMsg, result, result, test.expected, test.expected) diff --git a/tpl/collections/apply_test.go b/tpl/collections/apply_test.go index edec3da18..96dd8896b 100644 --- a/tpl/collections/apply_test.go +++ b/tpl/collections/apply_test.go @@ -18,9 +18,9 @@ import ( "fmt" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/tpl" - "github.com/stretchr/testify/require" ) type templateFinder int @@ -41,24 +41,25 @@ func (templateFinder) GetFuncs() map[string]interface{} { func TestApply(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New(&deps.Deps{Tmpl: new(templateFinder)}) strings := []interface{}{"a\n", "b\n"} result, err := ns.Apply(strings, "print", "a", "b", "c") - require.NoError(t, err) - require.Equal(t, []interface{}{"abc", "abc"}, result, "testing variadic") + c.Assert(err, qt.IsNil) + c.Assert(result, qt.DeepEquals, []interface{}{"abc", "abc"}) _, err = ns.Apply(strings, "apply", ".") - require.Error(t, err) + c.Assert(err, qt.Not(qt.IsNil)) var nilErr *error _, err = ns.Apply(nilErr, "chomp", ".") - require.Error(t, err) + c.Assert(err, qt.Not(qt.IsNil)) _, err = ns.Apply(strings, "dobedobedo", ".") - require.Error(t, err) + c.Assert(err, qt.Not(qt.IsNil)) _, err = ns.Apply(strings, "foo.Chomp", "c\n") if err == nil { diff --git a/tpl/collections/collections_test.go b/tpl/collections/collections_test.go index 662536a24..8ea973f0b 100644 --- a/tpl/collections/collections_test.go +++ b/tpl/collections/collections_test.go @@ -22,6 +22,7 @@ import ( "testing" "time" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/common/loggers" "github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/deps" @@ -29,14 +30,13 @@ import ( "github.com/gohugoio/hugo/hugofs" "github.com/gohugoio/hugo/langs" "github.com/spf13/viper" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) type tstNoStringer struct{} func TestAfter(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New(&deps.Deps{}) @@ -58,17 +58,17 @@ func TestAfter(t *testing.T) { {1, t, false}, {1, (*string)(nil), false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) + errMsg := qt.Commentf("[%d] %v", i, test) result, err := ns.After(test.index, test.seq) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil), errMsg) continue } - require.NoError(t, err, errMsg) - require.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil, errMsg) + c.Assert(result, qt.DeepEquals, test.expect, errMsg) } } @@ -92,7 +92,7 @@ func (g *tstGrouper2) Group(key interface{}, items interface{}) (interface{}, er func TestGroup(t *testing.T) { t.Parallel() - + c := qt.New(t) ns := New(&deps.Deps{}) for i, test := range []struct { @@ -111,22 +111,23 @@ func TestGroup(t *testing.T) { {"a", nil, false}, {nil, []*tstGrouper{{}, {}}, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) + errMsg := qt.Commentf("[%d] %v", i, test) result, err := ns.Group(test.key, test.items) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil), errMsg) continue } - require.NoError(t, err, errMsg) - require.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil, errMsg) + c.Assert(result, qt.Equals, test.expect, errMsg) } } func TestDelimit(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New(&deps.Deps{}) @@ -161,7 +162,7 @@ func TestDelimit(t *testing.T) { {map[int]string{3: "10", 2: "20", 1: "30", 4: "40", 5: "50"}, "--", "--and--", "30--20--10--40--and--50"}, {map[float64]string{3.5: "10", 2.5: "20", 1.5: "30", 4.5: "40", 5.5: "50"}, "--", "--and--", "30--20--10--40--and--50"}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) + errMsg := qt.Commentf("[%d] %v", i, test) var result template.HTML var err error @@ -172,13 +173,14 @@ func TestDelimit(t *testing.T) { result, err = ns.Delimit(test.seq, test.delimiter, test.last) } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil, errMsg) + c.Assert(result, qt.Equals, test.expect, errMsg) } } func TestDictionary(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New(&deps.Deps{}) @@ -192,22 +194,23 @@ func TestDictionary(t *testing.T) { {[]interface{}{5, "b"}, false}, {[]interface{}{"a", "b", "c"}, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test.values) + errMsg := qt.Commentf("[%d] %v", i, test.values) result, err := ns.Dictionary(test.values...) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil), errMsg) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil, errMsg) + c.Assert(result, qt.DeepEquals, test.expect, errMsg) } } func TestEchoParam(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New(&deps.Deps{}) @@ -229,16 +232,17 @@ func TestEchoParam(t *testing.T) { {map[string]interface{}{"foo": nil}, "foo", ""}, {(*[]string)(nil), "bar", ""}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) + errMsg := qt.Commentf("[%d] %v", i, test) result := ns.EchoParam(test.a, test.key) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(result, qt.Equals, test.expect, errMsg) } } func TestFirst(t *testing.T) { t.Parallel() + c := qt.New(t) ns := New(&deps.Deps{}) @@ -260,23 +264,23 @@ func TestFirst(t *testing.T) { {1, t, false}, {1, (*string)(nil), false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) + errMsg := qt.Commentf("[%d] %v", i, test) result, err := ns.First(test.limit, test.seq) if b, ok := test.expect.(bool); ok && !b { - require.Error(t, err, errMsg) + c.Assert(err, qt.Not(qt.IsNil), errMsg) continue } - require.NoError(t, err, errMsg) - assert.Equal(t, test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.DeepEquals, test.expect, errMsg) } } func TestIn(t *testing.T) { t.Parallel() - assert := require.New(t) + c := qt.New(t) ns := New(&deps.Deps{}) @@ -311,16 +315,16 @@ func TestIn(t *testing.T) { {pagesVals{p3v, p2v, p3v, p2v}, p4v, false}, } { - errMsg := fmt.Sprintf("[%d] %v", i, test) + errMsg := qt.Commentf("[%d] %v", i, test) result, err := ns.In(test.l1, test.l2) - assert.NoError(err) - assert.Equal(test.expect, result, errMsg) + c.Assert(err, qt.IsNil) + c.Assert(result, qt.Equals, test.expect, errMsg) } // Slices are not comparable _, err := ns.In([]string |