diff --git a/CHANGELOG.md b/CHANGELOG.md index f3b70b9eb..92ddbac52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html), with the exception that 0.x versions can break between minor versions. +## Unreleased +### Changed +- Parse backslash followed by unescapable character the same way as + the reference implementations. +### Fixed +- Fix tab handling in ATX and Setext headings. + ## [0.11.0] - 2018-01-17 ### Added - The extension for tables now also renders to plain text diff --git a/commonmark-android-test/app/src/androidTest/java/com/atlassian/commonmark/android/test/AndroidSupportTest.java b/commonmark-android-test/app/src/androidTest/java/com/atlassian/commonmark/android/test/AndroidSupportTest.java index ecb9fcd86..26fd2c360 100644 --- a/commonmark-android-test/app/src/androidTest/java/com/atlassian/commonmark/android/test/AndroidSupportTest.java +++ b/commonmark-android-test/app/src/androidTest/java/com/atlassian/commonmark/android/test/AndroidSupportTest.java @@ -10,7 +10,7 @@ import org.commonmark.node.Node; import org.commonmark.parser.Parser; import org.commonmark.renderer.html.HtmlRenderer; -import org.commonmark.testutil.spec.SpecReader; +import org.commonmark.testutil.TestResources; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -30,7 +30,7 @@ public class AndroidSupportTest { @Before public void setUp() throws Exception { - spec = SpecReader.readSpec(); + spec = TestResources.readAsString(TestResources.getSpec()); } @Test diff --git a/commonmark-integration-test/src/test/java/org/commonmark/integration/BoundsIntegrationTest.java b/commonmark-integration-test/src/test/java/org/commonmark/integration/BoundsIntegrationTest.java index 981da1540..8ee15164a 100644 --- a/commonmark-integration-test/src/test/java/org/commonmark/integration/BoundsIntegrationTest.java +++ b/commonmark-integration-test/src/test/java/org/commonmark/integration/BoundsIntegrationTest.java @@ -2,8 +2,9 @@ import org.commonmark.node.Node; import org.commonmark.parser.Parser; -import org.commonmark.testutil.spec.SpecExample; -import org.commonmark.testutil.spec.SpecReader; +import org.commonmark.testutil.TestResources; +import org.commonmark.testutil.example.Example; +import org.commonmark.testutil.example.ExampleReader; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -29,9 +30,9 @@ public BoundsIntegrationTest(String input) { @Parameterized.Parameters(name = "{0}") public static List data() { - List examples = SpecReader.readExamples(); + List examples = ExampleReader.readExamples(TestResources.getSpec()); List data = new ArrayList<>(); - for (SpecExample example : examples) { + for (Example example : examples) { data.add(new Object[]{example.getSource()}); } return data; diff --git a/commonmark-integration-test/src/test/java/org/commonmark/integration/PegDownBenchmark.java b/commonmark-integration-test/src/test/java/org/commonmark/integration/PegDownBenchmark.java index 2056868ec..7b61242f4 100644 --- a/commonmark-integration-test/src/test/java/org/commonmark/integration/PegDownBenchmark.java +++ b/commonmark-integration-test/src/test/java/org/commonmark/integration/PegDownBenchmark.java @@ -1,6 +1,7 @@ package org.commonmark.integration; -import org.commonmark.testutil.spec.SpecReader; +import org.commonmark.testutil.TestResources; +import org.commonmark.testutil.example.ExampleReader; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Scope; import org.openjdk.jmh.annotations.State; @@ -17,8 +18,8 @@ @State(Scope.Benchmark) public class PegDownBenchmark { - private static final String SPEC = SpecReader.readSpec(); - private static final List SPEC_EXAMPLES = SpecReader.readExamplesAsString(); + private static final String SPEC = TestResources.readAsString(TestResources.getSpec()); + private static final List SPEC_EXAMPLES = ExampleReader.readExampleSources(TestResources.getSpec()); private static final PegDownProcessor PROCESSOR = new PegDownProcessor(Extensions.FENCED_CODE_BLOCKS); public static void main(String[] args) throws Exception { diff --git a/commonmark-integration-test/src/test/java/org/commonmark/integration/SpecIntegrationTest.java b/commonmark-integration-test/src/test/java/org/commonmark/integration/SpecIntegrationTest.java index 77dd26608..6462f4094 100644 --- a/commonmark-integration-test/src/test/java/org/commonmark/integration/SpecIntegrationTest.java +++ b/commonmark-integration-test/src/test/java/org/commonmark/integration/SpecIntegrationTest.java @@ -8,7 +8,7 @@ import org.commonmark.ext.front.matter.YamlFrontMatterExtension; import org.commonmark.renderer.html.HtmlRenderer; import org.commonmark.parser.Parser; -import org.commonmark.testutil.spec.SpecExample; +import org.commonmark.testutil.example.Example; import org.commonmark.testutil.SpecTestCase; import org.junit.Test; @@ -30,7 +30,7 @@ public class SpecIntegrationTest extends SpecTestCase { private static final HtmlRenderer RENDERER = HtmlRenderer.builder().extensions(EXTENSIONS).percentEncodeUrls(true).build(); private static final Map OVERRIDDEN_EXAMPLES = getOverriddenExamples(); - public SpecIntegrationTest(SpecExample example) { + public SpecIntegrationTest(Example example) { super(example); } diff --git a/commonmark-test-util/src/main/java/org/commonmark/testutil/SpecTestCase.java b/commonmark-test-util/src/main/java/org/commonmark/testutil/SpecTestCase.java index a87d4dad4..1c35b7c28 100644 --- a/commonmark-test-util/src/main/java/org/commonmark/testutil/SpecTestCase.java +++ b/commonmark-test-util/src/main/java/org/commonmark/testutil/SpecTestCase.java @@ -1,7 +1,7 @@ package org.commonmark.testutil; -import org.commonmark.testutil.spec.SpecExample; -import org.commonmark.testutil.spec.SpecReader; +import org.commonmark.testutil.example.Example; +import org.commonmark.testutil.example.ExampleReader; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -13,17 +13,17 @@ @RunWith(Parameterized.class) public abstract class SpecTestCase extends RenderingTestCase { - protected final SpecExample example; + protected final Example example; - public SpecTestCase(SpecExample example) { + public SpecTestCase(Example example) { this.example = example; } @Parameters(name = "{0}") public static List data() { - List examples = SpecReader.readExamples(); + List examples = ExampleReader.readExamples(TestResources.getSpec()); List data = new ArrayList<>(); - for (SpecExample example : examples) { + for (Example example : examples) { data.add(new Object[]{example}); } return data; diff --git a/commonmark-test-util/src/main/java/org/commonmark/testutil/TestResources.java b/commonmark-test-util/src/main/java/org/commonmark/testutil/TestResources.java new file mode 100644 index 000000000..8f6f5c071 --- /dev/null +++ b/commonmark-test-util/src/main/java/org/commonmark/testutil/TestResources.java @@ -0,0 +1,37 @@ +package org.commonmark.testutil; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URL; +import java.nio.charset.Charset; +import java.util.Arrays; +import java.util.List; + +public class TestResources { + + public static URL getSpec() { + return TestResources.class.getResource("/spec.txt"); + } + + public static List getRegressions() { + return Arrays.asList( + TestResources.class.getResource("/cmark-regression.txt"), + TestResources.class.getResource("/commonmark.js-regression.txt") + ); + } + + public static String readAsString(URL url) { + StringBuilder sb = new StringBuilder(); + try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), Charset.forName("UTF-8")))) { + String line; + while ((line = reader.readLine()) != null) { + sb.append(line); + sb.append("\n"); + } + return sb.toString(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/commonmark-test-util/src/main/java/org/commonmark/testutil/spec/SpecExample.java b/commonmark-test-util/src/main/java/org/commonmark/testutil/example/Example.java similarity index 57% rename from commonmark-test-util/src/main/java/org/commonmark/testutil/spec/SpecExample.java rename to commonmark-test-util/src/main/java/org/commonmark/testutil/example/Example.java index decade455..8dc2c1e25 100644 --- a/commonmark-test-util/src/main/java/org/commonmark/testutil/spec/SpecExample.java +++ b/commonmark-test-util/src/main/java/org/commonmark/testutil/example/Example.java @@ -1,13 +1,15 @@ -package org.commonmark.testutil.spec; +package org.commonmark.testutil.example; -public class SpecExample { +public class Example { + private final String filename; private final String section; private final int exampleNumber; private final String source; private final String html; - public SpecExample(String section, int exampleNumber, String source, String html) { + public Example(String filename, String section, int exampleNumber, String source, String html) { + this.filename = filename; this.section = section; this.exampleNumber = exampleNumber; this.source = source; @@ -24,6 +26,6 @@ public String getHtml() { @Override public String toString() { - return "Section \"" + section + "\" example " + exampleNumber; + return "File \"" + filename + "\" section \"" + section + "\" example " + exampleNumber; } } diff --git a/commonmark-test-util/src/main/java/org/commonmark/testutil/spec/SpecReader.java b/commonmark-test-util/src/main/java/org/commonmark/testutil/example/ExampleReader.java similarity index 61% rename from commonmark-test-util/src/main/java/org/commonmark/testutil/spec/SpecReader.java rename to commonmark-test-util/src/main/java/org/commonmark/testutil/example/ExampleReader.java index 4db1aa491..ad288f2fb 100644 --- a/commonmark-test-util/src/main/java/org/commonmark/testutil/spec/SpecReader.java +++ b/commonmark-test-util/src/main/java/org/commonmark/testutil/example/ExampleReader.java @@ -1,20 +1,22 @@ -package org.commonmark.testutil.spec; +package org.commonmark.testutil.example; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; +import java.io.*; +import java.net.URL; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -public class SpecReader { +/** + * Reader for files containing examples of CommonMark source and the expected HTML rendering (e.g. spec.txt). + */ +public class ExampleReader { private static final Pattern SECTION_PATTERN = Pattern.compile("#{1,6} *(.*)"); private final InputStream inputStream; + private final String filename; private State state = State.BEFORE; private String section; @@ -22,52 +24,31 @@ public class SpecReader { private StringBuilder html; private int exampleNumber = 0; - private List examples = new ArrayList<>(); + private List examples = new ArrayList<>(); - private SpecReader(InputStream stream) { + private ExampleReader(InputStream stream, String filename) { this.inputStream = stream; + this.filename = filename; } - public static List readExamples() { - try (InputStream stream = getSpecInputStream()) { - return new SpecReader(stream).read(); + public static List readExamples(URL url) { + try (InputStream stream = url.openStream()) { + return new ExampleReader(stream, new File(url.getPath()).getName()).read(); } catch (IOException e) { throw new RuntimeException(e); } } - public static List readExamplesAsString() { - List examples = SpecReader.readExamples(); + public static List readExampleSources(URL url) { + List examples = ExampleReader.readExamples(url); List result = new ArrayList<>(); - for (SpecExample example : examples) { + for (Example example : examples) { result.add(example.getSource()); } return result; } - public static String readSpec() { - StringBuilder sb = new StringBuilder(); - try (BufferedReader reader = new BufferedReader(new InputStreamReader(getSpecInputStream(), Charset.forName("UTF-8")))) { - String line; - while ((line = reader.readLine()) != null) { - sb.append(line); - sb.append("\n"); - } - return sb.toString(); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - public static InputStream getSpecInputStream() { - InputStream stream = SpecReader.class.getResourceAsStream("/spec.txt"); - if (stream == null) { - throw new IllegalStateException("Could not load spec.txt classpath resource"); - } - return stream; - } - - private List read() throws IOException { + private List read() throws IOException { resetContents(); try (BufferedReader reader = new BufferedReader( @@ -106,7 +87,7 @@ private void processLine(String line) { case HTML: if (line.equals("````````````````````````````````")) { state = State.BEFORE; - examples.add(new SpecExample(section, exampleNumber, + examples.add(new Example(filename, section, exampleNumber, source.toString(), html.toString())); resetContents(); } else { diff --git a/commonmark-test-util/src/main/resources/README.md b/commonmark-test-util/src/main/resources/README.md new file mode 100644 index 000000000..a749c59b5 --- /dev/null +++ b/commonmark-test-util/src/main/resources/README.md @@ -0,0 +1,7 @@ +These files are copied from the CommonMark repositories, namely: + +https://github.com/commonmark/CommonMark/blob/master/spec.txt +https://github.com/commonmark/cmark/blob/master/test/regression.txt +https://github.com/commonmark/commonmark.js/blob/master/test/regression.txt + +They are licensed as stated in those repositories. diff --git a/commonmark-test-util/src/main/resources/cmark-regression.txt b/commonmark-test-util/src/main/resources/cmark-regression.txt new file mode 100644 index 000000000..2984a3bef --- /dev/null +++ b/commonmark-test-util/src/main/resources/cmark-regression.txt @@ -0,0 +1,95 @@ +### Regression tests + +Issue #113: EOL character weirdness on Windows +(Important: first line ends with CR + CR + LF) + +```````````````````````````````` example +line1 + +line2 +. +

