1
0
mirror of https://github.com/danog/blackfriday.git synced 2024-11-26 20:14:43 +01:00

Print diffs for reference tests (#481)

Fixes #469
This commit is contained in:
Cameron Moore 2018-09-04 16:36:14 -05:00 committed by Vytautas Šaltenis
parent eebcfd6bbf
commit 2ab1ea34bd

View File

@ -18,6 +18,8 @@ import (
"path/filepath"
"regexp"
"testing"
"github.com/pmezard/go-difflib/difflib"
)
type TestParams struct {
@ -168,8 +170,7 @@ func doTestsReference(t *testing.T, files []string, flag Extensions) {
actual := string(runMarkdown(input, params))
if actual != expected {
t.Errorf("\n [%#v]\nExpected[%#v]\nActual [%#v]",
basename+".text", expected, actual)
t.Errorf("\n" + doTestDiff(basename, expected, actual))
}
// now test every prefix of every input to check for
@ -184,3 +185,14 @@ func doTestsReference(t *testing.T, files []string, flag Extensions) {
}
})
}
func doTestDiff(name, expected, actual string) string {
d, _ := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{
A: difflib.SplitLines(expected),
B: difflib.SplitLines(actual),
FromFile: "expect: " + name,
ToFile: "actual: " + name,
Context: 1,
})
return d
}