diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-02-05 10:20:06 +0700 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-02-17 17:15:26 +0100 |
commit | 93ca7c9e958e34469a337e4efcc7c75774ec50fd (patch) | |
tree | 5dfa296cfe74fd5ef8f0d41ea4078704f453aa04 /helpers/content_renderer_test.go | |
parent | e34af6ee30f70f5780a281e2fd8f4ed9b487ee61 (diff) |
all: Refactor to nonglobal Viper, i18n etc.
This is a final rewrite that removes all the global state in Hugo, which also enables
the use if `t.Parallel` in tests.
Updates #2701
Fixes #3016
Diffstat (limited to 'helpers/content_renderer_test.go')
-rw-r--r-- | helpers/content_renderer_test.go | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/helpers/content_renderer_test.go b/helpers/content_renderer_test.go index 82168fcfd..ab663966b 100644 --- a/helpers/content_renderer_test.go +++ b/helpers/content_renderer_test.go @@ -22,9 +22,9 @@ import ( ) // Renders a codeblock using Blackfriday -func render(input string) string { - ctx := newViperProvidedRenderingContext() - render := getHTMLRenderer(0, ctx) +func (c ContentSpec) render(input string) string { + ctx := newRenderingContext(c.cfg) + render := c.getHTMLRenderer(0, ctx) buf := &bytes.Buffer{} render.BlockCode(buf, []byte(input), "html") @@ -32,9 +32,9 @@ func render(input string) string { } // Renders a codeblock using Mmark -func renderWithMmark(input string) string { - ctx := newViperProvidedRenderingContext() - render := getMmarkHTMLRenderer(0, ctx) +func (c ContentSpec) renderWithMmark(input string) string { + ctx := newRenderingContext(c.cfg) + render := c.getMmarkHTMLRenderer(0, ctx) buf := &bytes.Buffer{} render.BlockCode(buf, []byte(input), "html", []byte(""), false, false) @@ -59,16 +59,16 @@ func TestCodeFence(t *testing.T) { {false, "<html></html>", `(?s)^<pre><code class="language-html">.*?</code></pre>\n$`}, } - viper.Reset() - defer viper.Reset() + for i, d := range data { + v := viper.New() - viper.Set("pygmentsStyle", "monokai") - viper.Set("pygmentsUseClasses", true) + v.Set("pygmentsStyle", "monokai") + v.Set("pygmentsUseClasses", true) + v.Set("pygmentsCodeFences", d.enabled) - for i, d := range data { - viper.Set("pygmentsCodeFences", d.enabled) + c := NewContentSpec(v) - result := render(d.input) + result := c.render(d.input) expectedRe, err := regexp.Compile(d.expected) @@ -81,7 +81,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 = renderWithMmark(d.input) + result = c.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) @@ -90,6 +90,8 @@ func TestCodeFence(t *testing.T) { } func TestBlackfridayTaskList(t *testing.T) { + c := newTestContentSpec() + for i, this := range []struct { markdown string taskListEnabled bool @@ -118,11 +120,11 @@ END </ul> `}, } { - blackFridayConfig := NewBlackfriday(viper.GetViper()) + blackFridayConfig := c.NewBlackfriday() blackFridayConfig.TaskLists = this.taskListEnabled ctx := &RenderingContext{Content: []byte(this.markdown), PageFmt: "markdown", Config: blackFridayConfig} - result := string(RenderBytes(ctx)) + result := string(c.RenderBytes(ctx)) if result != this.expect { t.Errorf("[%d] got \n%v but expected \n%v", i, result, this.expect) |