mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-25 22:00:58 +02:00
tests: Convert from testify to quicktest
This commit is contained in:
@@ -18,8 +18,8 @@ import (
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
qt "github.com/frankban/quicktest"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// Renders a codeblock using Blackfriday
|
||||
@@ -43,7 +43,7 @@ func (c ContentSpec) renderWithMmark(input string) string {
|
||||
}
|
||||
|
||||
func TestCodeFence(t *testing.T) {
|
||||
assert := require.New(t)
|
||||
c := qt.New(t)
|
||||
|
||||
type test struct {
|
||||
enabled bool
|
||||
@@ -64,10 +64,10 @@ func TestCodeFence(t *testing.T) {
|
||||
v.Set("pygmentsCodeFences", d.enabled)
|
||||
v.Set("pygmentsUseClassic", useClassic)
|
||||
|
||||
c, err := NewContentSpec(v)
|
||||
assert.NoError(err)
|
||||
cs, err := NewContentSpec(v)
|
||||
c.Assert(err, qt.IsNil)
|
||||
|
||||
result := c.render(d.input)
|
||||
result := cs.render(d.input)
|
||||
|
||||
expectedRe, err := regexp.Compile(d.expected)
|
||||
|
||||
@@ -80,7 +80,7 @@ func TestCodeFence(t *testing.T) {
|
||||
t.Errorf("Test %d failed. BlackFriday enabled:%t, Expected:\n%q got:\n%q", i, d.enabled, d.expected, result)
|
||||
}
|
||||
|
||||
result = c.renderWithMmark(d.input)
|
||||
result = cs.renderWithMmark(d.input)
|
||||
matched = expectedRe.MatchString(result)
|
||||
if !matched {
|
||||
t.Errorf("Test %d failed. Mmark enabled:%t, Expected:\n%q got:\n%q", i, d.enabled, d.expected, result)
|
||||
|
@@ -21,10 +21,9 @@ import (
|
||||
|
||||
"github.com/spf13/viper"
|
||||
|
||||
qt "github.com/frankban/quicktest"
|
||||
"github.com/miekg/mmark"
|
||||
"github.com/russross/blackfriday"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const tstHTMLContent = "<!DOCTYPE html><html><head><script src=\"http://two/foobar.js\"></script></head><body><nav><ul><li hugo-nav=\"section_0\"></li><li hugo-nav=\"section_1\"></li></ul></nav><article>content <a href=\"http://two/foobar\">foobar</a>. Follow up</article><p>This is some text.<br>And some more.</p></body></html>"
|
||||
@@ -90,17 +89,19 @@ func BenchmarkStripHTML(b *testing.B) {
|
||||
}
|
||||
|
||||
func TestStripEmptyNav(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
cleaned := stripEmptyNav([]byte("do<nav>\n</nav>\n\nbedobedo"))
|
||||
assert.Equal(t, []byte("dobedobedo"), cleaned)
|
||||
c.Assert(cleaned, qt.DeepEquals, []byte("dobedobedo"))
|
||||
}
|
||||
|
||||
func TestBytesToHTML(t *testing.T) {
|
||||
assert.Equal(t, template.HTML("dobedobedo"), BytesToHTML([]byte("dobedobedo")))
|
||||
c := qt.New(t)
|
||||
c.Assert(BytesToHTML([]byte("dobedobedo")), qt.Equals, template.HTML("dobedobedo"))
|
||||
}
|
||||
|
||||
func TestNewContentSpec(t *testing.T) {
|
||||
cfg := viper.New()
|
||||
assert := require.New(t)
|
||||
c := qt.New(t)
|
||||
|
||||
cfg.Set("summaryLength", 32)
|
||||
cfg.Set("buildFuture", true)
|
||||
@@ -109,11 +110,11 @@ func TestNewContentSpec(t *testing.T) {
|
||||
|
||||
spec, err := NewContentSpec(cfg)
|
||||
|
||||
assert.NoError(err)
|
||||
assert.Equal(32, spec.summaryLength)
|
||||
assert.True(spec.BuildFuture)
|
||||
assert.True(spec.BuildExpired)
|
||||
assert.True(spec.BuildDrafts)
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(spec.summaryLength, qt.Equals, 32)
|
||||
c.Assert(spec.BuildFuture, qt.Equals, true)
|
||||
c.Assert(spec.BuildExpired, qt.Equals, true)
|
||||
c.Assert(spec.BuildDrafts, qt.Equals, true)
|
||||
|
||||
}
|
||||
|
||||
|
@@ -19,9 +19,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
qt "github.com/frankban/quicktest"
|
||||
"github.com/spf13/afero"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestGuessType(t *testing.T) {
|
||||
@@ -188,6 +187,7 @@ func TestSliceToLower(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestReaderContains(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
for i, this := range append(containsBenchTestData, containsAdditionalTestData...) {
|
||||
result := ReaderContains(strings.NewReader(this.v1), this.v2)
|
||||
if result != this.expect {
|
||||
@@ -195,21 +195,21 @@ func TestReaderContains(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
assert.False(t, ReaderContains(nil, []byte("a")))
|
||||
assert.False(t, ReaderContains(nil, nil))
|
||||
c.Assert(ReaderContains(nil, []byte("a")), qt.Equals, false)
|
||||
c.Assert(ReaderContains(nil, nil), qt.Equals, false)
|
||||
}
|
||||
|
||||
func TestGetTitleFunc(t *testing.T) {
|
||||
title := "somewhere over the rainbow"
|
||||
assert := require.New(t)
|
||||
c := qt.New(t)
|
||||
|
||||
assert.Equal("Somewhere Over The Rainbow", GetTitleFunc("go")(title))
|
||||
assert.Equal("Somewhere over the Rainbow", GetTitleFunc("chicago")(title), "Chicago style")
|
||||
assert.Equal("Somewhere over the Rainbow", GetTitleFunc("Chicago")(title), "Chicago style")
|
||||
assert.Equal("Somewhere Over the Rainbow", GetTitleFunc("ap")(title), "AP style")
|
||||
assert.Equal("Somewhere Over the Rainbow", GetTitleFunc("ap")(title), "AP style")
|
||||
assert.Equal("Somewhere Over the Rainbow", GetTitleFunc("")(title), "AP style")
|
||||
assert.Equal("Somewhere Over the Rainbow", GetTitleFunc("unknown")(title), "AP style")
|
||||
c.Assert(GetTitleFunc("go")(title), qt.Equals, "Somewhere Over The Rainbow")
|
||||
c.Assert(GetTitleFunc("chicago")(title), qt.Equals, "Somewhere over the Rainbow")
|
||||
c.Assert(GetTitleFunc("Chicago")(title), qt.Equals, "Somewhere over the Rainbow")
|
||||
c.Assert(GetTitleFunc("ap")(title), qt.Equals, "Somewhere Over the Rainbow")
|
||||
c.Assert(GetTitleFunc("ap")(title), qt.Equals, "Somewhere Over the Rainbow")
|
||||
c.Assert(GetTitleFunc("")(title), qt.Equals, "Somewhere Over the Rainbow")
|
||||
c.Assert(GetTitleFunc("unknown")(title), qt.Equals, "Somewhere Over the Rainbow")
|
||||
|
||||
}
|
||||
|
||||
@@ -244,19 +244,20 @@ func TestUniqueStringsReuse(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUniqueStringsSorted(t *testing.T) {
|
||||
assert := require.New(t)
|
||||
c := qt.New(t)
|
||||
in := []string{"a", "a", "b", "c", "b", "", "a", "", "d"}
|
||||
output := UniqueStringsSorted(in)
|
||||
expected := []string{"", "a", "b", "c", "d"}
|
||||
assert.Equal(expected, output)
|
||||
assert.Nil(UniqueStringsSorted(nil))
|
||||
c.Assert(output, qt.DeepEquals, expected)
|
||||
c.Assert(UniqueStringsSorted(nil), qt.IsNil)
|
||||
}
|
||||
|
||||
func TestFindAvailablePort(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
addr, err := FindAvailablePort()
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, addr)
|
||||
assert.True(t, addr.Port > 0)
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(addr, qt.Not(qt.IsNil))
|
||||
c.Assert(addr.Port > 0, qt.Equals, true)
|
||||
}
|
||||
|
||||
func TestFastMD5FromFile(t *testing.T) {
|
||||
@@ -278,17 +279,17 @@ func TestFastMD5FromFile(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
req := require.New(t)
|
||||
c := qt.New(t)
|
||||
|
||||
sf1, err := fs.Open("small.txt")
|
||||
req.NoError(err)
|
||||
c.Assert(err, qt.IsNil)
|
||||
sf2, err := fs.Open("small2.txt")
|
||||
req.NoError(err)
|
||||
c.Assert(err, qt.IsNil)
|
||||
|
||||
bf1, err := fs.Open("bigger.txt")
|
||||
req.NoError(err)
|
||||
c.Assert(err, qt.IsNil)
|
||||
bf2, err := fs.Open("bigger2.txt")
|
||||
req.NoError(err)
|
||||
c.Assert(err, qt.IsNil)
|
||||
|
||||
defer sf1.Close()
|
||||
defer sf2.Close()
|
||||
@@ -296,24 +297,24 @@ func TestFastMD5FromFile(t *testing.T) {
|
||||
defer bf2.Close()
|
||||
|
||||
m1, err := MD5FromFileFast(sf1)
|
||||
req.NoError(err)
|
||||
req.Equal("e9c8989b64b71a88b4efb66ad05eea96", m1)
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(m1, qt.Equals, "e9c8989b64b71a88b4efb66ad05eea96")
|
||||
|
||||
m2, err := MD5FromFileFast(sf2)
|
||||
req.NoError(err)
|
||||
req.NotEqual(m1, m2)
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(m2, qt.Not(qt.Equals), m1)
|
||||
|
||||
m3, err := MD5FromFileFast(bf1)
|
||||
req.NoError(err)
|
||||
req.NotEqual(m2, m3)
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(m3, qt.Not(qt.Equals), m2)
|
||||
|
||||
m4, err := MD5FromFileFast(bf2)
|
||||
req.NoError(err)
|
||||
req.NotEqual(m3, m4)
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(m4, qt.Not(qt.Equals), m3)
|
||||
|
||||
m5, err := MD5FromReader(bf2)
|
||||
req.NoError(err)
|
||||
req.NotEqual(m4, m5)
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(m5, qt.Not(qt.Equals), m4)
|
||||
}
|
||||
|
||||
func BenchmarkMD5FromFileFast(b *testing.B) {
|
||||
|
@@ -27,7 +27,7 @@ import (
|
||||
|
||||
"github.com/gohugoio/hugo/langs"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
qt "github.com/frankban/quicktest"
|
||||
|
||||
"github.com/gohugoio/hugo/hugofs"
|
||||
"github.com/spf13/afero"
|
||||
@@ -35,6 +35,7 @@ import (
|
||||
)
|
||||
|
||||
func TestMakePath(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
tests := []struct {
|
||||
input string
|
||||
expected string
|
||||
@@ -61,7 +62,7 @@ func TestMakePath(t *testing.T) {
|
||||
|
||||
l := langs.NewDefaultLanguage(v)
|
||||
p, err := NewPathSpec(hugofs.NewMem(v), l, nil)
|
||||
require.NoError(t, err)
|
||||
c.Assert(err, qt.IsNil)
|
||||
|
||||
output := p.MakePath(test.input)
|
||||
if output != test.expected {
|
||||
@@ -547,8 +548,8 @@ func TestAbsPathify(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestExtNoDelimiter(t *testing.T) {
|
||||
assert := require.New(t)
|
||||
assert.Equal("json", ExtNoDelimiter(filepath.FromSlash("/my/data.json")))
|
||||
c := qt.New(t)
|
||||
c.Assert(ExtNoDelimiter(filepath.FromSlash("/my/data.json")), qt.Equals, "json")
|
||||
}
|
||||
|
||||
func TestFilename(t *testing.T) {
|
||||
@@ -636,11 +637,11 @@ func TestExtractAndGroupRootPaths(t *testing.T) {
|
||||
|
||||
result := ExtractAndGroupRootPaths(in)
|
||||
|
||||
assert := require.New(t)
|
||||
assert.Equal(filepath.FromSlash("[/a/b/{c,e} /c/d/e]"), fmt.Sprint(result))
|
||||
c := qt.New(t)
|
||||
c.Assert(fmt.Sprint(result), qt.Equals, filepath.FromSlash("[/a/b/{c,e} /c/d/e]"))
|
||||
|
||||
// Make sure the original is preserved
|
||||
assert.Equal(inCopy, in)
|
||||
c.Assert(in, qt.DeepEquals, inCopy)
|
||||
|
||||
}
|
||||
|
||||
|
@@ -17,13 +17,14 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
qt "github.com/frankban/quicktest"
|
||||
"github.com/gohugoio/hugo/hugofs"
|
||||
|
||||
"github.com/gohugoio/hugo/langs"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestNewPathSpecFromConfig(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
v := newTestCfg()
|
||||
l := langs.NewLanguage("no", v)
|
||||
v.Set("disablePathToLower", true)
|
||||
@@ -44,16 +45,16 @@ func TestNewPathSpecFromConfig(t *testing.T) {
|
||||
|
||||
p, err := NewPathSpec(fs, l, nil)
|
||||
|
||||
require.NoError(t, err)
|
||||
require.True(t, p.CanonifyURLs)
|
||||
require.True(t, p.DisablePathToLower)
|
||||
require.True(t, p.RemovePathAccents)
|
||||
require.True(t, p.UglyURLs)
|
||||
require.Equal(t, "no", p.Language.Lang)
|
||||
require.Equal(t, "side", p.PaginatePath)
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(p.CanonifyURLs, qt.Equals, true)
|
||||
c.Assert(p.DisablePathToLower, qt.Equals, true)
|
||||
c.Assert(p.RemovePathAccents, qt.Equals, true)
|
||||
c.Assert(p.UglyURLs, qt.Equals, true)
|
||||
c.Assert(p.Language.Lang, qt.Equals, "no")
|
||||
c.Assert(p.PaginatePath, qt.Equals, "side")
|
||||
|
||||
require.Equal(t, "http://base.com", p.BaseURL.String())
|
||||
require.Equal(t, "thethemes", p.ThemesDir)
|
||||
require.Equal(t, "thework", p.WorkingDir)
|
||||
c.Assert(p.BaseURL.String(), qt.Equals, "http://base.com")
|
||||
c.Assert(p.ThemesDir, qt.Equals, "thethemes")
|
||||
c.Assert(p.WorkingDir, qt.Equals, "thework")
|
||||
|
||||
}
|
||||
|
@@ -20,12 +20,12 @@ import (
|
||||
|
||||
"github.com/alecthomas/chroma/formatters/html"
|
||||
|
||||
qt "github.com/frankban/quicktest"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestParsePygmentsArgs(t *testing.T) {
|
||||
assert := require.New(t)
|
||||
c := qt.New(t)
|
||||
|
||||
for i, this := range []struct {
|
||||
in string
|
||||
@@ -46,7 +46,7 @@ func TestParsePygmentsArgs(t *testing.T) {
|
||||
v.Set("pygmentsStyle", this.pygmentsStyle)
|
||||
v.Set("pygmentsUseClasses", this.pygmentsUseClasses)
|
||||
spec, err := NewContentSpec(v)
|
||||
assert.NoError(err)
|
||||
c.Assert(err, qt.IsNil)
|
||||
|
||||
result1, err := spec.createPygmentsOptionsString(this.in)
|
||||
if b, ok := this.expect1.(bool); ok && !b {
|
||||
@@ -67,7 +67,7 @@ func TestParsePygmentsArgs(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseDefaultPygmentsArgs(t *testing.T) {
|
||||
assert := require.New(t)
|
||||
c := qt.New(t)
|
||||
|
||||
expect := "encoding=utf8,noclasses=false,style=foo"
|
||||
|
||||
@@ -95,7 +95,7 @@ func TestParseDefaultPygmentsArgs(t *testing.T) {
|
||||
}
|
||||
|
||||
spec, err := NewContentSpec(v)
|
||||
assert.NoError(err)
|
||||
c.Assert(err, qt.IsNil)
|
||||
|
||||
result, err := spec.createPygmentsOptionsString(this.in)
|
||||
if err != nil {
|
||||
@@ -134,22 +134,22 @@ func formatterChromaInfo(f *html.Formatter) chromaInfo {
|
||||
}
|
||||
|
||||
func TestChromaHTMLHighlight(t *testing.T) {
|
||||
assert := require.New(t)
|
||||
c := qt.New(t)
|
||||
|
||||
v := viper.New()
|
||||
v.Set("pygmentsUseClasses", true)
|
||||
spec, err := NewContentSpec(v)
|
||||
assert.NoError(err)
|
||||
c.Assert(err, qt.IsNil)
|
||||
|
||||
result, err := spec.Highlight(`echo "Hello"`, "bash", "")
|
||||
assert.NoError(err)
|
||||
c.Assert(err, qt.IsNil)
|
||||
|
||||
assert.Contains(result, `<div class="highlight"><pre class="chroma"><code class="language-bash" data-lang="bash"><span class="nb">echo</span> <span class="s2">"Hello"</span></code></pre></div>`)
|
||||
c.Assert(result, qt.Contains, `<div class="highlight"><pre class="chroma"><code class="language-bash" data-lang="bash"><span class="nb">echo</span> <span class="s2">"Hello"</span></code></pre></div>`)
|
||||
|
||||
}
|
||||
|
||||
func TestChromaHTMLFormatterFromOptions(t *testing.T) {
|
||||
assert := require.New(t)
|
||||
c := qt.New(t)
|
||||
|
||||
for i, this := range []struct {
|
||||
in string
|
||||
@@ -158,40 +158,40 @@ func TestChromaHTMLFormatterFromOptions(t *testing.T) {
|
||||
pygmentsOptions string
|
||||
assert func(c chromaInfo)
|
||||
}{
|
||||
{"", "monokai", true, "style=manni,noclasses=true", func(c chromaInfo) {
|
||||
assert.True(c.classes)
|
||||
assert.False(c.lineNumbers)
|
||||
assert.Equal(0, c.highlightRangesLen)
|
||||
{"", "monokai", true, "style=manni,noclasses=true", func(ci chromaInfo) {
|
||||
c.Assert(ci.classes, qt.Equals, true)
|
||||
c.Assert(ci.lineNumbers, qt.Equals, false)
|
||||
c.Assert(ci.highlightRangesLen, qt.Equals, 0)
|
||||
|
||||
}},
|
||||
{"", nil, nil, "style=monokai,noclasses=false", func(c chromaInfo) {
|
||||
assert.True(c.classes)
|
||||
{"", nil, nil, "style=monokai,noclasses=false", func(ci chromaInfo) {
|
||||
c.Assert(ci.classes, qt.Equals, true)
|
||||
}},
|
||||
{"linenos=sure,hl_lines=1 2 3", nil, nil, "style=monokai,noclasses=false", func(c chromaInfo) {
|
||||
assert.True(c.classes)
|
||||
assert.True(c.lineNumbers)
|
||||
assert.Equal(3, c.highlightRangesLen)
|
||||
assert.Equal("[[1 1] [2 2] [3 3]]", c.highlightRangesStr)
|
||||
assert.Equal(1, c.baseLineNumber)
|
||||
{"linenos=sure,hl_lines=1 2 3", nil, nil, "style=monokai,noclasses=false", func(ci chromaInfo) {
|
||||
c.Assert(ci.classes, qt.Equals, true)
|
||||
c.Assert(ci.lineNumbers, qt.Equals, true)
|
||||
c.Assert(ci.highlightRangesLen, qt.Equals, 3)
|
||||
c.Assert(ci.highlightRangesStr, qt.Equals, "[[1 1] [2 2] [3 3]]")
|
||||
c.Assert(ci.baseLineNumber, qt.Equals, 1)
|
||||
}},
|
||||
{"linenos=inline,hl_lines=1,linenostart=4", nil, nil, "style=monokai,noclasses=false", func(c chromaInfo) {
|
||||
assert.True(c.classes)
|
||||
assert.True(c.lineNumbers)
|
||||
assert.False(c.lineNumbersInTable)
|
||||
assert.Equal(1, c.highlightRangesLen)
|
||||
{"linenos=inline,hl_lines=1,linenostart=4", nil, nil, "style=monokai,noclasses=false", func(ci chromaInfo) {
|
||||
c.Assert(ci.classes, qt.Equals, true)
|
||||
c.Assert(ci.lineNumbers, qt.Equals, true)
|
||||
c.Assert(ci.lineNumbersInTable, qt.Equals, false)
|
||||
c.Assert(ci.highlightRangesLen, qt.Equals, 1)
|
||||
// This compansates for https://github.com/alecthomas/chroma/issues/30
|
||||
assert.Equal("[[4 4]]", c.highlightRangesStr)
|
||||
assert.Equal(4, c.baseLineNumber)
|
||||
c.Assert(ci.highlightRangesStr, qt.Equals, "[[4 4]]")
|
||||
c.Assert(ci.baseLineNumber, qt.Equals, 4)
|
||||
}},
|
||||
{"linenos=table", nil, nil, "style=monokai", func(c chromaInfo) {
|
||||
assert.True(c.lineNumbers)
|
||||
assert.True(c.lineNumbersInTable)
|
||||
{"linenos=table", nil, nil, "style=monokai", func(ci chromaInfo) {
|
||||
c.Assert(ci.lineNumbers, qt.Equals, true)
|
||||
c.Assert(ci.lineNumbersInTable, qt.Equals, true)
|
||||
}},
|
||||
{"style=monokai,noclasses=false", nil, nil, "style=manni,noclasses=true", func(c chromaInfo) {
|
||||
assert.True(c.classes)
|
||||
{"style=monokai,noclasses=false", nil, nil, "style=manni,noclasses=true", func(ci chromaInfo) {
|
||||
c.Assert(ci.classes, qt.Equals, true)
|
||||
}},
|
||||
{"style=monokai,noclasses=true", "friendly", false, "style=manni,noclasses=false", func(c chromaInfo) {
|
||||
assert.False(c.classes)
|
||||
{"style=monokai,noclasses=true", "friendly", false, "style=manni,noclasses=false", func(ci chromaInfo) {
|
||||
c.Assert(ci.classes, qt.Equals, false)
|
||||
}},
|
||||
} {
|
||||
v := viper.New()
|
||||
@@ -207,7 +207,7 @@ func TestChromaHTMLFormatterFromOptions(t *testing.T) {
|
||||
}
|
||||
|
||||
spec, err := NewContentSpec(v)
|
||||
assert.NoError(err)
|
||||
c.Assert(err, qt.IsNil)
|
||||
|
||||
opts, err := spec.parsePygmentsOpts(this.in)
|
||||
if err != nil {
|
||||
@@ -257,7 +257,7 @@ func TestHlLinesToRanges(t *testing.T) {
|
||||
}
|
||||
|
||||
func BenchmarkChromaHighlight(b *testing.B) {
|
||||
assert := require.New(b)
|
||||
c := qt.New(b)
|
||||
v := viper.New()
|
||||
|
||||
v.Set("pygmentsstyle", "trac")
|
||||
@@ -289,7 +289,7 @@ func GetTitleFunc(style string) func(s string) string {
|
||||
`
|
||||
|
||||
spec, err := NewContentSpec(v)
|
||||
assert.NoError(err)
|
||||
c.Assert(err, qt.IsNil)
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
_, err := spec.Highlight(code, "go", "linenos=inline,hl_lines=8 15-17")
|
||||
|
@@ -14,14 +14,12 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
qt "github.com/frankban/quicktest"
|
||||
"github.com/gohugoio/hugo/hugofs"
|
||||
"github.com/gohugoio/hugo/langs"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestURLize(t *testing.T) {
|
||||
@@ -111,7 +109,9 @@ func doTestAbsURL(t *testing.T, defaultInSubDir, addLanguage, multilingual bool,
|
||||
}
|
||||
|
||||
func TestIsAbsURL(t *testing.T) {
|
||||
for i, this := range []struct {
|
||||
c := qt.New(t)
|
||||
|
||||
for _, this := range []struct {
|
||||
a string
|
||||
b bool
|
||||
}{
|
||||
@@ -122,7 +122,7 @@ func TestIsAbsURL(t *testing.T) {
|
||||
{"/content", false},
|
||||
{"content", false},
|
||||
} {
|
||||
require.True(t, IsAbsURL(this.a) == this.b, fmt.Sprintf("Test %d", i))
|
||||
c.Assert(IsAbsURL(this.a) == this.b, qt.Equals, true)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,31 +292,33 @@ func TestAddContextRoot(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPretty(t *testing.T) {
|
||||
assert.Equal(t, PrettifyURLPath("/section/name.html"), "/section/name/index.html")
|
||||
assert.Equal(t, PrettifyURLPath("/section/sub/name.html"), "/section/sub/name/index.html")
|
||||
assert.Equal(t, PrettifyURLPath("/section/name/"), "/section/name/index.html")
|
||||
assert.Equal(t, PrettifyURLPath("/section/name/index.html"), "/section/name/index.html")
|
||||
assert.Equal(t, PrettifyURLPath("/index.html"), "/index.html")
|
||||
assert.Equal(t, PrettifyURLPath("/name.xml"), "/name/index.xml")
|
||||
assert.Equal(t, PrettifyURLPath("/"), "/")
|
||||
assert.Equal(t, PrettifyURLPath(""), "/")
|
||||
assert.Equal(t, PrettifyURL("/section/name.html"), "/section/name")
|
||||
assert.Equal(t, PrettifyURL("/section/sub/name.html"), "/section/sub/name")
|
||||
assert.Equal(t, PrettifyURL("/section/name/"), "/section/name")
|
||||
assert.Equal(t, PrettifyURL("/section/name/index.html"), "/section/name")
|
||||
assert.Equal(t, PrettifyURL("/index.html"), "/")
|
||||
assert.Equal(t, PrettifyURL("/name.xml"), "/name/index.xml")
|
||||
assert.Equal(t, PrettifyURL("/"), "/")
|
||||
assert.Equal(t, PrettifyURL(""), "/")
|
||||
c := qt.New(t)
|
||||
c.Assert("/section/name/index.html", qt.Equals, PrettifyURLPath("/section/name.html"))
|
||||
c.Assert("/section/sub/name/index.html", qt.Equals, PrettifyURLPath("/section/sub/name.html"))
|
||||
c.Assert("/section/name/index.html", qt.Equals, PrettifyURLPath("/section/name/"))
|
||||
c.Assert("/section/name/index.html", qt.Equals, PrettifyURLPath("/section/name/index.html"))
|
||||
c.Assert("/index.html", qt.Equals, PrettifyURLPath("/index.html"))
|
||||
c.Assert("/name/index.xml", qt.Equals, PrettifyURLPath("/name.xml"))
|
||||
c.Assert("/", qt.Equals, PrettifyURLPath("/"))
|
||||
c.Assert("/", qt.Equals, PrettifyURLPath(""))
|
||||
c.Assert("/section/name", qt.Equals, PrettifyURL("/section/name.html"))
|
||||
c.Assert("/section/sub/name", qt.Equals, PrettifyURL("/section/sub/name.html"))
|
||||
c.Assert("/section/name", qt.Equals, PrettifyURL("/section/name/"))
|
||||
c.Assert("/section/name", qt.Equals, PrettifyURL("/section/name/index.html"))
|
||||
c.Assert("/", qt.Equals, PrettifyURL("/index.html"))
|
||||
c.Assert("/name/index.xml", qt.Equals, PrettifyURL("/name.xml"))
|
||||
c.Assert("/", qt.Equals, PrettifyURL("/"))
|
||||
c.Assert("/", qt.Equals, PrettifyURL(""))
|
||||
}
|
||||
|
||||
func TestUgly(t *testing.T) {
|
||||
assert.Equal(t, Uglify("/section/name.html"), "/section/name.html")
|
||||
assert.Equal(t, Uglify("/section/sub/name.html"), "/section/sub/name.html")
|
||||
assert.Equal(t, Uglify("/section/name/"), "/section/name.html")
|
||||
assert.Equal(t, Uglify("/section/name/index.html"), "/section/name.html")
|
||||
assert.Equal(t, Uglify("/index.html"), "/index.html")
|
||||
assert.Equal(t, Uglify("/name.xml"), "/name.xml")
|
||||
assert.Equal(t, Uglify("/"), "/")
|
||||
assert.Equal(t, Uglify(""), "/")
|
||||
c := qt.New(t)
|
||||
c.Assert("/section/name.html", qt.Equals, Uglify("/section/name.html"))
|
||||
c.Assert("/section/sub/name.html", qt.Equals, Uglify("/section/sub/name.html"))
|
||||
c.Assert("/section/name.html", qt.Equals, Uglify("/section/name/"))
|
||||
c.Assert("/section/name.html", qt.Equals, Uglify("/section/name/index.html"))
|
||||
c.Assert("/index.html", qt.Equals, Uglify("/index.html"))
|
||||
c.Assert("/name.xml", qt.Equals, Uglify("/name.xml"))
|
||||
c.Assert("/", qt.Equals, Uglify("/"))
|
||||
c.Assert("/", qt.Equals, Uglify(""))
|
||||
}
|
||||
|
Reference in New Issue
Block a user