line1

+

line2

+```````````````````````````````` + +Issue #114: cmark skipping first character in line +(Important: the blank lines around "Repeatedly" contain a tab.) + +```````````````````````````````` example +By taking it apart + +- alternative solutions +→ +Repeatedly solving +→ +- how techniques +. +

By taking it apart

+
    +
  • alternative solutions
  • +
+

Repeatedly solving

+
    +
  • how techniques
  • +
+```````````````````````````````` + +Issue jgm/CommonMark#430: h2..h6 not recognized as block tags. + +```````````````````````````````` example +

lorem

+ +

lorem

+ +

lorem

+ +

lorem

+ +
lorem
+ +
lorem
+. +

lorem

+

lorem

+

lorem

+

lorem

+
lorem
+
lorem
+```````````````````````````````` + +Issue jgm/commonmark.js#109 - tabs after setext header line + + +```````````````````````````````` example +hi +--→ +. +

hi

+```````````````````````````````` + +Issue #177 - incorrect emphasis parsing + +```````````````````````````````` example +a***b* c* +. +

a*b c

+```````````````````````````````` + +Issue #193 - unescaped left angle brackets in link destination + +```````````````````````````````` example +[a] + +[a]: +. +

a

+```````````````````````````````` + +Issue #192 - escaped spaces in link destination + + +```````````````````````````````` example +[a](te\ st) +. +

