diff --git a/extension/definition_list_test.go b/extension/definition_list_test.go index 6280a64..d9dfa6c 100644 --- a/extension/definition_list_test.go +++ b/extension/definition_list_test.go @@ -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()...) } diff --git a/extension/footnote_test.go b/extension/footnote_test.go index 447d177..08e29d8 100644 --- a/extension/footnote_test.go +++ b/extension/footnote_test.go @@ -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()...) } diff --git a/extension/linkify_test.go b/extension/linkify_test.go index 18d1331..d096aca 100644 --- a/extension/linkify_test.go +++ b/extension/linkify_test.go @@ -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) { diff --git a/extension/strikethrough_test.go b/extension/strikethrough_test.go index 2569bff..3274c0e 100644 --- a/extension/strikethrough_test.go +++ b/extension/strikethrough_test.go @@ -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()...) } diff --git a/extension/table_test.go b/extension/table_test.go index baacdf7..cea3c8e 100644 --- a/extension/table_test.go +++ b/extension/table_test.go @@ -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()...) } diff --git a/extension/tasklist_test.go b/extension/tasklist_test.go index 6a04cba..e376227 100644 --- a/extension/tasklist_test.go +++ b/extension/tasklist_test.go @@ -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()...) } diff --git a/extension/typographer_test.go b/extension/typographer_test.go index 0b1b66f..f8eded1 100644 --- a/extension/typographer_test.go +++ b/extension/typographer_test.go @@ -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()...) } diff --git a/extra_test.go b/extra_test.go index bddfe3f..892848e 100644 --- a/extra_test.go +++ b/extra_test.go @@ -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) { diff --git a/options_test.go b/options_test.go index 4375b63..9607eb3 100644 --- a/options_test.go +++ b/options_test.go @@ -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()...) } diff --git a/testutil/testutil.go b/testutil/testutil.go index ac2f2a2..e24f89d 100644 --- a/testutil/testutil.go +++ b/testutil/testutil.go @@ -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,7 +110,18 @@ func DoTestCaseFile(m goldmark.Markdown, filename string, t TestingT) { buf = append(buf, text) } c.Expected = strings.Join(buf, "\n") - cases = append(cases, c) + 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) }