Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-08-10 22:05:17 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-08-12 14:26:32 +0300
commit9e571827055dedb46b78c5db3d17d6913f14870b (patch)
treef5f0108afe0c9385ff6dc27664943d9f719f57ad /common
parent6027ee11082d0b9d72de1d4d1980a702be294ad2 (diff)
tests: Convert from testify to quicktest
Diffstat (limited to 'common')
-rw-r--r--common/collections/append_test.go19
-rw-r--r--common/collections/slice_test.go19
-rw-r--r--common/herrors/error_locator_test.go54
-rw-r--r--common/herrors/file_error_test.go17
-rw-r--r--common/hreflect/helpers_test.go12
-rw-r--r--common/hugo/hugo_test.go16
-rw-r--r--common/hugo/version_test.go89
-rw-r--r--common/loggers/loggers_test.go6
-rw-r--r--common/maps/maps_test.go6
-rw-r--r--common/maps/params_test.go18
-rw-r--r--common/maps/scratch_test.go44
-rw-r--r--common/math/math_test.go15
-rw-r--r--common/text/position_test.go14
-rw-r--r--common/types/evictingqueue_test.go24
-rw-r--r--common/types/types_test.go8
15 files changed, 177 insertions, 184 deletions
diff --git a/common/collections/append_test.go b/common/collections/append_test.go
index c08a69c0d..8c9a6e73f 100644
--- a/common/collections/append_test.go
+++ b/common/collections/append_test.go
@@ -14,17 +14,16 @@
package collections
import (
- "fmt"
- "reflect"
"testing"
- "github.com/stretchr/testify/require"
+ qt "github.com/frankban/quicktest"
)
func TestAppend(t *testing.T) {
t.Parallel()
+ c := qt.New(t)
- for i, test := range []struct {
+ for _, test := range []struct {
start interface{}
addend []interface{}
expected interface{}
@@ -59,20 +58,16 @@ func TestAppend(t *testing.T) {
false},
} {
- errMsg := fmt.Sprintf("[%d]", i)
-
result, err := Append(test.start, test.addend...)
if b, ok := test.expected.(bool); ok && !b {
- require.Error(t, err, errMsg)
+
+ c.Assert(err, qt.Not(qt.IsNil))
continue
}
- require.NoError(t, err, 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)
- }
+ c.Assert(err, qt.IsNil)
+ c.Assert(result, qt.DeepEquals, test.expected)
}
}
diff --git a/common/collections/slice_test.go b/common/collections/slice_test.go
index fd8eb24f1..3ebfe6d11 100644
--- a/common/collections/slice_test.go
+++ b/common/collections/slice_test.go
@@ -15,10 +15,9 @@ package collections
import (
"errors"
- "fmt"
"testing"
- "github.com/alecthomas/assert"
+ qt "github.com/frankban/quicktest"
)
var _ Slicer = (*tstSlicer)(nil)
@@ -34,15 +33,15 @@ type testSlicerInterface interface {
type testSlicerInterfaces []testSlicerInterface
type tstSlicerIn1 struct {
- name string
+ TheName string
}
type tstSlicerIn2 struct {
- name string
+ TheName string
}
type tstSlicer struct {
- name string
+ TheName string
}
func (p *tstSlicerIn1) Slice(in interface{}) (interface{}, error) {
@@ -75,11 +74,11 @@ func (p *tstSlicerIn2) Slice(in interface{}) (interface{}, error) {
}
func (p *tstSlicerIn1) Name() string {
- return p.name
+ return p.TheName
}
func (p *tstSlicerIn2) Name() string {
- return p.name
+ return p.TheName
}
func (p *tstSlicer) Slice(in interface{}) (interface{}, error) {
@@ -100,6 +99,7 @@ type tstSlicers []*tstSlicer
func TestSlice(t *testing.T) {
t.Parallel()
+ c := qt.New(t)
for i, test := range []struct {
args []interface{}
@@ -114,12 +114,11 @@ func TestSlice(t *testing.T) {
{[]interface{}{&tstSlicerIn1{"a"}, &tstSlicerIn2{"b"}}, testSlicerInterfaces{&tstSlicerIn1{"a"}, &tstSlicerIn2{"b"}}},
{[]interface{}{&tstSlicerIn1{"a"}, &tstSlicer{"b"}}, []interface{}{&tstSlicerIn1{"a"}, &tstSlicer{"b"}}},
} {
- errMsg := fmt.Sprintf("[%d] %v", i, test.args)
+ errMsg := qt.Commentf("[%d] %v", i, test.args)
result := Slice(test.args...)
- assert.Equal(t, test.expected, result, errMsg)
+ c.Assert(test.expected, qt.DeepEquals, result, errMsg)
}
- assert.Len(t, Slice(), 0)
}
diff --git a/common/herrors/error_locator_test.go b/common/herrors/error_locator_test.go
index 2d007016d..cce94166f 100644
--- a/common/herrors/error_locator_test.go
+++ b/common/herrors/error_locator_test.go
@@ -18,11 +18,11 @@ import (
"strings"
"testing"
- "github.com/stretchr/testify/require"
+ qt "github.com/frankban/quicktest"
)
func TestErrorLocator(t *testing.T) {
- assert := require.New(t)
+ c := qt.New(t)
lineMatcher := func(m LineMatcher) bool {
return strings.Contains(m.Line, "THEONE")
@@ -39,45 +39,45 @@ LINE 8
`
location := locateErrorInString(lines, lineMatcher)
- assert.Equal([]string{"LINE 3", "LINE 4", "This is THEONE", "LINE 6", "LINE 7"}, location.Lines)
+ c.Assert(location.Lines, qt.DeepEquals, []string{"LINE 3", "LINE 4", "This is THEONE", "LINE 6", "LINE 7"})
pos := location.Position()
- assert.Equal(5, pos.LineNumber)
- assert.Equal(2, location.LinesPos)
+ c.Assert(pos.LineNumber, qt.Equals, 5)
+ c.Assert(location.LinesPos, qt.Equals, 2)
- assert.Equal([]string{"This is THEONE"}, locateErrorInString(`This is THEONE`, lineMatcher).Lines)
+ c.Assert(locateErrorInString(`This is THEONE`, lineMatcher).Lines, qt.DeepEquals, []string{"This is THEONE"})
location = locateErrorInString(`L1
This is THEONE
L2
`, lineMatcher)
- assert.Equal(2, location.Position().LineNumber)
- assert.Equal(1, location.LinesPos)
- assert.Equal([]string{"L1", "This is THEONE", "L2", ""}, location.Lines)
+ c.Assert(location.Position().LineNumber, qt.Equals, 2)
+ c.Assert(location.LinesPos, qt.Equals, 1)
+ c.Assert(location.Lines, qt.DeepEquals, []string{"L1", "This is THEONE", "L2", ""})
location = locateErrorInString(`This is THEONE
L2
`, lineMatcher)
- assert.Equal(0, location.LinesPos)
- assert.Equal([]string{"This is THEONE", "L2", ""}, location.Lines)
+ c.Assert(location.LinesPos, qt.Equals, 0)
+ c.Assert(location.Lines, qt.DeepEquals, []string{"This is THEONE", "L2", ""})
location = locateErrorInString(`L1
This THEONE
`, lineMatcher)
- assert.Equal([]string{"L1", "This THEONE", ""}, location.Lines)
- assert.Equal(1, location.LinesPos)
+ c.Assert(location.Lines, qt.DeepEquals, []string{"L1", "This THEONE", ""})
+ c.Assert(location.LinesPos, qt.Equals, 1)
location = locateErrorInString(`L1
L2
This THEONE
`, lineMatcher)
- assert.Equal([]string{"L1", "L2", "This THEONE", ""}, location.Lines)
- assert.Equal(2, location.LinesPos)
+ c.Assert(location.Lines, qt.DeepEquals, []string{"L1", "L2", "This THEONE", ""})
+ c.Assert(location.LinesPos, qt.Equals, 2)
location = locateErrorInString("NO MATCH", lineMatcher)
- assert.Equal(-1, location.Position().LineNumber)
- assert.Equal(-1, location.LinesPos)
- assert.Equal(0, len(location.Lines))
+ c.Assert(location.Position().LineNumber, qt.Equals, -1)
+ c.Assert(location.LinesPos, qt.Equals, -1)
+ c.Assert(len(location.Lines), qt.Equals, 0)
lineMatcher = func(m LineMatcher) bool {
return m.LineNumber == 6
@@ -94,9 +94,9 @@ H
I
J`, lineMatcher)
- assert.Equal([]string{"D", "E", "F", "G", "H"}, location.Lines)
- assert.Equal(6, location.Position().LineNumber)
- assert.Equal(2, location.LinesPos)
+ c.Assert(location.Lines, qt.DeepEquals, []string{"D", "E", "F", "G", "H"})
+ c.Assert(location.Position().LineNumber, qt.Equals, 6)
+ c.Assert(location.LinesPos, qt.Equals, 2)
// Test match EOF
lineMatcher = func(m LineMatcher) bool {
@@ -108,9 +108,9 @@ B
C
`, lineMatcher)
- assert.Equal([]string{"B", "C", ""}, location.Lines)
- assert.Equal(4, location.Position().LineNumber)
- assert.Equal(2, location.LinesPos)
+ c.Assert(location.Lines, qt.DeepEquals, []string{"B", "C", ""})
+ c.Assert(location.Position().LineNumber, qt.Equals, 4)
+ c.Assert(location.LinesPos, qt.Equals, 2)
offsetMatcher := func(m LineMatcher) bool {
return m.Offset == 1
@@ -122,8 +122,8 @@ C
D
E`, offsetMatcher)
- assert.Equal([]string{"A", "B", "C", "D"}, location.Lines)
- assert.Equal(2, location.Position().LineNumber)
- assert.Equal(1, location.LinesPos)
+ c.Assert(location.Lines, qt.DeepEquals, []string{"A", "B", "C", "D"})
+ c.Assert(location.Position().LineNumber, qt.Equals, 2)
+ c.Assert(location.LinesPos, qt.Equals, 1)
}
diff --git a/common/herrors/file_error_test.go b/common/herrors/file_error_test.go
index 4108983d3..b1b5c5a02 100644
--- a/common/herrors/file_error_test.go
+++ b/common/herrors/file_error_test.go
@@ -14,18 +14,17 @@
package herrors
import (
- "fmt"
"testing"
"github.com/pkg/errors"
- "github.com/stretchr/testify/require"
+ qt "github.com/frankban/quicktest"
)
func TestToLineNumberError(t *testing.T) {
t.Parallel()
- assert := require.New(t)
+ c := qt.New(t)
for i, test := range []struct {
in error
@@ -43,15 +42,15 @@ func TestToLineNumberError(t *testing.T) {
got := ToFileError("template", test.in)
- errMsg := fmt.Sprintf("[%d][%T]", i, got)
+ errMsg := qt.Commentf("[%d][%T]", i, got)
le, ok := got.(FileError)
- assert.True(ok)
+ c.Assert(ok, qt.Equals, true)
- assert.True(ok, errMsg)
+ c.Assert(ok, qt.Equals, true, errMsg)
pos := le.Position()
- assert.Equal(test.lineNumber, pos.LineNumber, errMsg)
- assert.Equal(test.columnNumber, pos.ColumnNumber, errMsg)
- assert.Error(errors.Cause(got))
+ c.Assert(pos.LineNumber, qt.Equals, test.lineNumber, errMsg)
+ c.Assert(pos.ColumnNumber, qt.Equals, test.columnNumber, errMsg)
+ c.Assert(errors.Cause(got), qt.Not(qt.IsNil))
}
}
diff --git a/common/hreflect/helpers_test.go b/common/hreflect/helpers_test.go
index 3c9179394..480ccb27a 100644
--- a/common/hreflect/helpers_test.go
+++ b/common/hreflect/helpers_test.go
@@ -18,16 +18,16 @@ import (
"testing"
"time"
- "github.com/stretchr/testify/require"
+ qt "github.com/frankban/quicktest"
)
func TestIsTruthful(t *testing.T) {
- assert := require.New(t)
+ c := qt.New(t)
- assert.True(IsTruthful(true))
- assert.False(IsTruthful(false))
- assert.True(IsTruthful(time.Now()))
- assert.False(IsTruthful(time.Time{}))
+ 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)
}
func BenchmarkIsTruthFul(b *testing.B) {
diff --git a/common/hugo/hugo_test.go b/common/hugo/hugo_test.go
index 1769db587..5be575b62 100644
--- a/common/hugo/hugo_test.go
+++ b/common/hugo/hugo_test.go
@@ -17,19 +17,19 @@ import (
"fmt"
"testing"
- "github.com/stretchr/testify/require"
+ qt "github.com/frankban/quicktest"
)
func TestHugoInfo(t *testing.T) {
- assert := require.New(t)
+ c := qt.New(t)
hugoInfo := NewInfo("")
- assert.Equal(CurrentVersion.Version(), hugoInfo.Version())
- assert.IsType(VersionString(""), hugoInfo.Version())
- assert.Equal(commitHash, hugoInfo.CommitHash)
- assert.Equal(buildDate, hugoInfo.BuildDate)
- assert.Equal("production", hugoInfo.Environment)
- assert.Contains(hugoInfo.Generator(), fmt.Sprintf("Hugo %s", hugoInfo.Version()))
+ c.Assert(hugoInfo.Version(), qt.Equals, CurrentVersion.Version())
+ c.Assert(fmt.Sprintf("%T", VersionString("")), qt.Equals, fmt.Sprintf("%T", hugoInfo.Version()))
+ c.Assert(hugoInfo.CommitHash, qt.Equals, commitHash)
+ c.Assert(hugoInfo.BuildDate, qt.Equals, buildDate)
+ c.Assert(hugoInfo.Environment, qt.Equals, "production")
+ c.Assert(string(hugoInfo.Generator()), qt.Contains, fmt.Sprintf("Hugo %s", hugoInfo.Version()))
}
diff --git a/common/hugo/version_test.go b/common/hugo/version_test.go
index e2aeeabbf..e0cd0e6e8 100644
--- a/common/hugo/version_test.go
+++ b/common/hugo/version_test.go
@@ -16,70 +16,73 @@ package hugo
import (
"testing"
- "github.com/stretchr/testify/assert"
- "github.com/stretchr/testify/require"
+ qt "github.com/frankban/quicktest"
)
func TestHugoVersion(t *testing.T) {
- assert.Equal(t, "0.15-DEV", version(0.15, 0, "-DEV"))
- assert.Equal(t, "0.15.2-DEV", version(0.15, 2, "-DEV"))
+ c := qt.New(t)
+
+ c.Assert(version(0.15, 0, "-DEV"), qt.Equals, "0.15-DEV")
+ c.Assert(version(0.15, 2, "-DEV"), qt.Equals, "0.15.2-DEV")
v := Version{Number: 0.21, PatchLevel: 0, Suffix: "-DEV"}
- require.Equal(t, v.ReleaseVersion().String(), "0.21")
- require.Equal(t, "0.21-DEV", v.String())
- require.Equal(t, "0.22", v.Next().String())
+ c.Assert(v.ReleaseVersion().String(), qt.Equals, "0.21")
+ c.Assert(v.String(), qt.Equals, "0.21-DEV")
+ c.Assert(v.Next().String(), qt.Equals, "0.22")
nextVersionString := v.Next().Version()
- require.Equal(t, "0.22", nextVersionString.String())
- require.True(t, nextVersionString.Eq("0.22"))
- require.False(t, nextVersionString.Eq("0.21"))
- require.True(t, nextVersionString.Eq(nextVersionString))
- require.Equal(t, "0.20.3", v.NextPatchLevel(3).String())
+ c.Assert(nextVersionString.String(), qt.Equals, "0.22")
+ c.Assert(nextVersionString.Eq("0.22"), qt.Equals, true)
+ c.Assert(nextVersionString.Eq("0.21"), qt.Equals, false)
+ c.Assert(nextVersionString.Eq(nextVersionString), qt.Equals, true)
+ c.Assert(v.NextPatchLevel(3).String(), qt.Equals, "0.20.3")
// We started to use full semver versions even for main
// releases in v0.54.0
v = Version{Number: 0.53, PatchLevel: 0}
- require.Equal(t, "0.53", v.String())
- require.Equal(t, "0.54.0", v.Next().String())
- require.Equal(t, "0.55.0", v.Next().Next().String())
+ c.Assert(v.String(), qt.Equals, "0.53")
+ c.Assert(v.Next().String(), qt.Equals, "0.54.0")
+ c.Assert(v.Next().Next().String(), qt.Equals, "0.55.0")
v = Version{Number: 0.54, PatchLevel: 0, Suffix: "-DEV"}
- require.Equal(t, "0.54.0-DEV", v.String())
+ c.Assert(v.String(), qt.Equals, "0.54.0-DEV")
}
func TestCompareVersions(t *testing.T) {
- require.Equal(t, 0, compareVersions(0.20, 0, 0.20))
- require.Equal(t, 0, compareVersions(0.20, 0, float32(0.20)))
- require.Equal(t, 0, compareVersions(0.20, 0, float64(0.20)))
- require.Equal(t, 1, compareVersions(0.19, 1, 0.20))
- require.Equal(t, 1, compareVersions(0.19, 3, "0.20.2"))
- require.Equal(t, -1, compareVersions(0.19, 1, 0.01))
- require.Equal(t, 1, compareVersions(0, 1, 3))
- require.Equal(t, 1, compareVersions(0, 1, int32(3)))
- require.Equal(t, 1, compareVersions(0, 1, int64(3)))
- require.Equal(t, 0, compareVersions(0.20, 0, "0.20"))
- require.Equal(t, 0, compareVersions(0.20, 1, "0.20.1"))
- require.Equal(t, -1, compareVersions(0.20, 1, "0.20"))
- require.Equal(t, 1, compareVersions(0.20, 0, "0.20.1"))
- require.Equal(t, 1, compareVersions(0.20, 1, "0.20.2"))
- require.Equal(t, 1, compareVersions(0.21, 1, "0.22.1"))
- require.Equal(t, -1, compareVersions(0.22, 0, "0.22-DEV"))
- require.Equal(t, 1, compareVersions(0.22, 0, "0.22.1-DEV"))
- require.Equal(t, 1, compareVersionsWithSuffix(0.22, 0, "-DEV", "0.22"))
- require.Equal(t, -1, compareVersionsWithSuffix(0.22, 1, "-DEV", "0.22"))
- require.Equal(t, 0, compareVersionsWithSuffix(0.22, 1, "-DEV", "0.22.1-DEV"))
+ c := qt.New(t)
+ c.Assert(compareVersions(0.20, 0, 0.20), qt.Equals, 0)
+ c.Assert(compareVersions(0.20, 0, float32(0.20)), qt.Equals, 0)
+ c.Assert(compareVersions(0.20, 0, float64(0.20)), qt.Equals, 0)
+ c.Assert(compareVersions(0.19, 1, 0.20), qt.Equals, 1)
+ c.Assert(compareVersions(0.19, 3, "0.20.2"), qt.Equals, 1)
+ c.Assert(compareVersions(0.19, 1, 0.01), qt.Equals, -1)
+ c.Assert(compareVersions(0, 1, 3), qt.Equals, 1)
+ c.Assert(compareVersions(0, 1, int32(3)), qt.Equals, 1)
+ c.Assert(compareVersions(0, 1, int64(3)), qt.Equals, 1)
+ c.Assert(compareVersions(0.20, 0, "0.20"), qt.Equals, 0)
+ c.Assert(compareVersions(0.20, 1, "0.20.1"), qt.Equals, 0)
+ c.Assert(compareVersions(0.20, 1, "0.20"), qt.Equals, -1)
+ c.Assert(compareVersions(0.20, 0, "0.20.1"), qt.Equals, 1)
+ c.Assert(compareVersions(0.20, 1, "0.20.2"), qt.Equals, 1)
+ c.Assert(compareVersions(0.21, 1, "0.22.1"), qt.Equals, 1)
+ c.Assert(compareVersions(0.22, 0, "0.22-DEV"), qt.Equals, -1)
+ c.Assert(compareVersions(0.22, 0, "0.22.1-DEV"), qt.Equals, 1)
+ c.Assert(compareVersionsWithSuffix(0.22, 0, "-DEV", "0.22"), qt.Equals, 1)
+ c.Assert(compareVersionsWithSuffix(0.22, 1, "-DEV", "0.22"), qt.Equals, -1)
+ c.Assert(compareVersionsWithSuffix(0.22, 1, "-DEV", "0.22.1-DEV"), qt.Equals, 0)
}
func TestParseHugoVersion(t *testing.T) {
- require.Equal(t, "0.25", MustParseVersion("0.25").String())
- require.Equal(t, "0.25.2", MustParseVersion("0.25.2").String())
- require.Equal(t, "0.25-test", MustParseVersion("0.25-test").String())
- require.Equal(t, "0.25-DEV", MustParseVersion("0.25-DEV").String())
+ c := qt.New(t)
+ c.Assert(MustParseVersion("0.25").String(), qt.Equals, "0.25")
+ c.Assert(MustParseVersion("0.25.2").String(), qt.Equals, "0.25.2")
+ c.Assert(MustParseVersion("0.25-test").String(), qt.Equals, "0.25-test")
+ c.Assert(MustParseVersion("0.25-DEV").String(), qt.Equals, "0.25-DEV")
}
func TestGoMinorVersion(t *testing.T) {
- assert := require.New(t)
- assert.Equal(12, goMinorVersion("go1.12.5"))
- assert.True(GoMinorVersion() >= 11)
+ c := qt.New(t)
+ c.Assert(goMinorVersion("go1.12.5"), qt.Equals, 12)
+ c.Assert(GoMinorVersion() >= 11, qt.Equals, true)
}
diff --git a/common/loggers/loggers_test.go b/common/loggers/loggers_test.go
index 3737ddc68..f572ba170 100644
--- a/common/loggers/loggers_test.go
+++ b/common/loggers/loggers_test.go
@@ -16,17 +16,17 @@ package loggers
import (
"testing"
- "github.com/stretchr/testify/require"
+ qt "github.com/frankban/quicktest"
)
func TestLogger(t *testing.T) {
- assert := require.New(t)
+ c := qt.New(t)
l := NewWarningLogger()
l.ERROR.Println("One error")
l.ERROR.Println("Two error")
l.WARN.Println("A warning")
- assert.Equal(uint64(2), l.ErrorCounter.Count())
+ c.Assert(l.ErrorCounter.Count(), qt.Equals, uint64(2))
}
diff --git a/common/maps/maps_test.go b/common/maps/maps_test.go
index 29bffa6bc..8b0aa5eb9 100644
--- a/common/maps/maps_test.go
+++ b/common/maps/maps_test.go
@@ -17,7 +17,7 @@ import (
"reflect"
"testing"
- "github.com/stretchr/testify/require"
+ qt "github.com/frankban/quicktest"
)
func TestToLower(t *testing.T) {
@@ -74,7 +74,7 @@ func TestToLower(t *testing.T) {
}
func TestRenameKeys(t *testing.T) {
- assert := require.New(t)
+ c := qt.New(t)
m := map[string]interface{}{
"a": 32,
@@ -112,7 +112,7 @@ func TestRenameKeys(t *testing.T) {
"{ren1,sub/*/ren1}", "new1",
"{Ren2,sub/ren2}", "new2",
)
- assert.NoError(err)
+ c.Assert(err, qt.IsNil)
renamer.Rename(m)
diff --git a/common/maps/params_test.go b/common/maps/params_test.go
index 7443553f1..6477de6f4 100644
--- a/common/maps/params_test.go
+++ b/common/maps/params_test.go
@@ -16,7 +16,7 @@ package maps
import (
"testing"
- "github.com/stretchr/testify/require"
+ qt "github.com/frankban/quicktest"
)
func TestGetNestedParam(t *testing.T) {
@@ -33,19 +33,19 @@ func TestGetNestedParam(t *testing.T) {
},
}
- assert := require.New(t)
+ c := qt.New(t)
must := func(keyStr, separator string, candidates ...map[string]interface{}) interface{} {
v, err := GetNestedParam(keyStr, separator, candidates...)
- assert.NoError(err)
+ c.Assert(err, qt.IsNil)
return v
}
- assert.Equal(1, must("first", "_", m))
- assert.Equal(1, must("First", "_", m))
- assert.Equal(2, must("with_underscore", "_", m))
- assert.Equal("blue", must("nested_color", "_", m))
- assert.Equal("green", must("nested.nestednested.color", ".", m))
- assert.Nil(must("string.name", ".", m))
+ c.Assert(must("first", "_", m), qt.Equals, 1)
+ c.Assert(must("First", "_", m), qt.Equals, 1)
+ c.Assert(must("with_underscore", "_", m), qt.Equals, 2)
+ c.Assert(must("nested_color", "_", m), qt.Equals, "blue")
+ c.Assert(must("nested.nestednested.color", ".", m), qt.Equals, "green")
+ c.Assert(must("string.name", ".", m), qt.IsNil)
}
diff --git a/common/maps/scratch_test.go b/common/maps/scratch_test.go
index 4550a22c5..c2c436e40 100644
--- a/common/maps/scratch_test.go
+++ b/common/maps/scratch_test.go
@@ -18,31 +18,31 @@ import (
"sync"
"testing"
- "github.com/stretchr/testify/require"
+ qt "github.com/frankban/quicktest"
)
func TestScratchAdd(t *testing.T) {
t.Parallel()
- assert := require.New(t)
+ c := qt.New(t)
scratch := NewScratch()
scratch.Add("int1", 10)
scratch.Add("int1", 20)
scratch.Add("int2", 20)
- assert.Equal(int64(30), scratch.Get("int1"))
- assert.Equal(20, scratch.Get("int2"))
+ c.Assert(scratch.Get("int1"), qt.Equals, int64(30))
+ c.Assert(scratch.Get("int2"), qt.Equals, 20)
scratch.Add("float1", float64(10.5))
scratch.Add("float1", float64(20.1))
- assert.Equal(float64(30.6), scratch.Get("float1"))
+ c.Assert(scratch.Get("float1"), qt.Equals, float64(30.6))
scratch.Add("string1", "Hello ")
scratch.Add("string1", "big ")
scratch.Add("string1", "World!")
- assert.Equal("Hello big World!", scratch.Get("string1"))
+ c.Assert(scratch.Get("string1"), qt.Equals, "Hello big World!")
scratch.Add("scratch", scratch)
_, err := scratch.Add("scratch", scratch)
@@ -55,14 +55,14 @@ func TestScratchAdd(t *testing.T) {
func TestScratchAddSlice(t *testing.T) {
t.Parallel()
- assert := require.New(t)
+ c := qt.New(t)
scratch := NewScratch()
_, err := scratch.Add("intSlice", []int{1, 2})
- assert.NoError(err)
+ c.Assert(err, qt.IsNil)
_, err = scratch.Add("intSlice", 3)
- assert.NoError(err)
+ c.Assert(err, qt.IsNil)
sl := scratch.Get("intSlice")
expected := []int{1, 2, 3}
@@ -72,7 +72,7 @@ func TestScratchAddSlice(t *testing.T) {
}
_, err = scratch.Add("intSlice", []int{4, 5})
- assert.NoError(err)
+ c.Assert(err, qt.IsNil)
sl = scratch.Get("intSlice")
expected = []int{1, 2, 3, 4, 5}
@@ -85,49 +85,49 @@ func TestScratchAddSlice(t *testing.T) {
// https://github.com/gohugoio/hugo/issues/5275
func TestScratchAddTypedSliceToInterfaceSlice(t *testing.T) {
t.Parallel()
- assert := require.New(t)
+ c := qt.New(t)
scratch := NewScratch()
scratch.Set("slice", []interface{}{})
_, err := scratch.Add("slice", []int{1, 2})
- assert.NoError(err)
- assert.Equal([]int{1, 2}, scratch.Get("slice"))
+ c.Assert(err, qt.IsNil)
+ c.Assert(scratch.Get("slice"), qt.DeepEquals, []int{1, 2})
}
// https://github.com/gohugoio/hugo/issues/5361
func TestScratchAddDifferentTypedSliceToInterfaceSlice(t *testing.T) {
t.Parallel()
- assert := require.New(t)
+ c := qt.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"))
+ c.Assert(err, qt.IsNil)
+ c.Assert(scratch.Get("slice"), qt.DeepEquals, []interface{}{"foo", 1, 2})
}
func TestScratchSet(t *testing.T) {
t.Parallel()
- assert := require.New(t)
+ c := qt.New(t)
scratch := NewScratch()
scratch.Set("key", "val")
- assert.Equal("val", scratch.Get("key"))
+ c.Assert(scratch.Get("key"), qt.Equals, "val")
}
func TestScratchDelete(t *testing.T) {
t.Parallel()
- assert := require.New(t)
+ c := qt.New(t)
scratch := NewScratch()
scratch.Set("key", "val")
scratch.Delete("key")
scratch.Add("key", "Lucy Parsons")
- assert.Equal("Lucy Parsons", scratch.Get("key"))
+ c.Assert(scratch.Get("key"), qt.Equals, "Lucy Parsons")
}
// Issue #2005
@@ -177,7 +177,7 @@ func TestScratchGet(t *testing.T) {
func TestScratchSetInMap(t *testing.T) {
t.Parallel()
- assert := require.New(t)
+ c := qt.New(t)
scratch := NewScratch()
scratch.SetInMap("key", "lux", "Lux")
@@ -185,7 +185,7 @@ func TestScratchSetInMap(t *testing.T) {
scratch.SetInMap("key", "zyx", "Zyx")
scratch.SetInMap("key", "abc", "Abc (updated)")
scratch.SetInMap("key", "def", "Def")
- assert.Equal([]interface{}{0: "Abc (updated)", 1: "Def", 2: "Lux", 3: "Zyx"}, scratch.GetSortedMapValues("key"))
+ c.Assert(scratch.GetSortedMapValues("key"), qt.DeepEquals, []interface{}{0: "Abc (updated)", 1: "Def", 2: "Lux", 3: "Zyx"})
}
func TestScratchGetSortedMapValues(t *testing.T) {
diff --git a/common/math/math_test.go b/common/math/math_test.go
index 613ac3073..a11701862 100644
--- a/common/math/math_test.go
+++ b/common/math/math_test.go
@@ -14,17 +14,16 @@
package math
import (
- "fmt"
"testing"
- "github.com/alecthomas/assert"
- "github.com/stretchr/testify/require"
+ qt "github.com/frankban/quicktest"
)
func TestDoArithmetic(t *testing.T) {
t.Parallel()
+ c := qt.New(t)
- for i, test := range []struct {
+ for _, test := range []struct {
a interface{}
b interface{}
op rune
@@ -94,16 +93,14 @@ func TestDoArithmetic(t *testing.T) {
{"foo", "bar", '-', false},
{3, 2, '%', false},
} {
- errMsg := fmt.Sprintf("[%d] %v", i, test)
-
result, err := DoArithmetic(test.a, test.b, test.op)
if b, ok := test.expect.(bool); ok && !b {
- require.Error(t, err, errMsg)
+ c.Assert(err, qt.Not(qt.IsNil))
continue
}
- require.NoError(t, err, errMsg)
- assert.Equal(t, test.expect, result, errMsg)
+ c.Assert(err, qt.IsNil)
+ c.Assert(test.expect, qt.Equals, result)
}
}
diff --git a/common/text/position_test.go b/common/text/position_test.go
index a25a3edbd..ba4824344 100644
--- a/common/text/position_test.go
+++ b/common/text/position_test.go
@@ -16,18 +16,18 @@ package text
import (
"testing"
- "github.com/stretchr/testify/require"
+ qt "github.com/frankban/quicktest"
)
func TestPositionStringFormatter(t *testing.T) {
- assert := require.New(t)
+ c := qt.New(t)
pos := Position{Filename: "/my/file.txt", LineNumber: 12, ColumnNumber: 13, Offset: 14}
- assert.Equal("/my/file.txt|13|12", createPositionStringFormatter(":file|:col|:line")(pos))
- assert.Equal("13|/my/file.txt|12", createPositionStringFormatter(":col|:file|:line")(pos))
- assert.Equal("好:13", createPositionStringFormatter("好::col")(pos))
- assert.Equal("\"/my/file.txt:12:13\"", createPositionStringFormatter("")(pos))
- assert.Equal("\"/my/file.txt:12:13\"", pos.String())
+ c.Assert(createPositionStringFormatter(":file|:col|:line")(pos), qt.Equals, "/my/file.txt|13|12")
+ c.Assert(createPositionStringFormatter(":col|:file|:line")(pos), qt.Equals, "13|/my/file.txt|12")
+ c.Assert(createPositionStringFormatter("好::col")(pos), qt.Equals, "好:13")
+ c.Assert(createPositionStringFormatter("")(pos), qt.Equals, "\"/my/file.txt:12:13\"")
+ c.Assert(pos.String(), qt.Equals, "\"/my/file.txt:12:13\"")
}
diff --git a/common/types/evictingqueue_test.go b/common/types/evictingqueue_test.go
index a7b1e1d54..7489ba88d 100644
--- a/common/types/evictingqueue_test.go
+++ b/common/types/evictingqueue_test.go
@@ -17,36 +17,36 @@ import (
"sync"
"testing"
- "github.com/stretchr/testify/require"
+ qt "github.com/frankban/quicktest"
)
func TestEvictingStringQueue(t *testing.T) {
- assert := require.New(t)
+ c := qt.New(t)
queue := NewEvictingStringQueue(3)
- assert.Equal("", queue.Peek())
+ c.Assert(queue.Peek(), qt.Equals, "")
queue.Add("a")
queue.Add("b")
queue.Add("a")
- assert.Equal("b", queue.Peek())
+ c.Assert(queue.Peek(), qt.Equals, "b")
queue.Add("b")
- assert.Equal("b", queue.Peek())
+ c.Assert(queue.Peek(), qt.Equals, "b")
queue.Add("a")
queue.Add("b")
- assert.True(queue.Contains("a"))
- assert.False(queue.Contains("foo"))
+ c.Assert(queue.Contains("a"), qt.Equals, true)
+ c.Assert(queue.Contains("foo"), qt.Equals, false)
- assert.Equal([]string{"b", "a"}, queue.PeekAll())
- assert.Equal("b", queue.Peek())
+ c.Assert(queue.PeekAll(), qt.DeepEquals, []string{"b", "a"})
+ c.Assert(queue.Peek(), qt.Equals, "b")
queue.Add("c")
queue.Add("d")
// Overflowed, a should now be removed.
- assert.Equal([]string{"d", "c", "b"}, queue.PeekAll())
- assert.Len(queue.PeekAllSet(), 3)
- assert.True(queue.PeekAllSet()["c"])
+ c.Assert(queue.PeekAll(), qt.DeepEquals, []string{"d", "c", "b"})
+ c.Assert(len(queue.PeekAllSet()), qt.Equals, 3)
+ c.Assert(queue.PeekAllSet()["c"], qt.Equals, true)
}
func TestEvictingStringQueueConcurrent(t *testing.T) {
diff --git a/common/types/types_test.go b/common/types/types_test.go
index 7cec8c0c0..7c5cba659 100644
--- a/common/types/types_test.go
+++ b/common/types/types_test.go
@@ -16,14 +16,14 @@ package types
import (
"testing"
- "github.com/stretchr/testify/require"
+ qt "github.com/frankban/quicktest"
)
func TestKeyValues(t *testing.T) {
- assert := require.New(t)
+ c := qt.New(t)
kv := NewKeyValuesStrings("key", "a1", "a2")
- assert.Equal("key", kv.KeyString())
- assert.Equal([]interface{}{"a1", "a2"}, kv.Values)
+ c.Assert(kv.KeyString(), qt.Equals, "key")
+ c.Assert(kv.Values, qt.DeepEquals, []interface{}{"a1", "a2"})
}