mirror of
https://github.com/yuin/goldmark
synced 2025-03-04 23:04:52 +00:00
Move test utilities to testutil/
This moves the following functions meant for use from tests into a
testutil subpackage.
func DoTestCase(m Markdown, testCase MarkdownTestCase, t TestingT)
func DoTestCaseFile(m Markdown, filename string, t TestingT)
func DoTestCases(m goldmark.Markdown, cases []MarkdownTestCase, t TestingT)
This will help keep the top-level goldmark package clean and limited to
core functionality.
(Note that tests in the top-level goldmark package that make use of
these functions must now use the package name `goldmark_test` so that
they're considered separate from the main `goldmark` package, otherwise
you'll see an import cycle: goldmark imports testutil imports goldmark.)
This commit is contained in:
parent
f98eb987aa
commit
8c55e6fa9c
12 changed files with 57 additions and 35 deletions
|
|
@ -1,10 +1,12 @@
|
||||||
package goldmark
|
package goldmark_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
. "github.com/yuin/goldmark"
|
||||||
|
"github.com/yuin/goldmark/testutil"
|
||||||
"github.com/yuin/goldmark/renderer/html"
|
"github.com/yuin/goldmark/renderer/html"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -26,9 +28,9 @@ func TestSpec(t *testing.T) {
|
||||||
if err := json.Unmarshal(bs, &testCases); err != nil {
|
if err := json.Unmarshal(bs, &testCases); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
cases := []MarkdownTestCase{}
|
cases := []testutil.MarkdownTestCase{}
|
||||||
for _, c := range testCases {
|
for _, c := range testCases {
|
||||||
cases = append(cases, MarkdownTestCase{
|
cases = append(cases, testutil.MarkdownTestCase{
|
||||||
No: c.Example,
|
No: c.Example,
|
||||||
Markdown: c.Markdown,
|
Markdown: c.Markdown,
|
||||||
Expected: c.HTML,
|
Expected: c.HTML,
|
||||||
|
|
@ -38,5 +40,5 @@ func TestSpec(t *testing.T) {
|
||||||
html.WithXHTML(),
|
html.WithXHTML(),
|
||||||
html.WithUnsafe(),
|
html.WithUnsafe(),
|
||||||
))
|
))
|
||||||
DoTestCases(markdown, cases, t)
|
testutil.DoTestCases(markdown, cases, t)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
package extension
|
package extension
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/yuin/goldmark"
|
|
||||||
"github.com/yuin/goldmark/renderer/html"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/yuin/goldmark"
|
||||||
|
"github.com/yuin/goldmark/testutil"
|
||||||
|
"github.com/yuin/goldmark/renderer/html"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDefinitionList(t *testing.T) {
|
func TestDefinitionList(t *testing.T) {
|
||||||
|
|
@ -15,5 +17,5 @@ func TestDefinitionList(t *testing.T) {
|
||||||
DefinitionList,
|
DefinitionList,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
goldmark.DoTestCaseFile(markdown, "_test/definition_list.txt", t)
|
testutil.DoTestCaseFile(markdown, "_test/definition_list.txt", t)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
package extension
|
package extension
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/yuin/goldmark"
|
|
||||||
"github.com/yuin/goldmark/renderer/html"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/yuin/goldmark"
|
||||||
|
"github.com/yuin/goldmark/testutil"
|
||||||
|
"github.com/yuin/goldmark/renderer/html"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFootnote(t *testing.T) {
|
func TestFootnote(t *testing.T) {
|
||||||
|
|
@ -15,5 +17,5 @@ func TestFootnote(t *testing.T) {
|
||||||
Footnote,
|
Footnote,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
goldmark.DoTestCaseFile(markdown, "_test/footnote.txt", t)
|
testutil.DoTestCaseFile(markdown, "_test/footnote.txt", t)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
package extension
|
package extension
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/yuin/goldmark"
|
|
||||||
"github.com/yuin/goldmark/renderer/html"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/yuin/goldmark"
|
||||||
|
"github.com/yuin/goldmark/testutil"
|
||||||
|
"github.com/yuin/goldmark/renderer/html"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLinkify(t *testing.T) {
|
func TestLinkify(t *testing.T) {
|
||||||
|
|
@ -15,5 +17,5 @@ func TestLinkify(t *testing.T) {
|
||||||
Linkify,
|
Linkify,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
goldmark.DoTestCaseFile(markdown, "_test/linkify.txt", t)
|
testutil.DoTestCaseFile(markdown, "_test/linkify.txt", t)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
package extension
|
package extension
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/yuin/goldmark"
|
|
||||||
"github.com/yuin/goldmark/renderer/html"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/yuin/goldmark"
|
||||||
|
"github.com/yuin/goldmark/testutil"
|
||||||
|
"github.com/yuin/goldmark/renderer/html"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestStrikethrough(t *testing.T) {
|
func TestStrikethrough(t *testing.T) {
|
||||||
|
|
@ -15,5 +17,5 @@ func TestStrikethrough(t *testing.T) {
|
||||||
Strikethrough,
|
Strikethrough,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
goldmark.DoTestCaseFile(markdown, "_test/strikethrough.txt", t)
|
testutil.DoTestCaseFile(markdown, "_test/strikethrough.txt", t)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
package extension
|
package extension
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/yuin/goldmark"
|
|
||||||
"github.com/yuin/goldmark/renderer/html"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/yuin/goldmark"
|
||||||
|
"github.com/yuin/goldmark/testutil"
|
||||||
|
"github.com/yuin/goldmark/renderer/html"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTable(t *testing.T) {
|
func TestTable(t *testing.T) {
|
||||||
|
|
@ -15,5 +17,5 @@ func TestTable(t *testing.T) {
|
||||||
Table,
|
Table,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
goldmark.DoTestCaseFile(markdown, "_test/table.txt", t)
|
testutil.DoTestCaseFile(markdown, "_test/table.txt", t)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
package extension
|
package extension
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/yuin/goldmark"
|
|
||||||
"github.com/yuin/goldmark/renderer/html"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/yuin/goldmark"
|
||||||
|
"github.com/yuin/goldmark/testutil"
|
||||||
|
"github.com/yuin/goldmark/renderer/html"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTaskList(t *testing.T) {
|
func TestTaskList(t *testing.T) {
|
||||||
|
|
@ -15,5 +17,5 @@ func TestTaskList(t *testing.T) {
|
||||||
TaskList,
|
TaskList,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
goldmark.DoTestCaseFile(markdown, "_test/tasklist.txt", t)
|
testutil.DoTestCaseFile(markdown, "_test/tasklist.txt", t)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
package extension
|
package extension
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/yuin/goldmark"
|
|
||||||
"github.com/yuin/goldmark/renderer/html"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/yuin/goldmark"
|
||||||
|
"github.com/yuin/goldmark/testutil"
|
||||||
|
"github.com/yuin/goldmark/renderer/html"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTypographer(t *testing.T) {
|
func TestTypographer(t *testing.T) {
|
||||||
|
|
@ -15,5 +17,5 @@ func TestTypographer(t *testing.T) {
|
||||||
Typographer,
|
Typographer,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
goldmark.DoTestCaseFile(markdown, "_test/typographer.txt", t)
|
testutil.DoTestCaseFile(markdown, "_test/typographer.txt", t)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
package goldmark
|
package goldmark_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
. "github.com/yuin/goldmark"
|
||||||
|
"github.com/yuin/goldmark/testutil"
|
||||||
"github.com/yuin/goldmark/renderer/html"
|
"github.com/yuin/goldmark/renderer/html"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -11,5 +13,5 @@ func TestDefinitionList(t *testing.T) {
|
||||||
html.WithXHTML(),
|
html.WithXHTML(),
|
||||||
html.WithUnsafe(),
|
html.WithUnsafe(),
|
||||||
))
|
))
|
||||||
DoTestCaseFile(markdown, "_test/extra.txt", t)
|
testutil.DoTestCaseFile(markdown, "_test/extra.txt", t)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,11 @@
|
||||||
package goldmark
|
package goldmark_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/yuin/goldmark/parser"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
. "github.com/yuin/goldmark"
|
||||||
|
"github.com/yuin/goldmark/testutil"
|
||||||
|
"github.com/yuin/goldmark/parser"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAttributeAndAutoHeadingID(t *testing.T) {
|
func TestAttributeAndAutoHeadingID(t *testing.T) {
|
||||||
|
|
@ -12,5 +15,5 @@ func TestAttributeAndAutoHeadingID(t *testing.T) {
|
||||||
parser.WithAutoHeadingID(),
|
parser.WithAutoHeadingID(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
DoTestCaseFile(markdown, "_test/options.txt", t)
|
testutil.DoTestCaseFile(markdown, "_test/options.txt", t)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package goldmark
|
package testutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/yuin/goldmark"
|
||||||
"github.com/yuin/goldmark/util"
|
"github.com/yuin/goldmark/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -29,7 +30,7 @@ type MarkdownTestCase struct {
|
||||||
const attributeSeparator = "//- - - - - - - - -//"
|
const attributeSeparator = "//- - - - - - - - -//"
|
||||||
const caseSeparator = "//= = = = = = = = = = = = = = = = = = = = = = = =//"
|
const caseSeparator = "//= = = = = = = = = = = = = = = = = = = = = = = =//"
|
||||||
|
|
||||||
func DoTestCaseFile(m Markdown, filename string, t TestingT) {
|
func DoTestCaseFile(m goldmark.Markdown, filename string, t TestingT) {
|
||||||
fp, err := os.Open(filename)
|
fp, err := os.Open(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
@ -85,13 +86,13 @@ func DoTestCaseFile(m Markdown, filename string, t TestingT) {
|
||||||
DoTestCases(m, cases, t)
|
DoTestCases(m, cases, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
func DoTestCases(m Markdown, cases []MarkdownTestCase, t TestingT) {
|
func DoTestCases(m goldmark.Markdown, cases []MarkdownTestCase, t TestingT) {
|
||||||
for _, testCase := range cases {
|
for _, testCase := range cases {
|
||||||
DoTestCase(m, testCase, t)
|
DoTestCase(m, testCase, t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func DoTestCase(m Markdown, testCase MarkdownTestCase, t TestingT) {
|
func DoTestCase(m goldmark.Markdown, testCase MarkdownTestCase, t TestingT) {
|
||||||
var ok bool
|
var ok bool
|
||||||
var out bytes.Buffer
|
var out bytes.Buffer
|
||||||
defer func() {
|
defer func() {
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package goldmark
|
package testutil
|
||||||
|
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
Loading…
Reference in a new issue