[a](te\ st)

+```````````````````````````````` diff --git a/commonmark-test-util/src/main/resources/commonmark.js-regression.txt b/commonmark-test-util/src/main/resources/commonmark.js-regression.txt new file mode 100644 index 000000000..7300952fe --- /dev/null +++ b/commonmark-test-util/src/main/resources/commonmark.js-regression.txt @@ -0,0 +1,104 @@ +# Regression tests + +Eating a character after a partially consumed tab. + +```````````````````````````````` example +* foo +→bar +. +
    +
  • foo +bar
  • +
+```````````````````````````````` + +Type 7 HTML block followed by whitespace (#98). + +```````````````````````````````` example + +x +. + +x +```````````````````````````````` + +h2..h6 raw HTML blocks (jgm/CommonMark#430). + +```````````````````````````````` example +

lorem

+ +

lorem

+ +

lorem

+ +

lorem

+ +
lorem
+ +
lorem
+. +

lorem

+

lorem

+

lorem

+

lorem

+
lorem
+
lorem
+```````````````````````````````` + +Issue #109 - tabs after setext header line + + +```````````````````````````````` example +hi +--→ +. +

hi

+```````````````````````````````` + +Issue #108 - Chinese punctuation not recognized + +```````````````````````````````` example +**。**话 +. +

**。**话

+```````````````````````````````` + +Issue jgm/cmark#177 - incorrect emphasis parsing + +```````````````````````````````` example +a***b* c* +. +

a*b c

+```````````````````````````````` + +Issue jgm/CommonMark#468 - backslash at end of link definition + + +```````````````````````````````` example +[\]: test +. +

[]: test

+```````````````````````````````` + +Issue jgm/commonmark.js#121 - punctuation set different + +```````````````````````````````` example +^_test_ +. +

^test

+```````````````````````````````` + +Issue #116 - tabs before and after ATX closing heading +```````````````````````````````` example +# foo→#→ +. +

foo

+```````````````````````````````` + +commonmark/CommonMark#493 - escaped space not allowed in link +destination. +```````````````````````````````` example +[link](a\ b) +. +

[link](a\ b)

+```````````````````````````````` diff --git a/commonmark/src/main/java/org/commonmark/internal/HeadingParser.java b/commonmark/src/main/java/org/commonmark/internal/HeadingParser.java index 3c26b1cd4..7e4f82c05 100644 --- a/commonmark/src/main/java/org/commonmark/internal/HeadingParser.java +++ b/commonmark/src/main/java/org/commonmark/internal/HeadingParser.java @@ -11,8 +11,8 @@ public class HeadingParser extends AbstractBlockParser { private static Pattern ATX_HEADING = Pattern.compile("^#{1,6}(?:[ \t]+|$)"); - private static Pattern ATX_TRAILING = Pattern.compile("(^| ) *#+ *$"); - private static Pattern SETEXT_HEADING = Pattern.compile("^(?:=+|-+) *$"); + private static Pattern ATX_TRAILING = Pattern.compile("(^|[ \t]+)#+[ \t]*$"); + private static Pattern SETEXT_HEADING = Pattern.compile("^(?:=+|-+)[ \t]*$"); private final Heading block = new Heading(); private final String content; @@ -54,7 +54,8 @@ public BlockStart tryStart(ParserState state, MatchedBlockParser matchedBlockPar int newOffset = nextNonSpace + matcher.group(0).length(); int level = matcher.group(0).trim().length(); // number of #s // remove trailing ###s: - String content = ATX_TRAILING.matcher(line.subSequence(newOffset, line.length())).replaceAll(""); + CharSequence afterLeading = line.subSequence(newOffset, line.length()); + String content = ATX_TRAILING.matcher(afterLeading).replaceAll(""); return BlockStart.of(new HeadingParser(level, content)) .atIndex(line.length()); diff --git a/commonmark/src/main/java/org/commonmark/internal/InlineParserImpl.java b/commonmark/src/main/java/org/commonmark/internal/InlineParserImpl.java index 45da99d90..78cbacd82 100644 --- a/commonmark/src/main/java/org/commonmark/internal/InlineParserImpl.java +++ b/commonmark/src/main/java/org/commonmark/internal/InlineParserImpl.java @@ -648,13 +648,13 @@ private void parseLinkDestinationWithBalancedParens() { case '\0': return; case '\\': - // go to character after backslash - index++; - // stop if that took us to the end of input - if (peek() == '\0') { - return; + // check if we have an escapable character + if (index + 1 < input.length() && ESCAPABLE.matcher(input.substring(index + 1, index + 2)).matches()) { + // skip over the escaped character (after switch) + index++; + break; } - // otherwise, we'll skip over character after backslash + // otherwise, we treat this as a literal backslash break; case '(': parens++; diff --git a/commonmark/src/test/java/org/commonmark/test/HtmlRendererTest.java b/commonmark/src/test/java/org/commonmark/test/HtmlRendererTest.java index d393ee12a..50f321efe 100644 --- a/commonmark/src/test/java/org/commonmark/test/HtmlRendererTest.java +++ b/commonmark/src/test/java/org/commonmark/test/HtmlRendererTest.java @@ -7,7 +7,7 @@ import org.commonmark.parser.Parser; import org.commonmark.renderer.NodeRenderer; import org.commonmark.renderer.html.*; -import org.commonmark.testutil.spec.SpecReader; +import org.commonmark.testutil.TestResources; import org.junit.Test; import java.util.*; @@ -210,7 +210,7 @@ public void imageAltTextWithEntities() { @Test public void threading() throws Exception { Parser parser = Parser.builder().build(); - String spec = SpecReader.readSpec(); + String spec = TestResources.readAsString(TestResources.getSpec()); final Node document = parser.parse(spec); final HtmlRenderer htmlRenderer = HtmlRenderer.builder().build(); diff --git a/commonmark/src/test/java/org/commonmark/test/ParserTest.java b/commonmark/src/test/java/org/commonmark/test/ParserTest.java index b5f487312..27b85f9a9 100644 --- a/commonmark/src/test/java/org/commonmark/test/ParserTest.java +++ b/commonmark/src/test/java/org/commonmark/test/ParserTest.java @@ -7,7 +7,7 @@ import org.commonmark.parser.Parser; import org.commonmark.parser.block.*; import org.commonmark.renderer.html.HtmlRenderer; -import org.commonmark.testutil.spec.SpecReader; +import org.commonmark.testutil.TestResources; import org.junit.Test; import java.io.IOException; @@ -32,13 +32,13 @@ public class ParserTest { public void ioReaderTest() throws IOException { Parser parser = Parser.builder().build(); - InputStream input1 = SpecReader.getSpecInputStream(); + InputStream input1 = TestResources.getSpec().openStream(); Node document1; try (InputStreamReader reader = new InputStreamReader(input1)) { document1 = parser.parseReader(reader); } - String spec = SpecReader.readSpec(); + String spec = TestResources.readAsString(TestResources.getSpec()); Node document2 = parser.parse(spec); HtmlRenderer renderer = HtmlRenderer.builder().escapeHtml(true).build(); @@ -124,7 +124,7 @@ public InlineParser create(InlineParserContext inlineParserContext) { @Test public void threading() throws Exception { final Parser parser = Parser.builder().build(); - final String spec = SpecReader.readSpec(); + final String spec = TestResources.readAsString(TestResources.getSpec()); HtmlRenderer renderer = HtmlRenderer.builder().build(); String expectedRendering = renderer.render(parser.parse(spec)); diff --git a/commonmark/src/test/java/org/commonmark/test/RegressionTest.java b/commonmark/src/test/java/org/commonmark/test/RegressionTest.java new file mode 100644 index 000000000..5d49c2abd --- /dev/null +++ b/commonmark/src/test/java/org/commonmark/test/RegressionTest.java @@ -0,0 +1,52 @@ +package org.commonmark.test; + +import org.commonmark.parser.Parser; +import org.commonmark.renderer.html.HtmlRenderer; +import org.commonmark.testutil.RenderingTestCase; +import org.commonmark.testutil.TestResources; +import org.commonmark.testutil.example.Example; +import org.commonmark.testutil.example.ExampleReader; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +@RunWith(Parameterized.class) +public class RegressionTest extends RenderingTestCase { + + private static final Parser PARSER = Parser.builder().build(); + // The spec says URL-escaping is optional, but the examples assume that it's enabled. + private static final HtmlRenderer RENDERER = HtmlRenderer.builder().percentEncodeUrls(true).build(); + + private final Example example; + + public RegressionTest(Example example) { + this.example = example; + } + + @Parameters(name = "{0}") + public static List data() { + List data = new ArrayList<>(); + for (URL regressionResource : TestResources.getRegressions()) { + List examples = ExampleReader.readExamples(regressionResource); + for (Example example : examples) { + data.add(new Object[]{example}); + } + } + return data; + } + + @Test + public void testHtmlRendering() { + assertRendering(example.getSource(), example.getHtml()); + } + + @Override + protected String render(String source) { + return RENDERER.render(PARSER.parse(source)); + } +} diff --git a/commonmark/src/test/java/org/commonmark/test/SpecBenchmark.java b/commonmark/src/test/java/org/commonmark/test/SpecBenchmark.java index 9b10b0f34..75ce7ffcd 100644 --- a/commonmark/src/test/java/org/commonmark/test/SpecBenchmark.java +++ b/commonmark/src/test/java/org/commonmark/test/SpecBenchmark.java @@ -1,8 +1,9 @@ package org.commonmark.test; -import org.commonmark.renderer.html.HtmlRenderer; import org.commonmark.parser.Parser; -import org.commonmark.testutil.spec.SpecReader; +import org.commonmark.renderer.html.HtmlRenderer; +import org.commonmark.testutil.TestResources; +import org.commonmark.testutil.example.ExampleReader; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Scope; import org.openjdk.jmh.annotations.State; @@ -17,8 +18,8 @@ @State(Scope.Benchmark) public class SpecBenchmark { - private static final String SPEC = SpecReader.readSpec(); - private static final List SPEC_EXAMPLES = SpecReader.readExamplesAsString(); + private static final String SPEC = TestResources.readAsString(TestResources.getSpec()); + private static final List SPEC_EXAMPLES = ExampleReader.readExampleSources(TestResources.getSpec()); private static final Parser PARSER = Parser.builder().build(); private static final HtmlRenderer RENDERER = HtmlRenderer.builder().build(); diff --git a/commonmark/src/test/java/org/commonmark/test/SpecCoreTest.java b/commonmark/src/test/java/org/commonmark/test/SpecCoreTest.java index 2a5ffe510..4e416264f 100644 --- a/commonmark/src/test/java/org/commonmark/test/SpecCoreTest.java +++ b/commonmark/src/test/java/org/commonmark/test/SpecCoreTest.java @@ -6,7 +6,7 @@ import org.commonmark.node.Text; import org.commonmark.parser.Parser; import org.commonmark.testutil.SpecTestCase; -import org.commonmark.testutil.spec.SpecExample; +import org.commonmark.testutil.example.Example; import org.junit.Test; import static org.junit.Assert.fail; @@ -17,7 +17,7 @@ public class SpecCoreTest extends SpecTestCase { // The spec says URL-escaping is optional, but the examples assume that it's enabled. private static final HtmlRenderer RENDERER = HtmlRenderer.builder().percentEncodeUrls(true).build(); - public SpecCoreTest(SpecExample example) { + public SpecCoreTest(Example example) { super(example); } diff --git a/commonmark/src/test/java/org/commonmark/test/SpecialInputTest.java b/commonmark/src/test/java/org/commonmark/test/SpecialInputTest.java index 930ecb023..1550d3197 100644 --- a/commonmark/src/test/java/org/commonmark/test/SpecialInputTest.java +++ b/commonmark/src/test/java/org/commonmark/test/SpecialInputTest.java @@ -110,9 +110,10 @@ public void linkLabelLength() { @Test public void linkDestinationEscaping() { + // Backslash escapes `)` assertRendering("[foo](\\))", "

foo

\n"); - assertRendering("[foo](\\ )", "

foo

\n"); - + // ` ` is not escapable, so the backslash is a literal backslash and there's an optional space at the end + assertRendering("[foo](\\ )", "

foo

\n"); // Backslash escapes `>`, so it's not a `(<...>)` link, but a `(...)` link instead assertRendering("[foo](<\\>)", "

foo

\n"); // Backslash is a literal, so valid diff --git a/etc/update-spec.sh b/etc/update-spec.sh index 8c9021a86..e5276f4b9 100755 --- a/etc/update-spec.sh +++ b/etc/update-spec.sh @@ -6,4 +6,8 @@ if [ "$#" -ne 1 ]; then fi version=$1 -curl -L "https://raw.githubusercontent.com/jgm/CommonMark/$version/spec.txt" -o commonmark-test-util/src/main/resources/spec.txt +curl -L "https://raw.githubusercontent.com/commonmark/CommonMark/$version/spec.txt" -o commonmark-test-util/src/main/resources/spec.txt + +echo "Check cmark and commonmark.js regression.txt:" +echo "https://github.com/commonmark/cmark/blob/master/test/regression.txt" +echo "https://github.com/commonmark/commonmark.js/blob/master/test/regression.txt"