mirror of
https://github.com/yuin/goldmark
synced 2025-03-04 23:04:52 +00:00
Add case=x,x.. aruguments for tests
This commit is contained in:
parent
33089e232f
commit
feff0bb82b
10 changed files with 39 additions and 11 deletions
|
|
@ -17,5 +17,5 @@ func TestDefinitionList(t *testing.T) {
|
|||
DefinitionList,
|
||||
),
|
||||
)
|
||||
testutil.DoTestCaseFile(markdown, "_test/definition_list.txt", t)
|
||||
testutil.DoTestCaseFile(markdown, "_test/definition_list.txt", t, testutil.ParseCliCaseArg()...)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,5 +17,5 @@ func TestFootnote(t *testing.T) {
|
|||
Footnote,
|
||||
),
|
||||
)
|
||||
testutil.DoTestCaseFile(markdown, "_test/footnote.txt", t)
|
||||
testutil.DoTestCaseFile(markdown, "_test/footnote.txt", t, testutil.ParseCliCaseArg()...)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ func TestLinkify(t *testing.T) {
|
|||
Linkify,
|
||||
),
|
||||
)
|
||||
testutil.DoTestCaseFile(markdown, "_test/linkify.txt", t)
|
||||
testutil.DoTestCaseFile(markdown, "_test/linkify.txt", t, testutil.ParseCliCaseArg()...)
|
||||
}
|
||||
|
||||
func TestLinkifyWithAllowedProtocols(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -17,5 +17,5 @@ func TestStrikethrough(t *testing.T) {
|
|||
Strikethrough,
|
||||
),
|
||||
)
|
||||
testutil.DoTestCaseFile(markdown, "_test/strikethrough.txt", t)
|
||||
testutil.DoTestCaseFile(markdown, "_test/strikethrough.txt", t, testutil.ParseCliCaseArg()...)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,5 +17,5 @@ func TestTable(t *testing.T) {
|
|||
Table,
|
||||
),
|
||||
)
|
||||
testutil.DoTestCaseFile(markdown, "_test/table.txt", t)
|
||||
testutil.DoTestCaseFile(markdown, "_test/table.txt", t, testutil.ParseCliCaseArg()...)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,5 +17,5 @@ func TestTaskList(t *testing.T) {
|
|||
TaskList,
|
||||
),
|
||||
)
|
||||
testutil.DoTestCaseFile(markdown, "_test/tasklist.txt", t)
|
||||
testutil.DoTestCaseFile(markdown, "_test/tasklist.txt", t, testutil.ParseCliCaseArg()...)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,5 +17,5 @@ func TestTypographer(t *testing.T) {
|
|||
Typographer,
|
||||
),
|
||||
)
|
||||
testutil.DoTestCaseFile(markdown, "_test/typographer.txt", t)
|
||||
testutil.DoTestCaseFile(markdown, "_test/typographer.txt", t, testutil.ParseCliCaseArg()...)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ func TestExtras(t *testing.T) {
|
|||
html.WithXHTML(),
|
||||
html.WithUnsafe(),
|
||||
))
|
||||
testutil.DoTestCaseFile(markdown, "_test/extra.txt", t)
|
||||
testutil.DoTestCaseFile(markdown, "_test/extra.txt", t, testutil.ParseCliCaseArg()...)
|
||||
}
|
||||
|
||||
func TestEndsWithNonSpaceCharacters(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -15,5 +15,5 @@ func TestAttributeAndAutoHeadingID(t *testing.T) {
|
|||
parser.WithAutoHeadingID(),
|
||||
),
|
||||
)
|
||||
testutil.DoTestCaseFile(markdown, "_test/options.txt", t)
|
||||
testutil.DoTestCaseFile(markdown, "_test/options.txt", t, testutil.ParseCliCaseArg()...)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,8 +32,25 @@ type MarkdownTestCase struct {
|
|||
const attributeSeparator = "//- - - - - - - - -//"
|
||||
const caseSeparator = "//= = = = = = = = = = = = = = = = = = = = = = = =//"
|
||||
|
||||
// ParseCliCaseArg parses -case command line args.
|
||||
func ParseCliCaseArg() []int {
|
||||
ret := []int{}
|
||||
for _, a := range os.Args {
|
||||
if strings.HasPrefix(a, "case=") {
|
||||
parts := strings.Split(a, "=")
|
||||
for _, cas := range strings.Split(parts[1], ",") {
|
||||
value, err := strconv.Atoi(strings.TrimSpace(cas))
|
||||
if err == nil {
|
||||
ret = append(ret, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
// DoTestCaseFile runs test cases in a given file.
|
||||
func DoTestCaseFile(m goldmark.Markdown, filename string, t TestingT) {
|
||||
func DoTestCaseFile(m goldmark.Markdown, filename string, t TestingT, no ...int) {
|
||||
fp, err := os.Open(filename)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
@ -93,8 +110,19 @@ func DoTestCaseFile(m goldmark.Markdown, filename string, t TestingT) {
|
|||
buf = append(buf, text)
|
||||
}
|
||||
c.Expected = strings.Join(buf, "\n")
|
||||
shouldAdd := len(no) == 0
|
||||
if !shouldAdd {
|
||||
for _, n := range no {
|
||||
if n == c.No {
|
||||
shouldAdd = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if shouldAdd {
|
||||
cases = append(cases, c)
|
||||
}
|
||||
}
|
||||
DoTestCases(m, cases, t)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue