mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-29 22:29:56 +02:00
tests: Convert from testify to quicktest
This commit is contained in:
@@ -19,7 +19,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
qt "github.com/frankban/quicktest"
|
||||
)
|
||||
|
||||
type testDoc struct {
|
||||
@@ -109,75 +109,75 @@ func TestSearch(t *testing.T) {
|
||||
idx.Add(docs...)
|
||||
|
||||
t.Run("count", func(t *testing.T) {
|
||||
assert := require.New(t)
|
||||
assert.Len(idx.index, 2)
|
||||
c := qt.New(t)
|
||||
c.Assert(len(idx.index), qt.Equals, 2)
|
||||
set1, found := idx.index["tags"]
|
||||
assert.True(found)
|
||||
c.Assert(found, qt.Equals, true)
|
||||
// 6 tags
|
||||
assert.Len(set1, 6)
|
||||
c.Assert(len(set1), qt.Equals, 6)
|
||||
|
||||
set2, found := idx.index["keywords"]
|
||||
assert.True(found)
|
||||
assert.Len(set2, 2)
|
||||
c.Assert(found, qt.Equals, true)
|
||||
c.Assert(len(set2), qt.Equals, 2)
|
||||
|
||||
})
|
||||
|
||||
t.Run("search-tags", func(t *testing.T) {
|
||||
assert := require.New(t)
|
||||
c := qt.New(t)
|
||||
m, err := idx.search(newQueryElement("tags", StringsToKeywords("a", "b", "d", "z")...))
|
||||
assert.NoError(err)
|
||||
assert.Len(m, 2)
|
||||
assert.Equal(docs[0], m[0])
|
||||
assert.Equal(docs[1], m[1])
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(len(m), qt.Equals, 2)
|
||||
c.Assert(m[0], qt.Equals, docs[0])
|
||||
c.Assert(m[1], qt.Equals, docs[1])
|
||||
})
|
||||
|
||||
t.Run("search-tags-and-keywords", func(t *testing.T) {
|
||||
assert := require.New(t)
|
||||
c := qt.New(t)
|
||||
m, err := idx.search(
|
||||
newQueryElement("tags", StringsToKeywords("a", "b", "z")...),
|
||||
newQueryElement("keywords", StringsToKeywords("a", "b")...))
|
||||
assert.NoError(err)
|
||||
assert.Len(m, 3)
|
||||
assert.Equal(docs[3], m[0])
|
||||
assert.Equal(docs[2], m[1])
|
||||
assert.Equal(docs[0], m[2])
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(len(m), qt.Equals, 3)
|
||||
c.Assert(m[0], qt.Equals, docs[3])
|
||||
c.Assert(m[1], qt.Equals, docs[2])
|
||||
c.Assert(m[2], qt.Equals, docs[0])
|
||||
})
|
||||
|
||||
t.Run("searchdoc-all", func(t *testing.T) {
|
||||
assert := require.New(t)
|
||||
c := qt.New(t)
|
||||
doc := newTestDoc("tags", "a").addKeywords("keywords", "a")
|
||||
m, err := idx.SearchDoc(doc)
|
||||
assert.NoError(err)
|
||||
assert.Len(m, 2)
|
||||
assert.Equal(docs[3], m[0])
|
||||
assert.Equal(docs[2], m[1])
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(len(m), qt.Equals, 2)
|
||||
c.Assert(m[0], qt.Equals, docs[3])
|
||||
c.Assert(m[1], qt.Equals, docs[2])
|
||||
})
|
||||
|
||||
t.Run("searchdoc-tags", func(t *testing.T) {
|
||||
assert := require.New(t)
|
||||
c := qt.New(t)
|
||||
doc := newTestDoc("tags", "a", "b", "d", "z").addKeywords("keywords", "a", "b")
|
||||
m, err := idx.SearchDoc(doc, "tags")
|
||||
assert.NoError(err)
|
||||
assert.Len(m, 2)
|
||||
assert.Equal(docs[0], m[0])
|
||||
assert.Equal(docs[1], m[1])
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(len(m), qt.Equals, 2)
|
||||
c.Assert(m[0], qt.Equals, docs[0])
|
||||
c.Assert(m[1], qt.Equals, docs[1])
|
||||
})
|
||||
|
||||
t.Run("searchdoc-keywords-date", func(t *testing.T) {
|
||||
assert := require.New(t)
|
||||
c := qt.New(t)
|
||||
doc := newTestDoc("tags", "a", "b", "d", "z").addKeywords("keywords", "a", "b")
|
||||
// This will get a date newer than the others.
|
||||
newDoc := newTestDoc("keywords", "a", "b")
|
||||
idx.Add(newDoc)
|
||||
|
||||
m, err := idx.SearchDoc(doc, "keywords")
|
||||
assert.NoError(err)
|
||||
assert.Len(m, 2)
|
||||
assert.Equal(docs[3], m[0])
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(len(m), qt.Equals, 2)
|
||||
c.Assert(m[0], qt.Equals, docs[3])
|
||||
})
|
||||
|
||||
t.Run("searchdoc-keywords-same-date", func(t *testing.T) {
|
||||
assert := require.New(t)
|
||||
c := qt.New(t)
|
||||
idx := NewInvertedIndex(config)
|
||||
|
||||
date := time.Now()
|
||||
@@ -192,10 +192,10 @@ func TestSearch(t *testing.T) {
|
||||
}
|
||||
|
||||
m, err := idx.SearchDoc(doc, "keywords")
|
||||
assert.NoError(err)
|
||||
assert.Len(m, 10)
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(len(m), qt.Equals, 10)
|
||||
for i := 0; i < 10; i++ {
|
||||
assert.Equal(fmt.Sprintf("doc%d", i), m[i].Name())
|
||||
c.Assert(m[i].Name(), qt.Equals, fmt.Sprintf("doc%d", i))
|
||||
}
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user