Skip to content

Commit feff0bb

Browse files
committed
Add case=x,x.. aruguments for tests
1 parent 33089e2 commit feff0bb

10 files changed

+39
-11
lines changed

extension/definition_list_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ func TestDefinitionList(t *testing.T) {
1717
DefinitionList,
1818
),
1919
)
20-
testutil.DoTestCaseFile(markdown, "_test/definition_list.txt", t)
20+
testutil.DoTestCaseFile(markdown, "_test/definition_list.txt", t, testutil.ParseCliCaseArg()...)
2121
}

extension/footnote_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ func TestFootnote(t *testing.T) {
1717
Footnote,
1818
),
1919
)
20-
testutil.DoTestCaseFile(markdown, "_test/footnote.txt", t)
20+
testutil.DoTestCaseFile(markdown, "_test/footnote.txt", t, testutil.ParseCliCaseArg()...)
2121
}

extension/linkify_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func TestLinkify(t *testing.T) {
1818
Linkify,
1919
),
2020
)
21-
testutil.DoTestCaseFile(markdown, "_test/linkify.txt", t)
21+
testutil.DoTestCaseFile(markdown, "_test/linkify.txt", t, testutil.ParseCliCaseArg()...)
2222
}
2323

2424
func TestLinkifyWithAllowedProtocols(t *testing.T) {

extension/strikethrough_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ func TestStrikethrough(t *testing.T) {
1717
Strikethrough,
1818
),
1919
)
20-
testutil.DoTestCaseFile(markdown, "_test/strikethrough.txt", t)
20+
testutil.DoTestCaseFile(markdown, "_test/strikethrough.txt", t, testutil.ParseCliCaseArg()...)
2121
}

extension/table_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ func TestTable(t *testing.T) {
1717
Table,
1818
),
1919
)
20-
testutil.DoTestCaseFile(markdown, "_test/table.txt", t)
20+
testutil.DoTestCaseFile(markdown, "_test/table.txt", t, testutil.ParseCliCaseArg()...)
2121
}

extension/tasklist_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ func TestTaskList(t *testing.T) {
1717
TaskList,
1818
),
1919
)
20-
testutil.DoTestCaseFile(markdown, "_test/tasklist.txt", t)
20+
testutil.DoTestCaseFile(markdown, "_test/tasklist.txt", t, testutil.ParseCliCaseArg()...)
2121
}

extension/typographer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ func TestTypographer(t *testing.T) {
1717
Typographer,
1818
),
1919
)
20-
testutil.DoTestCaseFile(markdown, "_test/typographer.txt", t)
20+
testutil.DoTestCaseFile(markdown, "_test/typographer.txt", t, testutil.ParseCliCaseArg()...)
2121
}

extra_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func TestExtras(t *testing.T) {
1616
html.WithXHTML(),
1717
html.WithUnsafe(),
1818
))
19-
testutil.DoTestCaseFile(markdown, "_test/extra.txt", t)
19+
testutil.DoTestCaseFile(markdown, "_test/extra.txt", t, testutil.ParseCliCaseArg()...)
2020
}
2121

2222
func TestEndsWithNonSpaceCharacters(t *testing.T) {

options_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ func TestAttributeAndAutoHeadingID(t *testing.T) {
1515
parser.WithAutoHeadingID(),
1616
),
1717
)
18-
testutil.DoTestCaseFile(markdown, "_test/options.txt", t)
18+
testutil.DoTestCaseFile(markdown, "_test/options.txt", t, testutil.ParseCliCaseArg()...)
1919
}

testutil/testutil.go

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,25 @@ type MarkdownTestCase struct {
3232
const attributeSeparator = "//- - - - - - - - -//"
3333
const caseSeparator = "//= = = = = = = = = = = = = = = = = = = = = = = =//"
3434

35+
// ParseCliCaseArg parses -case command line args.
36+
func ParseCliCaseArg() []int {
37+
ret := []int{}
38+
for _, a := range os.Args {
39+
if strings.HasPrefix(a, "case=") {
40+
parts := strings.Split(a, "=")
41+
for _, cas := range strings.Split(parts[1], ",") {
42+
value, err := strconv.Atoi(strings.TrimSpace(cas))
43+
if err == nil {
44+
ret = append(ret, value)
45+
}
46+
}
47+
}
48+
}
49+
return ret
50+
}
51+
3552
// DoTestCaseFile runs test cases in a given file.
36-
func DoTestCaseFile(m goldmark.Markdown, filename string, t TestingT) {
53+
func DoTestCaseFile(m goldmark.Markdown, filename string, t TestingT, no ...int) {
3754
fp, err := os.Open(filename)
3855
if err != nil {
3956
panic(err)
@@ -93,7 +110,18 @@ func DoTestCaseFile(m goldmark.Markdown, filename string, t TestingT) {
93110
buf = append(buf, text)
94111
}
95112
c.Expected = strings.Join(buf, "\n")
96-
cases = append(cases, c)
113+
shouldAdd := len(no) == 0
114+
if !shouldAdd {
115+
for _, n := range no {
116+
if n == c.No {
117+
shouldAdd = true
118+
break
119+
}
120+
}
121+
}
122+
if shouldAdd {
123+
cases = append(cases, c)
124+
}
97125
}
98126
DoTestCases(m, cases, t)
99127
}

0 commit comments

Comments
 (0)