Add case=x,x.. aruguments for tests

This commit is contained in:
yuin 2020-07-02 15:28:33 +09:00
parent 33089e232f
commit feff0bb82b
10 changed files with 39 additions and 11 deletions

View file

@ -17,5 +17,5 @@ func TestDefinitionList(t *testing.T) {
DefinitionList, DefinitionList,
), ),
) )
testutil.DoTestCaseFile(markdown, "_test/definition_list.txt", t) testutil.DoTestCaseFile(markdown, "_test/definition_list.txt", t, testutil.ParseCliCaseArg()...)
} }

View file

@ -17,5 +17,5 @@ func TestFootnote(t *testing.T) {
Footnote, Footnote,
), ),
) )
testutil.DoTestCaseFile(markdown, "_test/footnote.txt", t) testutil.DoTestCaseFile(markdown, "_test/footnote.txt", t, testutil.ParseCliCaseArg()...)
} }

View file

@ -18,7 +18,7 @@ func TestLinkify(t *testing.T) {
Linkify, Linkify,
), ),
) )
testutil.DoTestCaseFile(markdown, "_test/linkify.txt", t) testutil.DoTestCaseFile(markdown, "_test/linkify.txt", t, testutil.ParseCliCaseArg()...)
} }
func TestLinkifyWithAllowedProtocols(t *testing.T) { func TestLinkifyWithAllowedProtocols(t *testing.T) {

View file

@ -17,5 +17,5 @@ func TestStrikethrough(t *testing.T) {
Strikethrough, Strikethrough,
), ),
) )
testutil.DoTestCaseFile(markdown, "_test/strikethrough.txt", t) testutil.DoTestCaseFile(markdown, "_test/strikethrough.txt", t, testutil.ParseCliCaseArg()...)
} }

View file

@ -17,5 +17,5 @@ func TestTable(t *testing.T) {
Table, Table,
), ),
) )
testutil.DoTestCaseFile(markdown, "_test/table.txt", t) testutil.DoTestCaseFile(markdown, "_test/table.txt", t, testutil.ParseCliCaseArg()...)
} }

View file

@ -17,5 +17,5 @@ func TestTaskList(t *testing.T) {
TaskList, TaskList,
), ),
) )
testutil.DoTestCaseFile(markdown, "_test/tasklist.txt", t) testutil.DoTestCaseFile(markdown, "_test/tasklist.txt", t, testutil.ParseCliCaseArg()...)
} }

View file

@ -17,5 +17,5 @@ func TestTypographer(t *testing.T) {
Typographer, Typographer,
), ),
) )
testutil.DoTestCaseFile(markdown, "_test/typographer.txt", t) testutil.DoTestCaseFile(markdown, "_test/typographer.txt", t, testutil.ParseCliCaseArg()...)
} }

View file

@ -16,7 +16,7 @@ func TestExtras(t *testing.T) {
html.WithXHTML(), html.WithXHTML(),
html.WithUnsafe(), html.WithUnsafe(),
)) ))
testutil.DoTestCaseFile(markdown, "_test/extra.txt", t) testutil.DoTestCaseFile(markdown, "_test/extra.txt", t, testutil.ParseCliCaseArg()...)
} }
func TestEndsWithNonSpaceCharacters(t *testing.T) { func TestEndsWithNonSpaceCharacters(t *testing.T) {

View file

@ -15,5 +15,5 @@ func TestAttributeAndAutoHeadingID(t *testing.T) {
parser.WithAutoHeadingID(), parser.WithAutoHeadingID(),
), ),
) )
testutil.DoTestCaseFile(markdown, "_test/options.txt", t) testutil.DoTestCaseFile(markdown, "_test/options.txt", t, testutil.ParseCliCaseArg()...)
} }

View file

@ -32,8 +32,25 @@ type MarkdownTestCase struct {
const attributeSeparator = "//- - - - - - - - -//" const attributeSeparator = "//- - - - - - - - -//"
const caseSeparator = "//= = = = = = = = = = = = = = = = = = = = = = = =//" 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. // 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) fp, err := os.Open(filename)
if err != nil { if err != nil {
panic(err) panic(err)
@ -93,8 +110,19 @@ func DoTestCaseFile(m goldmark.Markdown, filename string, t TestingT) {
buf = append(buf, text) buf = append(buf, text)
} }
c.Expected = strings.Join(buf, "\n") 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) cases = append(cases, c)
} }
}
DoTestCases(m, cases, t) DoTestCases(m, cases, t)
} }