Make tests green on both Pygments 2.0.2 and 2.1.3

See #1969
This commit is contained in:
Bjørn Erik Pedersen
2016-03-13 22:06:51 +01:00
parent 988962e8b5
commit 542e220cc4
2 changed files with 34 additions and 7 deletions

View File

@@ -16,6 +16,7 @@ package helpers
import (
"bytes"
"github.com/spf13/viper"
"regexp"
"testing"
)
@@ -50,9 +51,11 @@ func TestCodeFence(t *testing.T) {
enabled bool
input, expected string
}
// Pygments 2.0 and 2.1 have slightly different outputs so only do partial matching
data := []test{
{true, "<html></html>", "<div class=\"highlight\"><pre><code class=\"language-html\" data-lang=\"html\"><span class=\"nt\">&lt;html&gt;&lt;/html&gt;</span>\n</code></pre></div>\n"},
{false, "<html></html>", "<pre><code class=\"language-html\">&lt;html&gt;&lt;/html&gt;</code></pre>\n"},
{true, "<html></html>", `(?s)^<div class="highlight"><pre><code class="language-html" data-lang="html">.*?</code></pre></div>\n$`},
{false, "<html></html>", `(?s)^<pre><code class="language-html">.*?</code></pre>\n$`},
}
viper.Reset()
@@ -65,12 +68,21 @@ func TestCodeFence(t *testing.T) {
viper.Set("PygmentsCodeFences", d.enabled)
result := render(d.input)
if result != d.expected {
expectedRe, err := regexp.Compile(d.expected)
if err != nil {
t.Fatalf("Invalid regexp", err)
}
matched := expectedRe.MatchString(result)
if !matched {
t.Errorf("Test %d failed. BlackFriday enabled:%t, Expected:\n%q got:\n%q", i, d.enabled, d.expected, result)
}
result = renderWithMmark(d.input)
if result != d.expected {
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)
}
}