Skip to content

Commit 67dc8c3

Browse files
committed
make spec example renderer base usable by non-flexmark renderers
1 parent b073be3 commit 67dc8c3

File tree

17 files changed

+185
-172
lines changed

17 files changed

+185
-172
lines changed

VERSION.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ flexmark-java
88
- [To Do](#to-do)
99
- [Next 0.60.0](#next-0600)
1010
- [API Changes](#api-changes)
11-
- [Next 0.59.17](#next-05917)
11+
- [Next 0.59.19](#next-05919)
12+
- [0.59.17](#05917)
1213
- [0.59.15](#05915)
1314
- [0.59.13](#05913)
1415
- [0.59.11](#05911)
@@ -142,7 +143,7 @@ Please give feedback on the upcoming changes if you have concerns about breaking
142143
* `com.vladsch.flexmark.util.ast.NodeAdaptingVisitHandler`
143144
* `com.vladsch.flexmark.util.ast.NodeAdaptingVisitor`
144145

145-
Next 0.59.17
146+
Next 0.59.19
146147
------------
147148

148149
* [ ] Fix: Change spec example to variable number of sections
@@ -154,6 +155,14 @@ Next 0.59.17
154155
spec test and not requiring deep inheritance dependencies. Merge full test spec and
155156
individual tests. for example see MdNav `LightPlatformCodeInsightSpecTestCase`
156157

158+
0.59.17
159+
-------
160+
161+
* Fix: make `SpecExampleRendererBase` reusable by moving any references to flexmark parsing
162+
rendering specifics to `FlexmarkSpecExampleRenderer` and moving up not related to flexmark
163+
parsing, like caching of generated HTML and AST.
164+
* Fix: consolidate full spec and individual example test case in to one method.
165+
157166
0.59.15
158167
-------
159168

flexmark-core-test/src/main/java/com/vladsch/flexmark/core/test/util/FormatterTranslationSpecTestBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ public abstract class FormatterTranslationSpecTestBase extends ComboSpecTestCase
3535
optionsMap.put("no-tailing-blanks", new MutableDataSet().set(Formatter.MAX_TRAILING_BLANK_LINES, 0));
3636
}
3737
public FormatterTranslationSpecTestBase(@NotNull SpecExample example, @Nullable Map<String, DataHolder> optionMap, @Nullable DataHolder... defaultOptions) {
38-
super(example, optionsMaps(optionsMap, optionMap), dataHolders(OPTIONS, defaultOptions));
38+
super(example, ComboSpecTestCase.optionsMaps(optionsMap, optionMap), ComboSpecTestCase.dataHolders(OPTIONS, defaultOptions));
3939
}
4040
}

flexmark-core-test/src/main/java/com/vladsch/flexmark/core/test/util/RendererSpecTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public abstract class RendererSpecTest extends ComboSpecTestCase {
2424
optionsMap.put("src-pos", new MutableDataSet().set(HtmlRenderer.SOURCE_POSITION_ATTRIBUTE, "md-pos"));
2525
}
2626
public RendererSpecTest(@NotNull SpecExample example, @Nullable Map<String, DataHolder> optionMap, @Nullable DataHolder... defaultOptions) {
27-
super(example, optionsMaps(optionsMap, optionMap), dataHolders(OPTIONS, defaultOptions));
27+
super(example, ComboSpecTestCase.optionsMaps(optionsMap, optionMap), ComboSpecTestCase.dataHolders(OPTIONS, defaultOptions));
2828
}
2929

3030
/**

flexmark-core-test/src/main/java/com/vladsch/flexmark/core/test/util/TranslationFormatterSpecTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.vladsch.flexmark.html.renderer.HeaderIdGenerator;
77
import com.vladsch.flexmark.parser.Parser;
88
import com.vladsch.flexmark.test.spec.SpecExample;
9+
import com.vladsch.flexmark.test.util.ComboSpecTestCase;
910
import com.vladsch.flexmark.test.util.FlexmarkSpecExampleRenderer;
1011
import com.vladsch.flexmark.test.util.SpecExampleRenderer;
1112
import com.vladsch.flexmark.test.util.TestUtils;
@@ -43,7 +44,7 @@ public abstract class TranslationFormatterSpecTest extends FormatterTranslationS
4344
optionsMap.put("ast-details", new MutableDataSet().set(AST_DETAILS, true));
4445
}
4546
public TranslationFormatterSpecTest(@NotNull SpecExample example, @Nullable Map<String, DataHolder> optionMap, @Nullable DataHolder... defaultOptions) {
46-
super(example, optionsMaps(optionsMap, optionMap), dataHolders(OPTIONS, defaultOptions));
47+
super(example, ComboSpecTestCase.optionsMaps(optionsMap, optionMap), ComboSpecTestCase.dataHolders(OPTIONS, defaultOptions));
4748
}
4849

4950
private Parser getParser(@Nullable DataHolder OPTIONS) {

flexmark-core-test/src/test/java/com/vladsch/flexmark/core/test/util/formatter/ComboCoreFormatterSpecTestBase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.vladsch.flexmark.formatter.Formatter;
55
import com.vladsch.flexmark.parser.Parser;
66
import com.vladsch.flexmark.test.spec.SpecExample;
7+
import com.vladsch.flexmark.test.util.ComboSpecTestCase;
78
import com.vladsch.flexmark.util.ast.KeepType;
89
import com.vladsch.flexmark.util.data.DataHolder;
910
import com.vladsch.flexmark.util.data.MutableDataSet;
@@ -63,6 +64,6 @@ public abstract class ComboCoreFormatterSpecTestBase extends FormatterSpecTest {
6364
optionsMap.put("no-soft-breaks", new MutableDataSet().set(Formatter.KEEP_SOFT_LINE_BREAKS, false));
6465
}
6566
public ComboCoreFormatterSpecTestBase(@NotNull SpecExample example, @Nullable Map<String, DataHolder> optionMap, @Nullable DataHolder... defaultOptions) {
66-
super(example, optionsMaps(optionsMap, optionMap), defaultOptions);
67+
super(example, ComboSpecTestCase.optionsMaps(optionsMap, optionMap), defaultOptions);
6768
}
6869
}

flexmark-core-test/src/test/java/com/vladsch/flexmark/core/test/util/renderer/CoreRendererSpecTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.vladsch.flexmark.html.HtmlRenderer;
55
import com.vladsch.flexmark.parser.Parser;
66
import com.vladsch.flexmark.test.spec.SpecExample;
7+
import com.vladsch.flexmark.test.util.ComboSpecTestCase;
78
import com.vladsch.flexmark.util.ast.KeepType;
89
import com.vladsch.flexmark.util.data.DataHolder;
910
import com.vladsch.flexmark.util.data.MutableDataSet;
@@ -124,6 +125,6 @@ public abstract class CoreRendererSpecTest extends RendererSpecTest {
124125
);
125126
}
126127
public CoreRendererSpecTest(@NotNull SpecExample example, @Nullable Map<String, DataHolder> optionMap, @Nullable DataHolder... defaultOptions) {
127-
super(example, optionsMaps(optionsMap, optionMap), dataHolders(OPTIONS, defaultOptions));
128+
super(example, ComboSpecTestCase.optionsMaps(optionsMap, optionMap), ComboSpecTestCase.dataHolders(OPTIONS, defaultOptions));
128129
}
129130
}

flexmark-docx-converter/src/test/java/com/vladsch/flexmark/docx/converter/ComboDocxConverterSpecTestBase.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public abstract class ComboDocxConverterSpecTestBase extends ComboSpecTestCase {
103103
optionsMap.put("yellow-missing-hyperlink", new MutableDataSet().set(DocxRenderer.LOCAL_HYPERLINK_MISSING_HIGHLIGHT, "yellow"));
104104
}
105105
public ComboDocxConverterSpecTestBase(@NotNull SpecExample example, @Nullable Map<String, DataHolder> optionMap, @Nullable DataHolder... defaultOptions) {
106-
super(example, optionsMaps(optionsMap, optionMap), dataHolders(OPTIONS, defaultOptions));
106+
super(example, ComboSpecTestCase.optionsMaps(optionsMap, optionMap), ComboSpecTestCase.dataHolders(OPTIONS, defaultOptions));
107107
}
108108

109109
@Override
@@ -123,7 +123,7 @@ public ComboDocxConverterSpecTestBase(@NotNull SpecExample example, @Nullable Ma
123123
}
124124

125125
@Override
126-
final public void testCase(SpecExampleRenderer exampleRenderer, SpecExampleParse exampleParse, DataHolder exampleOptions) {
126+
final public void addSpecExample(SpecExampleRenderer exampleRenderer, SpecExampleParse exampleParse, DataHolder exampleOptions) {
127127
if (!DUMP_TEST_CASE_FILES) return;
128128
Document document = (Document) ((FlexmarkSpecExampleRenderer) exampleRenderer).getDocument();
129129

@@ -164,7 +164,7 @@ final public void testCase(SpecExampleRenderer exampleRenderer, SpecExampleParse
164164
}
165165

166166
@Override
167-
final public void addSpecExample(@NotNull SpecExampleRenderer exampleRenderer, @NotNull SpecExampleParse exampleParse, DataHolder exampleOptions, boolean ignoredTestCase, @NotNull String html, @Nullable String ast) {
167+
final public void addFullSpecExample(@NotNull SpecExampleRenderer exampleRenderer, @NotNull SpecExampleParse exampleParse, DataHolder exampleOptions, boolean ignoredTestCase, @NotNull String html, @Nullable String ast) {
168168
if (!DUMP_ALL_TESTS_FILES) return;
169169

170170
boolean failed = !ignoredTestCase && !exampleRenderer.getHtml().equals(example.getHtml());

flexmark-html2md-converter/src/test/java/com/vladsch/flexmark/html2md/converter/HtmlConverterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ private static Document linkDocument() {
119119
}
120120

121121
public HtmlConverterTest(@NotNull SpecExample example, @Nullable Map<String, DataHolder> optionMap, @Nullable DataHolder... defaultOptions) {
122-
super(example, optionsMaps(optionsMap, optionMap), dataHolders(OPTIONS, defaultOptions));
122+
super(example, ComboSpecTestCase.optionsMaps(optionsMap, optionMap), ComboSpecTestCase.dataHolders(OPTIONS, defaultOptions));
123123
}
124124

125125
@Override

flexmark-integration-test/src/test/java/com/vladsch/flexmark/integration/SpecIntegrationTest.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,6 @@ protected boolean wantExampleInfo() {
6969
return false;
7070
}
7171

72-
@Override
73-
public void testFullSpec() {
74-
// we don't want it because it will not match and we cannot modify the full spec.
75-
super.testFullSpec();
76-
}
77-
7872
private static Map<String, String> getOverriddenExamples() {
7973
Map<String, String> m = new HashMap<>();
8074

flexmark-test-util/src/main/java/com/vladsch/flexmark/test/util/ComboSpecTestCase.java

Lines changed: 14 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,8 @@ public abstract class ComboSpecTestCase extends FullSpecTestCase {
2626

2727
public ComboSpecTestCase(@NotNull SpecExample example, @Nullable Map<String, DataHolder> optionMap, @Nullable DataHolder... defaultOptions) {
2828
this.example = example;
29-
DataHolder combinedOptions = null;
30-
if (defaultOptions != null) {
31-
for (DataHolder options : defaultOptions) {
32-
combinedOptions = combineOptions(combinedOptions, options);
33-
}
34-
}
35-
this.myDefaultOptions = combinedOptions == null ? null : combinedOptions.toImmutable();
36-
mergeMaps(optionMap);
37-
}
38-
39-
private void mergeMaps(@Nullable Map<String, DataHolder> overrides) {
40-
if (overrides != null) {
41-
optionsMap.putAll(overrides);
42-
}
29+
myDefaultOptions = TestUtils.combineDefaultOptions(defaultOptions,this::combineOptions);
30+
if (optionMap != null) optionsMap.putAll(optionMap);
4331
}
4432

4533
public static @NotNull Map<String, DataHolder> placementAndSortOptions(DataKey<ElementPlacement> placementDataKey, DataKey<ElementPlacementSort> sortDataKey) {
@@ -56,15 +44,12 @@ private void mergeMaps(@Nullable Map<String, DataHolder> overrides) {
5644

5745
@Nullable
5846
public static Map<String, DataHolder> optionsMaps(@Nullable Map<String, DataHolder> other, @Nullable Map<String, DataHolder> overrides) {
59-
if (other != null && overrides != null) {
60-
HashMap<String, DataHolder> map = new HashMap<>(other);
61-
map.putAll(overrides);
62-
return map;
63-
} else if (other != null) {
64-
return other;
65-
} else {
66-
return overrides;
67-
}
47+
return TestUtils.optionsMaps(other, overrides);
48+
}
49+
50+
@Nullable
51+
public static DataHolder[] dataHolders(@Nullable DataHolder other, @Nullable DataHolder[] overrides) {
52+
return TestUtils.dataHolders(other, overrides);
6853
}
6954

7055
@Nullable
@@ -74,39 +59,13 @@ final public DataHolder options(String option) {
7459
return optionsMap.get(option);
7560
}
7661

77-
@Nullable
78-
public static DataHolder[] dataHolders(@Nullable DataHolder other, @Nullable DataHolder[] overrides) {
79-
if (other == null) return overrides;
80-
else if (overrides == null || overrides.length == 0) return new DataHolder[] { other };
81-
82-
DataHolder[] holders = new DataHolder[overrides.length + 1];
83-
System.arraycopy(overrides, 0, holders, 1, overrides.length);
84-
holders[0] = other;
85-
return holders;
86-
}
87-
88-
protected @NotNull ResourceLocation getLocation(@NotNull String resourcePath) {
89-
return new ResourceLocation(ComboSpecTestCase.class, resourcePath, TestUtils.DEFAULT_URL_PREFIX);
90-
}
91-
92-
protected @NotNull ResourceLocation getLocation(@NotNull Class<?> resourceClass, @NotNull String resourcePath) {
93-
return new ResourceLocation(resourceClass, resourcePath, TestUtils.DEFAULT_URL_PREFIX);
94-
}
95-
96-
protected @NotNull ResourceLocation getLocation(@NotNull Class<?> resourceClass, @NotNull String resourcePath, @NotNull String fileUrlPrefix) {
97-
return new ResourceLocation(resourceClass, resourcePath, fileUrlPrefix);
98-
}
99-
100-
@Test
101-
public void testHtmlRendering() {
102-
if (!example.isSpecExample()) return;
103-
assertRendering(example);
104-
}
105-
10662
@Test
107-
public void testFullSpec() {
108-
if (!example.isFullSpecExample()) return;
109-
super.testFullSpec();
63+
public void testSpecExample() {
64+
if (example.isFullSpecExample()) {
65+
super.testSpecExample();
66+
} else {
67+
assertRendering(example);
68+
}
11069
}
11170

11271
protected static @NotNull List<Object[]> getTestData(@NotNull String resourcePath) {

0 commit comments

Comments
 (0)