Skip to content

Commit afb31c8

Browse files
committed
Move GFM spec out of tables ext, test strikethrough as well
All tests passing already (there's not many).
1 parent aa32a8e commit afb31c8

File tree

6 files changed

+64
-11
lines changed

6 files changed

+64
-11
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.commonmark.ext.gfm.strikethrough;
2+
3+
import org.commonmark.Extension;
4+
import org.commonmark.parser.Parser;
5+
import org.commonmark.renderer.html.HtmlRenderer;
6+
import org.commonmark.testutil.RenderingTestCase;
7+
import org.commonmark.testutil.TestResources;
8+
import org.commonmark.testutil.example.Example;
9+
import org.commonmark.testutil.example.ExampleReader;
10+
import org.junit.Test;
11+
import org.junit.runner.RunWith;
12+
import org.junit.runners.Parameterized;
13+
import org.junit.runners.Parameterized.Parameters;
14+
15+
import java.util.Collections;
16+
import java.util.List;
17+
import java.util.Set;
18+
19+
@RunWith(Parameterized.class)
20+
public class StrikethroughSpecTest extends RenderingTestCase {
21+
22+
private static final Set<Extension> EXTENSIONS = Collections.singleton(StrikethroughExtension.create());
23+
private static final Parser PARSER = Parser.builder().extensions(EXTENSIONS).build();
24+
private static final HtmlRenderer RENDERER = HtmlRenderer.builder().extensions(EXTENSIONS).build();
25+
26+
private final Example example;
27+
28+
public StrikethroughSpecTest(Example example) {
29+
this.example = example;
30+
}
31+
32+
@Parameters(name = "{0}")
33+
public static List<Object[]> data() {
34+
return ExampleReader.readExampleObjects(TestResources.getGfmSpec(), "strikethrough");
35+
}
36+
37+
@Test
38+
public void testHtmlRendering() {
39+
assertRendering(example.getSource(), example.getHtml());
40+
}
41+
42+
@Override
43+
protected String render(String source) {
44+
return RENDERER.render(PARSER.parse(source));
45+
}
46+
}

commonmark-ext-gfm-tables/src/test/java/org/commonmark/ext/gfm/tables/TablesSpecTest.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,7 @@ public TablesSpecTest(Example example) {
3232

3333
@Parameters(name = "{0}")
3434
public static List<Object[]> data() {
35-
List<Example> examples = ExampleReader.readExamples(TestResources.class.getResource("/gfm-spec.txt"));
36-
List<Object[]> data = new ArrayList<>();
37-
for (Example example : examples) {
38-
if (example.getInfo().contains("table")) {
39-
data.add(new Object[]{example});
40-
}
41-
}
42-
return data;
35+
return ExampleReader.readExampleObjects(TestResources.getGfmSpec(), "table");
4336
}
4437

4538
@Test

commonmark-test-util/src/main/java/org/commonmark/testutil/TestResources.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ public static URL getSpec() {
1414
return TestResources.class.getResource("/spec.txt");
1515
}
1616

17+
public static URL getGfmSpec() {
18+
return TestResources.class.getResource("/gfm-spec.txt");
19+
}
20+
1721
public static List<URL> getRegressions() {
1822
return Arrays.asList(
1923
TestResources.class.getResource("/cmark-regression.txt"),

commonmark-test-util/src/main/java/org/commonmark/testutil/example/ExampleReader.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ public static List<Example> readExamples(URL url) {
4242
}
4343
}
4444

45+
public static List<Object[]> readExampleObjects(URL url, String info) {
46+
List<Example> examples = readExamples(url);
47+
List<Object[]> data = new ArrayList<>();
48+
for (Example example : examples) {
49+
if (example.getInfo().contains(info)) {
50+
data.add(new Object[]{example});
51+
}
52+
}
53+
return data;
54+
}
55+
4556
public static List<String> readExampleSources(URL url) {
4657
List<Example> examples = ExampleReader.readExamples(url);
4758
List<String> result = new ArrayList<>();

commonmark-ext-gfm-tables/src/test/resources/gfm-spec.txt renamed to commonmark-test-util/src/main/resources/gfm-spec.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2077,7 +2077,7 @@ followed by one of the strings (case-insensitive) `address`,
20772077
`h1`, `h2`, `h3`, `h4`, `h5`, `h6`, `head`, `header`, `hr`,
20782078
`html`, `iframe`, `legend`, `li`, `link`, `main`, `menu`, `menuitem`,
20792079
`nav`, `noframes`, `ol`, `optgroup`, `option`, `p`, `param`,
2080-
`section`, `source`, `summary`, `table`, `tbody`, `td`,
2080+
`section`, `summary`, `table`, `tbody`, `td`,
20812081
`tfoot`, `th`, `thead`, `title`, `tr`, `track`, `ul`, followed
20822082
by [whitespace], the end of the line, the string `>`, or
20832083
the string `/>`.\
@@ -10224,4 +10224,3 @@ closers:
1022410224

1022510225
After we're done, we remove all delimiters above `stack_bottom` from the
1022610226
delimiter stack.
10227-

etc/update-spec.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fi
77

88
version=$1
99
curl -L "https://raw.githubusercontent.com/commonmark/commonmark-spec/$version/spec.txt" -o commonmark-test-util/src/main/resources/spec.txt
10-
curl -L "https://raw.githubusercontent.com/github/cmark-gfm/master/test/spec.txt" -o commonmark-ext-gfm-tables/src/test/resources/gfm-spec.txt
10+
curl -L "https://raw.githubusercontent.com/github/cmark-gfm/master/test/spec.txt" -o commonmark-test-util/src/main/resources/gfm-spec.txt
1111

1212
echo "Check cmark and commonmark.js regression.txt:"
1313
echo "https://github.com/commonmark/cmark/blob/master/test/regression.txt"

0 commit comments

Comments
 (0)