diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 95bdda997..6326e147a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - java: [11, 17, 21, 25] + java: [17, 21, 25] steps: - name: Checkout sources uses: actions/checkout@v7 @@ -33,7 +33,7 @@ jobs: - name: Set up JDK uses: actions/setup-java@v5 with: - java-version: 11 + java-version: 17 distribution: 'zulu' - name: Build with coverage @@ -54,7 +54,7 @@ jobs: - name: Set up JDK uses: actions/setup-java@v5 with: - java-version: 11 + java-version: 17 distribution: 'zulu' - name: Android Lint checks diff --git a/commonmark-ext-autolink/src/test/java/org/commonmark/ext/autolink/AutolinkTest.java b/commonmark-ext-autolink/src/test/java/org/commonmark/ext/autolink/AutolinkTest.java index fb79dfd60..34e50ac3e 100644 --- a/commonmark-ext-autolink/src/test/java/org/commonmark/ext/autolink/AutolinkTest.java +++ b/commonmark-ext-autolink/src/test/java/org/commonmark/ext/autolink/AutolinkTest.java @@ -91,12 +91,14 @@ public void sourceSpans() { .extensions(EXTENSIONS) .includeSourceSpans(IncludeSourceSpans.BLOCKS_AND_INLINES) .build(); - Node document = - parser.parse( - "abc\n" - + "http://example.com/one\n" - + "def http://example.com/two\n" - + "ghi http://example.com/three jkl"); + var s = + """ + abc + http://example.com/one + def http://example.com/two + ghi http://example.com/three jkl + """; + Node document = parser.parse(s); Paragraph paragraph = (Paragraph) document.getFirstChild(); Text abc = (Text) paragraph.getFirstChild(); diff --git a/commonmark-ext-footnotes/src/test/java/org/commonmark/ext/footnotes/FootnoteHtmlRendererTest.java b/commonmark-ext-footnotes/src/test/java/org/commonmark/ext/footnotes/FootnoteHtmlRendererTest.java index 1a89693b4..9102083e3 100644 --- a/commonmark-ext-footnotes/src/test/java/org/commonmark/ext/footnotes/FootnoteHtmlRendererTest.java +++ b/commonmark-ext-footnotes/src/test/java/org/commonmark/ext/footnotes/FootnoteHtmlRendererTest.java @@ -21,15 +21,21 @@ public class FootnoteHtmlRendererTest extends RenderingTestCase { @Test public void testOne() { assertRendering( - "Test [^foo]\n\n[^foo]: note\n", - "

Test 1

\n" - + "
\n" - + "
    \n" - + "
  1. \n" - + "

    note

    \n" - + "
  2. \n" - + "
\n" - + "
\n"); + """ + Test [^foo] + + [^foo]: note + """, + """ +

Test 1

+
+
    +
  1. +

    note

    +
  2. +
+
+ """); } @Test @@ -37,15 +43,21 @@ public void testLabelNormalization() { // Labels match via their normalized form. For the href and IDs to match, rendering needs to // use the label from the definition consistently. assertRendering( - "Test [^bar]\n\n[^BAR]: note\n", - "

Test 1

\n" - + "
\n" - + "
    \n" - + "
  1. \n" - + "

    note

    \n" - + "
  2. \n" - + "
\n" - + "
\n"); + """ + Test [^bar] + + [^BAR]: note + """, + """ +

Test 1

+
+
    +
  1. +

    note

    +
  2. +
+
+ """); } @Test @@ -55,53 +67,80 @@ public void testMultipleReferences() { // - The same number is used when a definition is referenced multiple times // - Multiple backrefs are rendered assertRendering( - "First [^foo]\n\nThen [^bar]\n\nThen [^foo] again\n\n[^bar]: b\n[^foo]: f\n", - "

First 1

\n" - + "

Then 2

\n" - + "

Then 1 again

\n" - + "
\n" - + "
    \n" - + "
  1. \n" - + "

    f 2

    \n" - + "
  2. \n" - + "
  3. \n" - + "

    b

    \n" - + "
  4. \n" - + "
\n" - + "
\n"); + """ + First [^foo] + + Then [^bar] + + Then [^foo] again + + [^bar]: b + [^foo]: f + """, + """ +

First 1

+

Then 2

+

Then 1 again

+
+
    +
  1. +

    f 2

    +
  2. +
  3. +

    b

    +
  4. +
+
+ """); } @Test public void testDefinitionWithTwoParagraphs() { // With two paragraphs, the backref should be added to the second one assertRendering( - "Test [^foo]\n\n[^foo]: one\n \n two\n", - "

Test 1

\n" - + "
\n" - + "
    \n" - + "
  1. \n" - + "

    one

    \n" - + "

    two

    \n" - + "
  2. \n" - + "
\n" - + "
\n"); + """ + Test [^foo] + + [^foo]: one + \s + two + """, + """ +

Test 1

+
+
    +
  1. +

    one

    +

    two

    +
  2. +
+
+ """); } @Test public void testDefinitionWithList() { assertRendering( - "Test [^foo]\n\n[^foo]:\n - one\n - two\n", - "

Test 1

\n" - + "
\n" - + "
    \n" - + "
  1. \n" - + "
      \n" - + "
    • one
    • \n" - + "
    • two
    • \n" - + "
    \n" - + "
  2. \n" - + "
\n" - + "
\n"); + """ + Test [^foo] + + [^foo]: + - one + - two + """, + """ +

Test 1

+
+
    +
  1. +
      +
    • one
    • +
    • two
    • +
    +
  2. +
+
+ """); } // See docs on FootnoteHtmlNodeRenderer about nested footnotes. @@ -109,18 +148,25 @@ public void testDefinitionWithList() { @Test public void testNestedFootnotesSimple() { assertRendering( - "[^foo1]\n" + "\n" + "[^foo1]: one [^foo2]\n" + "[^foo2]: two\n", - "

1

\n" - + "
\n" - + "
    \n" - + "
  1. \n" - + "

    one 2

    \n" - + "
  2. \n" - + "
  3. \n" - + "

    two

    \n" - + "
  4. \n" - + "
\n" - + "
\n"); + """ + [^foo1] + + [^foo1]: one [^foo2] + [^foo2]: two + """, + """ +

1

+
+
    +
  1. +

    one 2

    +
  2. +
  3. +

    two

    +
  4. +
+
+ """); } @Test @@ -129,149 +175,196 @@ public void testNestedFootnotesOrder() { // The reason is that the number is done based on all references in document order, // including references in definitions. So [^bar] from the first line is first. assertRendering( - "[^foo]: foo [^bar]\n" + "\n" + "[^foo]\n" + "\n" + "[^bar]: bar\n", - "

1

\n" - + "
\n" - + "
    \n" - + "
  1. \n" - + "

    foo 2

    \n" - + "
  2. \n" - + "
  3. \n" - + "

    bar

    \n" - + "
  4. \n" - + "
\n" - + "
\n"); + """ + [^foo]: foo [^bar] + + [^foo] + + [^bar]: bar + """, + """ +

1

+
+
    +
  1. +

    foo 2

    +
  2. +
  3. +

    bar

    +
  4. +
+
+ """); } @Test public void testNestedFootnotesOrder2() { assertRendering( - "[^1]\n" - + "\n" - + "[^4]: four\n" - + "[^3]: three [^4]\n" - + "[^2]: two [^4]\n" - + "[^1]: one [^2][^3]\n", - "

1

\n" - + "
\n" - + "
    \n" - + "
  1. \n" - + "

    one 23

    \n" - + "
  2. \n" - + "
  3. \n" - + "

    two 4

    \n" - + "
  4. \n" - + "
  5. \n" - + "

    three 4

    \n" - + "
  6. \n" - + "
  7. \n" - + "

    four 2

    \n" - + "
  8. \n" - + "
\n" - + "
\n"); + """ + [^1] + + [^4]: four + [^3]: three [^4] + [^2]: two [^4] + [^1]: one [^2][^3] + """, + """ +

1

+
+
    +
  1. +

    one 23

    +
  2. +
  3. +

    two 4

    +
  4. +
  5. +

    three 4

    +
  6. +
  7. +

    four 2

    +
  8. +
+
+ """); } @Test public void testNestedFootnotesCycle() { // Footnotes can contain cycles, lol. assertRendering( - "[^foo1]\n" + "\n" + "[^foo1]: one [^foo2]\n" + "[^foo2]: two [^foo1]\n", - "

1

\n" - + "
\n" - + "
    \n" - + "
  1. \n" - + "

    one 2 2

    \n" - + "
  2. \n" - + "
  3. \n" - + "

    two 1

    \n" - + "
  4. \n" - + "
\n" - + "
\n"); + """ + [^foo1] + + [^foo1]: one [^foo2] + [^foo2]: two [^foo1] + """, + """ +

1

+
+
    +
  1. +

    one 2 2

    +
  2. +
  3. +

    two 1

    +
  4. +
+
+ """); } @Test public void testNestedFootnotesUnreferenced() { // This should not result in any footnotes, as baz itself isn't referenced. // But GitHub renders bar only, with a broken backref, because bar is referenced from foo. - assertRendering("[^foo]: foo[^bar]\n" + "[^bar]: bar\n", ""); + assertRendering( + """ + [^foo]: foo[^bar] + [^bar]: bar + """, + ""); // And here only 1 is rendered. assertRendering( - "[^1]\n" + "\n" + "[^1]: one\n" + "[^foo]: foo[^bar]\n" + "[^bar]: bar\n", - "

1

\n" - + "
\n" - + "
    \n" - + "
  1. \n" - + "

    one

    \n" - + "
  2. \n" - + "
\n" - + "
\n"); + """ + [^1] + + [^1]: one + [^foo]: foo[^bar] + [^bar]: bar + """, + """ +

1

+
+
    +
  1. +

    one

    +
  2. +
+
+ """); } @Test public void testInlineFootnotes() { assertRenderingInline( "Test ^[inline *footnote*]", - "

Test 1

\n" - + "
\n" - + "
    \n" - + "
  1. \n" - + "

    inline footnote

    \n" - + "
  2. \n" - + "
\n" - + "
\n"); + """ +

Test 1

+
+
    +
  1. +

    inline footnote

    +
  2. +
+
+ """); } @Test public void testInlineFootnotesNested() { assertRenderingInline( "Test ^[inline ^[nested]]", - "

Test 1

\n" - + "
\n" - + "
    \n" - + "
  1. \n" - + "

    inline 2

    \n" - + "
  2. \n" - + "
  3. \n" - + "

    nested

    \n" - + "
  4. \n" - + "
\n" - + "
\n"); + """ +

Test 1

+
+
    +
  1. +

    inline 2

    +
  2. +
  3. +

    nested

    +
  4. +
+
+ """); } @Test public void testInlineFootnoteWithReference() { // This is a bit tricky because the IDs need to be unique. assertRenderingInline( - "Test ^[inline [^1]]\n" + "\n" + "[^1]: normal", - "

Test 1

\n" - + "
\n" - + "
    \n" - + "
  1. \n" - + "

    inline 2

    \n" - + "
  2. \n" - + "
  3. \n" - + "

    normal

    \n" - + "
  4. \n" - + "
\n" - + "
\n"); + """ + Test ^[inline [^1]] + + [^1]: normal""", + """ +

Test 1

+
+
    +
  1. +

    inline 2

    +
  2. +
  3. +

    normal

    +
  4. +
+
+ """); } @Test public void testInlineFootnoteInsideDefinition() { assertRenderingInline( - "Test [^1]\n" + "\n" + "[^1]: Definition ^[inline]\n", - "

Test 1

\n" - + "
\n" - + "
    \n" - + "
  1. \n" - + "

    Definition 2

    \n" - + "
  2. \n" - + "
  3. \n" - + "

    inline

    \n" - + "
  4. \n" - + "
\n" - + "
\n"); + """ + Test [^1] + + [^1]: Definition ^[inline] + """, + """ +

Test 1

+
+
    +
  1. +

    Definition 2

    +
  2. +
  3. +

    inline

    +
  4. +
+
+ """); } @Test @@ -279,24 +372,30 @@ public void testInlineFootnoteInsideDefinition2() { // Tricky because of the nested inline footnote which we want to visit after foo // (breadth-first). assertRenderingInline( - "Test [^1]\n" + "\n" + "[^1]: Definition ^[inline ^[nested]] ^[foo]\n", - "

Test 1

\n" - + "
\n" - + "
    \n" - + "
  1. \n" - + "

    Definition 2 3

    \n" - + "
  2. \n" - + "
  3. \n" - + "

    inline 4

    \n" - + "
  4. \n" - + "
  5. \n" - + "

    foo

    \n" - + "
  6. \n" - + "
  7. \n" - + "

    nested

    \n" - + "
  8. \n" - + "
\n" - + "
\n"); + """ + Test [^1] + + [^1]: Definition ^[inline ^[nested]] ^[foo] + """, + """ +

Test 1

+
+
    +
  1. +

    Definition 2 3

    +
  2. +
  3. +

    inline 4

    +
  4. +
  5. +

    foo

    +
  6. +
  7. +

    nested

    +
  8. +
+
+ """); } @Test @@ -314,14 +413,16 @@ public void testRenderNodesDirectly() { doc.appendChild(def); var expected = - "

Test 1

\n" - + "
\n" - + "
    \n" - + "
  1. \n" - + "

    note!

    \n" - + "
  2. \n" - + "
\n" - + "
\n"; + """ +

Test 1

+
+
    +
  1. +

    note!

    +
  2. +
+
+ """; Asserts.assertRendering("", expected, RENDERER.render(doc)); } diff --git a/commonmark-ext-gfm-alerts/src/test/java/org/commonmark/ext/gfm/alerts/AlertsTest.java b/commonmark-ext-gfm-alerts/src/test/java/org/commonmark/ext/gfm/alerts/AlertsTest.java index 99c0e8d7a..bee8f7be2 100644 --- a/commonmark-ext-gfm-alerts/src/test/java/org/commonmark/ext/gfm/alerts/AlertsTest.java +++ b/commonmark-ext-gfm-alerts/src/test/java/org/commonmark/ext/gfm/alerts/AlertsTest.java @@ -59,10 +59,12 @@ public void customType() { assertThat(renderer.render(parser.parse("> [!INFO]\n> Custom alert"))) .isEqualTo( - "
\n" - + "

Information

\n" - + "

Custom alert

\n" - + "
\n"); + """ +
+

Information

+

Custom alert

+
+ """); } @Test @@ -77,23 +79,33 @@ public void multipleCustomTypes() { var parser = Parser.builder().extensions(Set.of(extension)).build(); var renderer = HtmlRenderer.builder().extensions(Set.of(extension)).build(); - assertThat( - renderer.render( - parser.parse( - "> [!INFO]\n> Info content\n\n> [!SUCCESS]\n> Success content\n\n> [!DANGER]\n> Danger content"))) + var s = + """ + > [!INFO] + > Info content + + > [!SUCCESS] + > Success content + + > [!DANGER] + > Danger content + """; + assertThat(renderer.render(parser.parse(s))) .isEqualTo( - "
\n" - + "

Information

\n" - + "

Info content

\n" - + "
\n" - + "
\n" - + "

Success!

\n" - + "

Success content

\n" - + "
\n" - + "
\n" - + "

Danger!

\n" - + "

Danger content

\n" - + "
\n"); + """ +
+

Information

+

Info content

+
+
+

Success!

+

Success content

+
+
+

Danger!

+

Danger content

+
+ """); } @Test @@ -103,12 +115,19 @@ public void standardTypesWithCustomConfigured() { var parser = Parser.builder().extensions(Set.of(extension)).build(); var renderer = HtmlRenderer.builder().extensions(Set.of(extension)).build(); - assertThat(renderer.render(parser.parse("> [!NOTE]\n> Standard type"))) + var s = + """ + > [!NOTE] + > Standard type + """; + assertThat(renderer.render(parser.parse(s))) .isEqualTo( - "
\n" - + "

Note

\n" - + "

Standard type

\n" - + "
\n"); + """ +
+

Note

+

Standard type

+
+ """); } @Test @@ -118,12 +137,19 @@ public void overrideStandardTypeTitle() { var parser = Parser.builder().extensions(Set.of(extension)).build(); var renderer = HtmlRenderer.builder().extensions(Set.of(extension)).build(); - assertThat(renderer.render(parser.parse("> [!NOTE]\n> Localized title"))) + var s = + """ + > [!NOTE] + > Localized title + """; + assertThat(renderer.render(parser.parse(s))) .isEqualTo( - "
\n" - + "

Nota

\n" - + "

Localized title

\n" - + "
\n"); + """ +
+

Nota

+

Localized title

+
+ """); } // Custom type validation @@ -162,33 +188,61 @@ public void overwriteStandardTypes() { var parser = Parser.builder().extensions(Set.of(extension)).build(); var renderer = HtmlRenderer.builder().extensions(Set.of(extension)).build(); - assertThat(renderer.render(parser.parse("> [!NOTE]\n> Regular block quote"))) + var s = + """ + > [!NOTE] + > Regular block quote + """; + assertThat(renderer.render(parser.parse(s))) .isEqualTo( - "
\n" - + "

[!NOTE]\n" - + "Regular block quote

\n" - + "
\n"); - - assertThat(renderer.render(parser.parse("> [!TIP]\n> Regular block quote"))) + """ +
+

[!NOTE] + Regular block quote

+
+ """); + + s = + """ + > [!TIP] + > Regular block quote + """; + assertThat(renderer.render(parser.parse(s))) .isEqualTo( - "
\n" - + "

[!TIP]\n" - + "Regular block quote

\n" - + "
\n"); - - assertThat(renderer.render(parser.parse("> [!IMPORTANT]\n> Alert"))) + """ +
+

[!TIP] + Regular block quote

+
+ """); + + s = + """ + > [!IMPORTANT] + > Alert + """; + assertThat(renderer.render(parser.parse(s))) .isEqualTo( - "
\n" - + "

Important

\n" - + "

Alert

\n" - + "
\n"); - - assertThat(renderer.render(parser.parse("> [!BUG]\n> Alert"))) + """ +
+

Important

+

Alert

+
+ """); + + s = + """ + > [!BUG] + > Alert + """; + assertThat(renderer.render(parser.parse(s))) .isEqualTo( - "
\n" - + "

Known Bug

\n" - + "

Alert

\n" - + "
\n"); + """ +
+

Known Bug

+

Alert

+
+ """); } // Overwriting types validation @@ -222,130 +276,198 @@ public void overwriteTypesTitleMustNotBeEmpty() { @Test public void customTitle() { assertRenderingCustomTitles( - "> [!NOTE] Custom title\n> Note with a custom title", - "
\n" - + "

Custom title

\n" - + "

Note with a custom title

\n" - + "
\n"); + """ + > [!NOTE] Custom title + > Note with a custom title + """, + """ +
+

Custom title

+

Note with a custom title

+
+ """); } @Test public void customTitleNoSpace() { assertRenderingCustomTitles( - "> [!NOTE]Custom title\n> Note with a custom title", - "
\n" - + "

Custom title

\n" - + "

Note with a custom title

\n" - + "
\n"); + """ + > [!NOTE]Custom title + > Note with a custom title + """, + """ +
+

Custom title

+

Note with a custom title

+
+ """); } @Test public void customTitleExtraSpace() { assertRenderingCustomTitles( - "> [!NOTE] Custom title \n> Note with a custom title", - "
\n" - + "

Custom title

\n" - + "

Note with a custom title

\n" - + "
\n"); + """ + > [!NOTE] Custom title \s + > Note with a custom title + """, + """ +
+

Custom title

+

Note with a custom title

+
+ """); } @Test public void customTitleNoHardLineBreak() { assertRenderingCustomTitles( - "> [!NOTE] Custom title\\\n> Note with a custom title", - "
\n" - + "

Custom title\\

\n" - + "

Note with a custom title

\n" - + "
\n"); + """ + > [!NOTE] Custom title\\ + > Note with a custom title + """, + """ +
+

Custom title\\

+

Note with a custom title

+
+ """); } @Test public void customTitleWithComment() { assertRenderingCustomTitles( - "> [!NOTE] Custom title \n> Note with a custom title", - "
\n" - + "

Custom title

\n" - + "

Note with a custom title

\n" - + "
\n"); + """ + > [!NOTE] Custom title \s + > Note with a custom title + """, + """ +
+

Custom title

+

Note with a custom title

+
+ """); } @Test public void customTitleWithInlineFormatting() { assertRenderingCustomTitles( - "> [!NOTE] Custom _title with **formatting**_\n> Note with a custom title", - "
\n" - + "

Custom title with formatting

\n" - + "

Note with a custom title

\n" - + "
\n"); + """ + > [!NOTE] Custom _title with **formatting**_ + > Note with a custom title + """, + """ +
+

Custom title with formatting

+

Note with a custom title

+
+ """); } @Test public void customTitleWithLinkAndCode() { assertRenderingCustomTitles( - "> [!IMPORTANT] See [docs](https://example.com) or `run()`\n> Note with a custom title", - "
\n" - + "

See docs or run()

\n" - + "

Note with a custom title

\n" - + "
\n"); + """ + > [!IMPORTANT] See [docs](https://example.com) or `run()` + > Note with a custom title + """, + """ +
+

See docs or run()

+

Note with a custom title

+
+ """); } @Test public void customTitleLeadingEmptyLines() { assertRenderingCustomTitles( - ">\n> \n> [!NOTE] Custom **title**\n> Note with a custom title", - "
\n" - + "

Custom title

\n" - + "

Note with a custom title

\n" - + "
\n"); + """ + > + > \s + > [!NOTE] Custom **title** + > Note with a custom title + """, + """ +
+

Custom title

+

Note with a custom title

+
+ """); } @Test public void customTitleNoOverlappingInlines() { assertRenderingCustomTitles( - "> [!NOTE] Custom _title with **opening `delimiters\n> Note` with** closing delimiters_", - "
\n" - + "

Custom _title with **opening `delimiters

\n" - + "

Note` with** closing delimiters_

\n" - + "
\n"); + """ + > [!NOTE] Custom _title with **opening `delimiters + > Note` with** closing delimiters_ + """, + """ +
+

Custom _title with **opening `delimiters

+

Note` with** closing delimiters_

+
+ """); } @Test public void customTitleIgnoresBlockContent() { assertRenderingCustomTitles( - "> [!NOTE] ## Custom title looks like an ATX heading\n>But it's not", - "
\n" - + "

## Custom title looks like an ATX heading

\n" - + "

But it's not

\n" - + "
\n"); + """ + > [!NOTE] ## Custom title looks like an ATX heading + >But it's not + """, + """ +
+

## Custom title looks like an ATX heading

+

But it's not

+
+ """); } @Test public void customTitleNoBody() { // Alerts with no body are allowed. assertRenderingCustomTitles( - "> [!NOTE] Custom _title_\n> \n>\n>", - "
\n" - + "

Custom title

\n" - + "
\n"); + """ + > [!NOTE] Custom _title_ + > \s + > + > + """, + """ +
+

Custom title

+
+ """); } @Test public void customTitleNoBodyNoSpace() { assertRenderingCustomTitles( - "> [!NOTE] Custom _title_", - "
\n" - + "

Custom title

\n" - + "
\n"); + """ + > [!NOTE] Custom _title_ + """, + """ +
+

Custom title

+
+ """); } @Test public void onlyTrailingWhitespaceIsNotCustomTitle() { assertRenderingCustomTitles( - "> [!NOTE] \n> Body text", - "
\n" - + "

Note

\n" - + "

Body text

\n" - + "
\n"); + """ + > [!NOTE] \s + > Body text + """, + """ +
+

Note

+

Body text

+
+ """); } // Lazy continuation @@ -353,21 +475,31 @@ public void onlyTrailingWhitespaceIsNotCustomTitle() { @Test public void noLazyContinuationAfterMarker() { assertRendering( - "> [!NOTE]\nBody text", - "
\n" - + "

Note

\n" - + "
\n" - + "

Body text

\n"); + """ + > [!NOTE] + Body text + """, + """ +
+

Note

+
+

Body text

+ """); } @Test public void noLazyContinuationAfterTitle() { assertRenderingCustomTitles( - "> [!NOTE] Custom title\nBody text", - "
\n" - + "

Custom title

\n" - + "
\n" - + "

Body text

\n"); + """ + > [!NOTE] Custom title + Body text + """, + """ +
+

Custom title

+
+

Body text

+ """); } // Alert markers take precedence over link reference definitions @@ -375,32 +507,53 @@ public void noLazyContinuationAfterTitle() { @Test public void alertTakesPrecedence() { assertRenderingCustomTitles( - "> [!NOTE]: https://example.com\n> Body text\n\n[!NOTE]", - "
\n" - + "

: https://example.com

\n" - + "

Body text

\n" - + "
\n" - + "

[!NOTE]

\n"); + """ + > [!NOTE]: https://example.com + > Body text + + [!NOTE] + """, + """ +
+

: https://example.com

+

Body text

+
+

[!NOTE]

+ """); } @Test public void alertTakesPrecedenceBefore() { assertRenderingCustomTitles( - "> [!NOTE]\n> Body text\n\n[!NOTE]: https://example.com", - "
\n" - + "

Note

\n" - + "

Body text

\n" - + "
\n"); + """ + > [!NOTE] + > Body text + + [!NOTE]: https://example.com + """, + """ +
+

Note

+

Body text

+
+ """); } @Test public void alertTakesPrecedenceAfter() { assertRenderingCustomTitles( - "[!NOTE]: https://example.com\n\n> [!NOTE]\n> Body text", - "
\n" - + "

Note

\n" - + "

Body text

\n" - + "
\n"); + """ + [!NOTE]: https://example.com + + > [!NOTE] + > Body text + """, + """ +
+

Note

+

Body text

+
+ """); } // Nested alerts @@ -408,37 +561,55 @@ public void alertTakesPrecedenceAfter() { @Test public void noNestedAlertsByDefault() { assertRendering( - "> [!TIP]\n> Body\n\n- > [!TIP]\n > Nested body", - "
\n" - + "

Tip

\n" - + "

Body

\n" - + "
\n" - + "\n"); + """ + > [!TIP] + > Body + + - > [!TIP] + > Nested body + """, + """ +
+

Tip

+

Body

+
+ + """); } @Test public void noNestedAlertsByDefaultLeadingEmptyLines() { assertRendering( - ">\n> \n> [!TIP]\n> Body\n\n- > [!TIP]\n > Nested body", - "
\n" - + "

Tip

\n" - + "

Body

\n" - + "
\n" - + "\n"); + """ + > + > \s + > [!TIP] + > Body + + - > [!TIP] + > Nested body + """, + """ +
+

Tip

+

Body

+
+ + """); } @Test @@ -448,50 +619,49 @@ public void nestedAlerts() { var renderer = HtmlRenderer.builder().extensions(Set.of(extension)).build(); var source = - String.join( - "\n", - "> [!TIP]", - "> Tip body", - "> > [!IMPORTANT]", - "> > Important body", - "", - "- > [!NOTE]", - " > Nested body", - " >", - " > 1. Ordered list body", - " >", - " > > [!CAUTION]", - " > >", - " > > Deeply nested body"); + """ + > [!TIP] + > Tip body + > > [!IMPORTANT] + > > Important body + + - > [!NOTE] + > Nested body + > + > 1. Ordered list body + > + > > [!CAUTION] + > > + > > Deeply nested body + """; var expected = - String.join( - "\n", - "
", - "

Tip

", - "

Tip body

", - "
", - "

Important

", - "

Important body

", - "
", - "
", - "\n"); - + """ +
+

Tip

+

Tip body

+
+

Important

+

Important body

+
+
+ + """; assertThat(renderer.render(parser.parse(source))).isEqualTo(expected); } @@ -499,7 +669,12 @@ public void nestedAlerts() { @Test public void alertParsedAsAlertNode() { - var document = PARSER.parse("> [!NOTE]\n> This is a note"); + var document = + PARSER.parse( + """ + > [!NOTE] + > This is a note + """); var firstChild = document.getFirstChild(); assertThat(firstChild).isInstanceOf(Alert.class); var alert = (Alert) firstChild; @@ -522,7 +697,11 @@ public void customTypeParsedAsAlertNode() { @Test public void titleSourcePositionPreserved() { - var source = "> [!NOTE] Custom title\n> Body text"; + var source = + """ + > [!NOTE] Custom title + > Body text + """; var document = PARSER_CUSTOM_TITLES.parse(source); var alert = (Alert) document.getFirstChild(); var title = (AlertTitle) alert.getFirstChild(); @@ -533,7 +712,15 @@ public void titleSourcePositionPreserved() { @Test public void titleSourcePositionPreservedBetweenBlocks() { - var source = "- List\n\n> [!NOTE] Custom title\n> Body text\n\nPlain paragraph"; + var source = + """ + - List + + > [!NOTE] Custom title + > Body text + + Plain paragraph + """; var document = PARSER_CUSTOM_TITLES.parse(source); var alert = (Alert) document.getFirstChild().getNext(); var title = (AlertTitle) alert.getFirstChild(); @@ -544,7 +731,11 @@ public void titleSourcePositionPreservedBetweenBlocks() { @Test public void titleSourcePositionWithLeadingAndTrailingSpaces() { - var source = "> [!NOTE] Custom title \n> Body text"; + var source = + """ + > [!NOTE] Custom title \s + > Body text + """; var document = PARSER_CUSTOM_TITLES.parse(source); var alert = (Alert) document.getFirstChild(); var title = (AlertTitle) alert.getFirstChild(); @@ -555,7 +746,11 @@ public void titleSourcePositionWithLeadingAndTrailingSpaces() { @Test public void titleWithInlineFormattingSourcePosition() { - var source = "> [!NOTE] Custom _title_\n> Body text"; + var source = + """ + > [!NOTE] Custom _title_ + > Body text + """; var document = PARSER_CUSTOM_TITLES.parse(source); var alert = (Alert) document.getFirstChild(); var title = (AlertTitle) alert.getFirstChild(); @@ -583,7 +778,11 @@ public void titleWithInlineFormattingSourcePosition() { @Test public void titleWithNestedInlineFormattingSourcePosition() { - var source = "> [!NOTE] Text with **bold _and italic_**\n> Body text"; + var source = + """ + > [!NOTE] Text with **bold _and italic_** + > Body text + """; var document = PARSER_CUSTOM_TITLES.parse(source); var alert = (Alert) document.getFirstChild(); var title = (AlertTitle) alert.getFirstChild(); diff --git a/commonmark-ext-gfm-alerts/src/test/java/org/commonmark/ext/gfm/alerts/examples/AlertsExample.java b/commonmark-ext-gfm-alerts/src/test/java/org/commonmark/ext/gfm/alerts/examples/AlertsExample.java index 26b348016..15ef46c9c 100644 --- a/commonmark-ext-gfm-alerts/src/test/java/org/commonmark/ext/gfm/alerts/examples/AlertsExample.java +++ b/commonmark-ext-gfm-alerts/src/test/java/org/commonmark/ext/gfm/alerts/examples/AlertsExample.java @@ -25,17 +25,24 @@ private static void standardTypesExample() { var renderer = HtmlRenderer.builder().extensions(List.of(extension)).build(); var markdown = - "# GFM Alerts Demo\n\n" - + "> [!NOTE]\n" - + "> Highlights information that users should take into account.\n\n" - + "> [!TIP]\n" - + "> Helpful advice for doing things better.\n\n" - + "> [!IMPORTANT]\n" - + "> Key information users need to know.\n\n" - + "> [!WARNING]\n" - + "> Urgent info that needs immediate attention.\n\n" - + "> [!CAUTION]\n" - + "> Advises about risks or negative outcomes.\n"; + """ + # GFM Alerts Demo + + > [!NOTE] + > Highlights information that users should take into account. + + > [!TIP] + > Helpful advice for doing things better. + + > [!IMPORTANT] + > Key information users need to know. + + > [!WARNING] + > Urgent info that needs immediate attention. + + > [!CAUTION] + > Advises about risks or negative outcomes. + """; var html = renderer.render(parser.parse(markdown)); @@ -56,13 +63,18 @@ private static void customTypesExample() { var renderer = HtmlRenderer.builder().extensions(List.of(extension)).build(); var markdown = - "# Custom Alert Types\n\n" - + "> [!NOTE]\n" - + "> Useful information that users should know.\n\n" - + "> [!TIP]\n" - + "> Helpful advice for doing things better.\n\n" - + "> [!BUG]\n" - + "> This feature has a known issue with large files (see #42).\n"; + """ + # Custom Alert Types + + > [!NOTE] + > Useful information that users should know. + + > [!TIP] + > Helpful advice for doing things better. + + > [!BUG] + > This feature has a known issue with large files (see #42). + """; var html = renderer.render(parser.parse(markdown)); diff --git a/commonmark-ext-gfm-tables/src/test/java/org/commonmark/ext/gfm/tables/TablesTest.java b/commonmark-ext-gfm-tables/src/test/java/org/commonmark/ext/gfm/tables/TablesTest.java index 5ddee95b6..7621660f9 100644 --- a/commonmark-ext-gfm-tables/src/test/java/org/commonmark/ext/gfm/tables/TablesTest.java +++ b/commonmark-ext-gfm-tables/src/test/java/org/commonmark/ext/gfm/tables/TablesTest.java @@ -30,238 +30,405 @@ public void mustHaveHeaderAndSeparator() { @Test public void separatorMustBeOneOrMore() { assertRendering( - "Abc|Def\n-|-", - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
AbcDef
\n"); - assertRendering( - "Abc|Def\n--|--", - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
AbcDef
\n"); + """ + Abc|Def + -|- + """, + """ + + + + + + + +
AbcDef
+ """); + assertRendering( + """ + Abc|Def + --|-- + """, + """ + + + + + + + +
AbcDef
+ """); } @Test public void separatorMustNotContainInvalidChars() { - assertRendering("Abc|Def\n |-a-|---", "

Abc|Def\n|-a-|---

\n"); - assertRendering("Abc|Def\n |:--a|---", "

Abc|Def\n|:--a|---

\n"); - assertRendering("Abc|Def\n |:--a--:|---", "

Abc|Def\n|:--a--:|---

\n"); + assertRendering( + """ + Abc|Def + |-a-|--- + """, + """ +

Abc|Def + |-a-|---

+ """); + assertRendering( + """ + Abc|Def + |:--a|--- + """, + """ +

Abc|Def + |:--a|---

+ """); + assertRendering( + """ + Abc|Def + |:--a--:|--- + """, + """ +

Abc|Def + |:--a--:|---

+ """); } @Test public void separatorCanHaveLeadingSpaceThenPipe() { assertRendering( - "Abc|Def\n |---|---", - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
AbcDef
\n"); + """ + Abc|Def + |---|--- + """, + """ + + + + + + + +
AbcDef
+ """); } @Test public void separatorCanNotHaveAdjacentPipes() { - assertRendering("Abc|Def\n---||---", "

Abc|Def\n---||---

\n"); + assertRendering( + """ + Abc|Def + ---||--- + """, + """ +

Abc|Def + ---||---

+ """); } @Test public void separatorNeedsPipes() { - assertRendering("Abc|Def\n|--- ---", "

Abc|Def\n|--- ---

\n"); + assertRendering( + """ + Abc|Def + |--- --- + """, + """ +

Abc|Def + |--- ---

+ """); } @Test public void oneHeadNoBody() { assertRendering( - "Abc|Def\n---|---", - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
AbcDef
\n"); + """ + Abc|Def + ---|--- + """, + """ + + + + + + + +
AbcDef
+ """); } @Test public void oneColumnOneHeadNoBody() { String expected = - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
Abc
\n"; - assertRendering("|Abc\n|---\n", expected); - assertRendering("|Abc|\n|---|\n", expected); - assertRendering("Abc|\n---|\n", expected); + """ + + + + + + +
Abc
+ """; + assertRendering( + """ + |Abc + |--- + """, + expected); + assertRendering( + """ + |Abc| + |---| + """, + expected); + assertRendering( + """ + Abc| + ---| + """, + expected); // Pipe required on separator - assertRendering("|Abc\n---\n", "

|Abc

\n"); + assertRendering( + """ + |Abc + --- + """, + """ +

|Abc

+ """); // Pipe required on head - assertRendering("Abc\n|---\n", "

Abc\n|---

\n"); + assertRendering( + """ + Abc + |--- + """, + """ +

Abc + |---

+ """); } @Test public void oneColumnOneHeadOneBody() { String expected = - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
Abc
1
\n"; - assertRendering("|Abc\n|---\n|1", expected); - assertRendering("|Abc|\n|---|\n|1|", expected); - assertRendering("Abc|\n---|\n1|", expected); + """ + + + + + + + + + + + +
Abc
1
+ """; + assertRendering( + """ + |Abc + |--- + |1 + """, + expected); + assertRendering( + """ + |Abc| + |---| + |1| + """, + expected); + assertRendering( + """ + Abc| + ---| + 1| + """, + expected); // Pipe required on separator - assertRendering("|Abc\n---\n|1", "

|Abc

\n

|1

\n"); + assertRendering( + """ + |Abc + --- + |1 + """, + """ +

|Abc

+

|1

+ """); } @Test public void oneHeadOneBody() { assertRendering( - "Abc|Def\n---|---\n1|2", - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
AbcDef
12
\n"); + """ + Abc|Def + ---|--- + 1|2 + """, + """ + + + + + + + + + + + + + +
AbcDef
12
+ """); } @Test public void spaceBeforeSeparator() { assertRendering( - " |Abc|Def|\n |---|---|\n |1|2|", - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
AbcDef
12
\n"); + """ + |Abc|Def| + |---|---| + |1|2| + """, + """ + + + + + + + + + + + + + +
AbcDef
12
+ """); } @Test public void separatorMustNotHaveLessPartsThanHead() { - assertRendering("Abc|Def|Ghi\n---|---\n1|2|3", "

Abc|Def|Ghi\n---|---\n1|2|3

\n"); + assertRendering( + """ + Abc|Def|Ghi + ---|--- + 1|2|3 + """, + """ +

Abc|Def|Ghi + ---|--- + 1|2|3

+ """); } @Test public void padding() { assertRendering( - " Abc | Def \n --- | --- \n 1 | 2 ", - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
AbcDef
12
\n"); + """ + Abc | Def\s + --- | ---\s + 1 | 2\s + """, + """ + + + + + + + + + + + + + +
AbcDef
12
+ """); } @Test public void paddingWithCodeBlockIndentation() { assertRendering( - "Abc|Def\n---|---\n 1|2", - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
AbcDef
12
\n"); + """ + Abc|Def + ---|--- + 1|2 + """, + """ + + + + + + + + + + + + + +
AbcDef
12
+ """); } @Test public void pipesOnOutside() { assertRendering( - "|Abc|Def|\n|---|---|\n|1|2|", - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
AbcDef
12
\n"); + """ + |Abc|Def| + |---|---| + |1|2| + """, + """ + + + + + + + + + + + + + +
AbcDef
12
+ """); } @Test public void pipesOnOutsideWhitespaceAfterHeader() { assertRendering( - "|Abc|Def| \n|---|---|\n|1|2|", - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
AbcDef
12
\n"); + """ + |Abc|Def|\s + |---|---| + |1|2| + """, + """ + + + + + + + + + + + + + +
AbcDef
12
+ """); } @Test @@ -269,63 +436,81 @@ public void pipesOnOutsideZeroLengthHeaders() { // This is literally what someone has done IRL - it helped to expose // an issue with parsing the last header cell correctly assertRendering( - "||center header||\n" + "-|-------------|-\n" + "1| 2 |3", - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
center header
123
\n"); + """ + ||center header|| + -|-------------|- + 1| 2 |3 + """, + """ + + + + + + + + + + + + + + + +
center header
123
+ """); } @Test public void inlineElements() { assertRendering( - "*Abc*|Def\n---|---\n1|2", - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
AbcDef
12
\n"); + """ + *Abc*|Def + ---|--- + 1|2 + """, + """ + + + + + + + + + + + + + +
AbcDef
12
+ """); } @Test public void escapedPipe() { assertRendering( - "Abc|Def\n---|---\n1\\|2|20", - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
AbcDef
1|220
\n"); + """ + Abc|Def + ---|--- + 1\\|2|20 + """, + """ + + + + + + + + + + + + + +
AbcDef
1|220
+ """); } @Test @@ -334,21 +519,27 @@ public void escapedBackslash() { // followed by a pipe (so two cells). Instead, the `\|` is parsed as an escaped pipe first, // so just a single cell. The inline parser then gets `1\|2` which renders as `1|2`. assertRendering( - "Abc|Def\n---|---\n1\\\\|2", - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
AbcDef
1|2
\n"); + """ + Abc|Def + ---|--- + 1\\\\|2 + """, + """ + + + + + + + + + + + + + +
AbcDef
1|2
+ """); } @Test @@ -357,421 +548,580 @@ public void escapedOther() { // table, otherwise inline parsing is wrong. So we have to be careful where we do/don't // consume the backslash. assertRendering( - "Abc|Def\n---|---\n1|\\`not code`", - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
AbcDef
1`not code`
\n"); + """ + Abc|Def + ---|--- + 1|\\`not code` + """, + """ + + + + + + + + + + + + + +
AbcDef
1`not code`
+ """); } @Test public void backslashAtEnd() { assertRendering( - "Abc|Def\n---|---\n1|2\\", - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
AbcDef
12\\
\n"); + """ + Abc|Def + ---|--- + 1|2\\ + """, + """ + + + + + + + + + + + + + +
AbcDef
12\\
+ """); } @Test public void alignLeft() { assertRendering( - "Abc|Def\n:-|-\n1|2", - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
AbcDef
12
\n"); - assertRendering( - "Abc|Def\n:-|-\n1|2", - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
AbcDef
12
\n"); - assertRendering( - "Abc|Def\n:---|---\n1|2", - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
AbcDef
12
\n"); + """ + Abc|Def + :-|- + 1|2 + """, + """ + + + + + + + + + + + + + +
AbcDef
12
+ """); + assertRendering( + """ + Abc|Def + :-|- + 1|2 + """, + """ + + + + + + + + + + + + + +
AbcDef
12
+ """); + assertRendering( + """ + Abc|Def + :---|--- + 1|2 + """, + """ + + + + + + + + + + + + + +
AbcDef
12
+ """); } @Test public void alignRight() { assertRendering( - "Abc|Def\n-:|-\n1|2", - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
AbcDef
12
\n"); - assertRendering( - "Abc|Def\n--:|--\n1|2", - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
AbcDef
12
\n"); - assertRendering( - "Abc|Def\n---:|---\n1|2", - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
AbcDef
12
\n"); + """ + Abc|Def + -:|- + 1|2 + """, + """ + + + + + + + + + + + + + +
AbcDef
12
+ """); + assertRendering( + """ + Abc|Def + --:|-- + 1|2 + """, + """ + + + + + + + + + + + + + +
AbcDef
12
+ """); + assertRendering( + """ + Abc|Def + ---:|--- + 1|2 + """, + """ + + + + + + + + + + + + + +
AbcDef
12
+ """); } @Test public void alignCenter() { assertRendering( - "Abc|Def\n:-:|-\n1|2", - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
AbcDef
12
\n"); - assertRendering( - "Abc|Def\n:--:|--\n1|2", - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
AbcDef
12
\n"); - assertRendering( - "Abc|Def\n:---:|---\n1|2", - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
AbcDef
12
\n"); + """ + Abc|Def + :-:|- + 1|2 + """, + """ + + + + + + + + + + + + + +
AbcDef
12
+ """); + assertRendering( + """ + Abc|Def + :--:|-- + 1|2 + """, + """ + + + + + + + + + + + + + +
AbcDef
12
+ """); + assertRendering( + """ + Abc|Def + :---:|--- + 1|2 + """, + """ + + + + + + + + + + + + + +
AbcDef
12
+ """); } @Test public void alignCenterSecond() { assertRendering( - "Abc|Def\n---|:---:\n1|2", - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
AbcDef
12
\n"); + """ + Abc|Def + ---|:---: + 1|2 + """, + """ + + + + + + + + + + + + + +
AbcDef
12
+ """); } @Test public void alignLeftWithSpaces() { assertRendering( - "Abc|Def\n :--- |---\n1|2", - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
AbcDef
12
\n"); + """ + Abc|Def + :--- |--- + 1|2 + """, + """ + + + + + + + + + + + + + +
AbcDef
12
+ """); } @Test public void alignmentMarkerMustBeNextToDashes() { - assertRendering("Abc|Def\n: ---|---", "

Abc|Def\n: ---|---

\n"); - assertRendering("Abc|Def\n--- :|---", "

Abc|Def\n--- :|---

\n"); - assertRendering("Abc|Def\n---|: ---", "

Abc|Def\n---|: ---

\n"); - assertRendering("Abc|Def\n---|--- :", "

Abc|Def\n---|--- :

\n"); + assertRendering( + """ + Abc|Def + : ---|--- + """, + """ +

Abc|Def + : ---|---

+ """); + assertRendering( + """ + Abc|Def + --- :|--- + """, + """ +

Abc|Def + --- :|---

+ """); + assertRendering( + """ + Abc|Def + ---|: --- + """, + """ +

Abc|Def + ---|: ---

+ """); + assertRendering( + """ + Abc|Def + ---|--- : + """, + """ +

Abc|Def + ---|--- :

+ """); } @Test public void bodyCanNotHaveMoreColumnsThanHead() { assertRendering( - "Abc|Def\n---|---\n1|2|3", - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
AbcDef
12
\n"); + """ + Abc|Def + ---|--- + 1|2|3 + """, + """ + + + + + + + + + + + + + +
AbcDef
12
+ """); } @Test public void bodyWithFewerColumnsThanHeadResultsInEmptyCells() { assertRendering( - "Abc|Def|Ghi\n---|---|---\n1|2", - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
AbcDefGhi
12
\n"); + """ + Abc|Def|Ghi + ---|---|--- + 1|2 + """, + """ + + + + + + + + + + + + + + + +
AbcDefGhi
12
+ """); } @Test public void insideBlockQuote() { assertRendering( - "> Abc|Def\n> ---|---\n> 1|2", - "
\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
AbcDef
12
\n" - + "
\n"); + """ + > Abc|Def + > ---|--- + > 1|2 + """, + """ +
+ + + + + + + + + + + + + +
AbcDef
12
+
+ """); } @Test public void tableWithLazyContinuationLine() { assertRendering( - "Abc|Def\n---|---\n1|2\nlazy", - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
AbcDef
12
lazy
\n"); + """ + Abc|Def + ---|--- + 1|2 + lazy + """, + """ + + + + + + + + + + + + + + + + + +
AbcDef
12
lazy
+ """); } @Test public void issue142() { assertRendering( - "||Alveolar|Bilabial\n" - + "|:--|:-:|:-:\n" - + "|**Plosive**|t, d|b\n" - + "|**Tap**|ɾ|", - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
AlveolarBilabial
Plosivet, db
Tapɾ
\n"); + """ + ||Alveolar|Bilabial + |:--|:-:|:-: + |**Plosive**|t, d|b + |**Tap**|ɾ|""", + """ + + + + + + + + + + + + + + + + + + + + +
AlveolarBilabial
Plosivet, db
Tapɾ
+ """); } @Test public void danglingPipe() { assertRendering( - "Abc|Def\n" + "---|---\n" + "1|2\n" + "|", - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
AbcDef
12
\n" - + "

|

\n"); - - assertRendering( - "Abc|Def\n" + "---|---\n" + "1|2\n" + " | ", - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
AbcDef
12
\n" - + "

|

\n"); + """ + Abc|Def + ---|--- + 1|2 + | + """, + """ + + + + + + + + + + + + + +
AbcDef
12
+

|

+ """); + + assertRendering( + """ + Abc|Def + ---|--- + 1|2 + | \s + """, + """ + + + + + + + + + + + + + +
AbcDef
12
+

|

+ """); } @Test public void interruptsParagraph() { assertRendering( - "text\n" + "|a |\n" + "|---|\n" + "|b |", - "

text

\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
a
b
\n"); + """ + text + |a | + |---| + |b | + """, + """ +

text

+ + + + + + + + + + + +
a
b
+ """); } @Test @@ -799,20 +1149,22 @@ public void attributeProviderIsApplied() { String rendered = renderer.render(PARSER.parse("Abc|Def\n---|---\n1|2")); assertThat(rendered) .isEqualTo( - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
AbcDef
12
\n"); + """ + + + + + + + + + + + + + +
AbcDef
12
+ """); } @Test @@ -832,20 +1184,22 @@ public void columnWidthIsRecorded() { String rendered = renderer.render(PARSER.parse("Abc|Def\n-----|---\n1|2")); assertThat(rendered) .isEqualTo( - "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "
AbcDef
12
\n"); + """ + + + + + + + + + + + + + +
AbcDef
12
+ """); } @Test @@ -937,7 +1291,15 @@ public void sourceSpansWhenInterrupting() { .extensions(EXTENSIONS) .includeSourceSpans(IncludeSourceSpans.BLOCKS_AND_INLINES) .build(); - var document = parser.parse("a\n" + "bc\n" + "|de|\n" + "|---|\n" + "|fg|"); + var document = + parser.parse( + """ + a + bc + |de| + |---| + |fg| + """); var paragraph = (Paragraph) document.getFirstChild(); var text = (Text) paragraph.getFirstChild(); diff --git a/commonmark-ext-heading-anchor/src/test/java/org/commonmark/ext/heading/anchor/HeadingAnchorTest.java b/commonmark-ext-heading-anchor/src/test/java/org/commonmark/ext/heading/anchor/HeadingAnchorTest.java index 95ee2d7eb..07b281bf1 100644 --- a/commonmark-ext-heading-anchor/src/test/java/org/commonmark/ext/heading/anchor/HeadingAnchorTest.java +++ b/commonmark-ext-heading-anchor/src/test/java/org/commonmark/ext/heading/anchor/HeadingAnchorTest.java @@ -16,55 +16,96 @@ public class HeadingAnchorTest extends RenderingTestCase { @Test public void baseCaseSingleHeader() { - assertRendering("# Heading here\n", "

Heading here

\n"); + assertRendering( + """ + # Heading here + """, + """ +

Heading here

+ """); } @Test public void singleHeaderWithCodeBlock() { assertRendering( - "Hi there\n# Heading `here`\n", - "

Hi there

\n

Heading here

\n"); + """ + Hi there + # Heading `here` + """, + """ +

Hi there

+

Heading here

+ """); } @Test public void duplicateHeadersMakeUniqueIds() { assertRendering( - "# Heading here\n# Heading here", - "

Heading here

\n

Heading here

\n"); + """ + # Heading here + # Heading here + """, + """ +

Heading here

+

Heading here

+ """); } @Test public void testSupplementalDiacriticalMarks() { - assertRendering("# a\u1DC0", "

a\u1DC0

\n"); + assertRendering( + "# a\u1DC0", + """ +

a\u1DC0

+ """); } @Test public void testUndertieUnicodeDisplayed() { - assertRendering("# undertie \u203F", "

undertie \u203F

\n"); + assertRendering( + "# undertie \u203F", + """ +

undertie \u203F

+ """); } @Test public void testExplicitHeaderCollision() { assertRendering( - "# Header\n# Header\n# Header-1", - "

Header

\n" - + "

Header

\n" - + "

Header-1

\n"); + """ + # Header + # Header + # Header-1 + """, + """ +

Header

+

Header

+

Header-1

+ """); } @Test public void testCaseIsIgnoredWhenComparingIds() { assertRendering( - "# HEADING here\n" + "# heading here", - "

HEADING here

\n" - + "

heading here

\n"); + """ + # HEADING here + # heading here + """, + """ +

HEADING here

+

heading here

+ """); } @Test public void testNestedBlocks() { assertRendering( - "## `h` `e` **l** *l* o", - "

h e l l o

\n"); + """ + ## `h` `e` **l** *l* o + """, + """ +

h e l l o

+ """); } @Test @@ -77,25 +118,45 @@ public void boldEmphasisCharacters() { @Test public void testStrongEmphasis() { assertRendering( - "# _**Hi there**_", - "

Hi there

\n"); + """ + # _**Hi there**_ + """, + """ +

Hi there

+ """); } @Test public void testMultipleSpacesKept() { - assertRendering("# Hi There", "

Hi There

\n"); + assertRendering( + """ + # Hi There + """, + """ +

Hi There

+ """); } @Test public void testNonAsciiCharacterHeading() { - assertRendering("# bär", "

bär

\n"); + assertRendering( + """ + # bär + """, + """ +

bär

+ """); } @Test public void testCombiningDiaeresis() { assertRendering( - "# Product\u036D\u036B", - "

Product\u036D\u036B

\n"); + """ + # Product\u036D\u036B + """, + """ +

Product\u036D\u036B

+ """); } @Override diff --git a/commonmark-ext-task-list-items/src/test/java/org/commonmark/ext/task/list/items/TaskListItemsTest.java b/commonmark-ext-task-list-items/src/test/java/org/commonmark/ext/task/list/items/TaskListItemsTest.java index dd9290b6e..ff74c0d66 100644 --- a/commonmark-ext-task-list-items/src/test/java/org/commonmark/ext/task/list/items/TaskListItemsTest.java +++ b/commonmark-ext-task-list-items/src/test/java/org/commonmark/ext/task/list/items/TaskListItemsTest.java @@ -20,110 +20,253 @@ public class TaskListItemsTest extends RenderingTestCase { @Test public void baseCase() { assertRendering( - "- [x] this is *done*\n", - "\n"); + """ + - [x] this is *done* + """, + """ + + """ + .formatted(HTML_CHECKED)); assertRendering( - "- [ ] do this\n", "\n"); + """ + - [ ] do this + """, + """ + + """ + .formatted(HTML_UNCHECKED)); assertRendering( - "- [x] foo\n" + " - [ ] bar\n" + " - [x] baz\n" + "- [ ] bim", - "\n"); + """ + - [x] foo + - [ ] bar + - [x] baz + - [ ] bim + """, + """ + + """ + .formatted(HTML_CHECKED, HTML_UNCHECKED, HTML_CHECKED, HTML_UNCHECKED)); assertRendering( - "* [ ] do this\n* [ ] and this", - "\n"); + """ + * [ ] do this + * [ ] and this + """, + """ + + """ + .formatted(HTML_UNCHECKED, HTML_UNCHECKED)); assertRendering( - "+ [x] one\n" + " - [ ] two\n" + " * [x] three\n", - "\n"); + """ + + [x] one + - [ ] two + * [x] three + """, + """ + + """ + .formatted(HTML_CHECKED, HTML_UNCHECKED, HTML_CHECKED)); assertRendering( - "TODO list\n" - + "---------\n" - + "- [ ] first task\n" - + "- [x] second task\n" - + "- [ ] third task\n\n" - + "Let me know when you are finished", - "

TODO list

\n" - + "\n" - + "

Let me know when you are finished

\n"); + """ + TODO list + --------- + - [ ] first task + - [x] second task + - [ ] third task + + Let me know when you are finished + """, + """ +

TODO list

+ +

Let me know when you are finished

+ """ + .formatted(HTML_UNCHECKED, HTML_CHECKED, HTML_UNCHECKED)); } @Test public void notListItem() { - assertRendering("[x] this is not a task\n", "

[x] this is not a task

\n"); assertRendering( - " [ ] this is not a task either\n", "

[ ] this is not a task either

\n"); + """ + [x] this is not a task + """, + """ +

[x] this is not a task

+ """); + assertRendering( + """ + [ ] this is not a task either + """, + """ +

[ ] this is not a task either

+ """); } @Test public void notValidTaskFormat() { - assertRendering("- [x]no space\n", "\n"); - assertRendering( - "- [O] is not a _task_\n", "\n"); - assertRendering("* [] neither is this\n", "\n"); - assertRendering( - "* [ ] nor this\n" + "* [XX] nor this\n", - "\n"); - assertRendering("+ [x]] is not a task\n", "\n"); - assertRendering("- [x isn't\n", "\n"); - assertRendering("- [[x is not\n", "\n"); - assertRendering("- x] nope\n", "\n"); - assertRendering("- x]] no way\n", "\n"); - assertRendering("+ (x) sorry no\n", "\n"); - assertRendering("+ {x} sorry not sorry\n", "\n"); - assertRendering("+ [[x]] nooo\n", "\n"); - assertRendering( - "+ text before [x] is not a task\n", - "\n"); - assertRendering("* [x] \n* [ ] \n", "\n"); + assertRendering( + """ + - [x]no space + """, + """ + + """); + assertRendering( + """ + - [O] is not a _task_ + """, + """ + + """); + assertRendering( + """ + * [] neither is this + """, + """ + + """); + assertRendering( + """ + * [ ] nor this + * [XX] nor this + """, + """ + + """); + assertRendering( + """ + + [x]] is not a task + """, + """ + + """); + assertRendering( + """ + - [x isn't + """, + """ + + """); + assertRendering( + """ + - [[x is not + """, + """ + + """); + assertRendering( + """ + - x] nope + """, + """ + + """); + assertRendering( + """ + - x]] no way + """, + """ + + """); + assertRendering( + """ + + (x) sorry no + """, + """ + + """); + assertRendering( + """ + + {x} sorry not sorry + """, + """ + + """); + assertRendering( + """ + + [[x]] nooo + """, + """ + + """); + assertRendering( + """ + + text before [x] is not a task + """, + """ + + """); + assertRendering( + """ + * [x] \s + * [ ] \s + """, + """ + + """); } @Override diff --git a/commonmark-ext-yaml-front-matter/src/test/java/org/commonmark/ext/front/matter/YamlFrontMatterDataTest.java b/commonmark-ext-yaml-front-matter/src/test/java/org/commonmark/ext/front/matter/YamlFrontMatterDataTest.java index 6ead2c48b..6493ba716 100644 --- a/commonmark-ext-yaml-front-matter/src/test/java/org/commonmark/ext/front/matter/YamlFrontMatterDataTest.java +++ b/commonmark-ext-yaml-front-matter/src/test/java/org/commonmark/ext/front/matter/YamlFrontMatterDataTest.java @@ -20,7 +20,13 @@ Set getExtensions() { @Test public void simpleValue() { - final String input = "---" + "\nhello: world" + "\n..." + "\n" + "\ngreat"; + final String input = + """ + --- + hello: world + ... + + great"""; final String rendered = "

great

\n"; Map> data = getFrontMatterData(input); @@ -35,7 +41,13 @@ public void simpleValue() { @Test public void emptyValue() { - final String input = "---" + "\nkey:" + "\n---" + "\n" + "\ngreat"; + final String input = + """ + --- + key: + --- + + great"""; final String rendered = "

great

\n"; Map> data = getFrontMatterData(input); @@ -50,7 +62,15 @@ public void emptyValue() { @Test public void listValues() { final String input = - "---" + "\nlist:" + "\n - value1" + "\n - value2" + "\n..." + "\n" + "\ngreat"; + """ + --- + list: + - value1 + - value2 + ... + + great + """; final String rendered = "

great

\n"; Map> data = getFrontMatterData(input); @@ -67,13 +87,15 @@ public void listValues() { @Test public void literalValue1() { final String input = - "---" - + "\nliteral: |" - + "\n hello markdown!" - + "\n literal thing..." - + "\n---" - + "\n" - + "\ngreat"; + """ + --- + literal: | + hello markdown! + literal thing... + --- + + great + """; final String rendered = "

great

\n"; Map> data = getFrontMatterData(input); @@ -89,7 +111,14 @@ public void literalValue1() { @Test public void literalValue2() { final String input = - "---" + "\nliteral: |" + "\n - hello markdown!" + "\n---" + "\n" + "\ngreat"; + """ + --- + literal: | + - hello markdown! + --- + + great + """; final String rendered = "

great

\n"; Map> data = getFrontMatterData(input); @@ -105,17 +134,19 @@ public void literalValue2() { @Test public void complexValues() { final String input = - "---" - + "\nsimple: value" - + "\nliteral: |" - + "\n hello markdown!" - + "\n" - + "\n literal literal" - + "\nlist:" - + "\n - value1" - + "\n - value2" - + "\n---" - + "\ngreat"; + """ + --- + simple: value + literal: | + hello markdown! + + literal literal + list: + - value1 + - value2 + --- + great + """; final String rendered = "

great

\n"; Map> data = getFrontMatterData(input); @@ -140,7 +171,12 @@ public void complexValues() { @Test public void empty() { - final String input = "---\n" + "---\n" + "test"; + final String input = + """ + --- + --- + test + """; final String rendered = "

test

\n"; Map> data = getFrontMatterData(input); @@ -153,9 +189,20 @@ public void empty() { @Test public void yamlInParagraph() { final String input = - "# hello\n" + "\nhello markdown world!" + "\n---" + "\nhello: world" + "\n---"; + """ + # hello + + hello markdown world! + --- + hello: world + --- + """; final String rendered = - "

hello

\n

hello markdown world!

\n

hello: world

\n"; + """ +

hello

+

hello markdown world!

+

hello: world

+ """; Map> data = getFrontMatterData(input); @@ -166,8 +213,20 @@ public void yamlInParagraph() { @Test public void yamlOnSecondLine() { - final String input = "hello\n" + "\n---" + "\nhello: world" + "\n---"; - final String rendered = "

hello

\n
\n

hello: world

\n"; + final String input = + """ + hello + + --- + hello: world + --- + """; + final String rendered = + """ +

hello

+
+

hello: world

+ """; Map> data = getFrontMatterData(input); @@ -178,8 +237,16 @@ public void yamlOnSecondLine() { @Test public void nonMatchedStartTag() { - final String input = "----\n" + "test"; - final String rendered = "
\n

test

\n"; + final String input = + """ + ---- + test + """; + final String rendered = + """ +
+

test

+ """; Map> data = getFrontMatterData(input); @@ -190,8 +257,22 @@ public void nonMatchedStartTag() { @Test public void inList() { - final String input = "* ---\n" + " ---\n" + "test"; - final String rendered = "
    \n
  • \n
    \n
    \n
  • \n
\n

test

\n"; + final String input = + """ + * --- + --- + test + """; + final String rendered = + """ +
    +
  • +
    +
    +
  • +
+

test

+ """; Map> data = getFrontMatterData(input); @@ -202,7 +283,12 @@ public void inList() { @Test public void visitorIgnoresOtherCustomNodes() { - final String input = "---" + "\nhello: world" + "\n---" + "\n"; + final String input = + """ + --- + hello: world + --- + """; YamlFrontMatterVisitor visitor = new YamlFrontMatterVisitor(); Node document = parser.parse(input); @@ -217,7 +303,12 @@ public void visitorIgnoresOtherCustomNodes() { @Test public void nodesCanBeModified() { - final String input = "---" + "\nhello: world" + "\n---" + "\n"; + final String input = + """ + --- + hello: world + --- + """; Node document = parser.parse(input); YamlFrontMatterNode node = (YamlFrontMatterNode) document.getFirstChild().getFirstChild(); @@ -235,7 +326,12 @@ public void nodesCanBeModified() { @Test public void dotInKeys() { - final String input = "---" + "\nms.author: author" + "\n---" + "\n"; + final String input = + """ + --- + ms.author: author + --- + """; Map> data = getFrontMatterData(input); @@ -248,7 +344,13 @@ public void dotInKeys() { @Test public void singleQuotedLiterals() { final String input = - "---" + "\nstring: 'It''s me'" + "\nlist:" + "\n - 'I''m here'" + "\n---" + "\n"; + """ + --- + string: 'It''s me' + list: + - 'I''m here' + --- + """; Map> data = getFrontMatterData(input); @@ -260,12 +362,13 @@ public void singleQuotedLiterals() { @Test public void doubleQuotedLiteral() { final String input = - "---" - + "\nstring: \"backslash: \\\\ quote: \\\"\"" - + "\nlist:" - + "\n - \"hey\"" - + "\n---" - + "\n"; + """ + --- + string: "backslash: \\\\ quote: \\"" + list: + - "hey" + --- + """; Map> data = getFrontMatterData(input); diff --git a/commonmark-integration-test/src/test/java/org/commonmark/integration/ExtensionsIntegrationTest.java b/commonmark-integration-test/src/test/java/org/commonmark/integration/ExtensionsIntegrationTest.java index 345c02d15..e3d43b430 100644 --- a/commonmark-integration-test/src/test/java/org/commonmark/integration/ExtensionsIntegrationTest.java +++ b/commonmark-integration-test/src/test/java/org/commonmark/integration/ExtensionsIntegrationTest.java @@ -19,16 +19,27 @@ public class ExtensionsIntegrationTest extends RenderingTestCase { @Test public void testImageAttributes() { assertRendering( - "![text](/url.png){height=5 width=6}", - "

\"text\"

\n"); + """ + ![text](/url.png){height=5 width=6} + """, + """ +

text

+ """); } @Test public void testTaskListItems() { assertRendering( - "- [ ] task to do\n- [x] task done\n", - "
    \n
  • task to do
  • \n" - + "
  • task done
  • \n
\n"); + """ + - [ ] task to do + - [x] task done + """, + """ +
    +
  • task to do
  • +
  • task done
  • +
+ """); } @Override diff --git a/commonmark-integration-test/src/test/java/org/commonmark/ui/DingusApp.java b/commonmark-integration-test/src/test/java/org/commonmark/ui/DingusApp.java index e7870f411..a72ed959c 100644 --- a/commonmark-integration-test/src/test/java/org/commonmark/ui/DingusApp.java +++ b/commonmark-integration-test/src/test/java/org/commonmark/ui/DingusApp.java @@ -80,10 +80,17 @@ public void changedUpdate(DocumentEvent e) {} tabbedPane.addChangeListener(e -> updateOutput(input.getText())); input.setText( - "# Example\n" - + "Enter text *here* and see how it renders on the right.\n\n" - + "* Try\n* this\n\n" - + "```\nor this\n```"); + """ + # Example + Enter text *here* and see how it renders on the right. + + * Try + * this + + ``` + or this + ``` + """); updateOutput(input.getText()); frame.setLayout(new GridLayout()); diff --git a/commonmark/src/test/java/org/commonmark/test/DelimitedTest.java b/commonmark/src/test/java/org/commonmark/test/DelimitedTest.java index 06007e4bd..bb58ab74d 100644 --- a/commonmark/src/test/java/org/commonmark/test/DelimitedTest.java +++ b/commonmark/src/test/java/org/commonmark/test/DelimitedTest.java @@ -13,7 +13,12 @@ public class DelimitedTest { @Test public void emphasisDelimiters() { String input = - "* *emphasis* \n" + "* **strong** \n" + "* _important_ \n" + "* __CRITICAL__ \n"; + """ + * *emphasis*\s + * **strong**\s + * _important_\s + * __CRITICAL__\s + """; Parser parser = Parser.builder().build(); Node document = parser.parse(input); diff --git a/commonmark/src/test/java/org/commonmark/test/FencedCodeBlockParserTest.java b/commonmark/src/test/java/org/commonmark/test/FencedCodeBlockParserTest.java index a07519756..1ccd8a8db 100644 --- a/commonmark/src/test/java/org/commonmark/test/FencedCodeBlockParserTest.java +++ b/commonmark/src/test/java/org/commonmark/test/FencedCodeBlockParserTest.java @@ -3,7 +3,6 @@ import static org.assertj.core.api.Assertions.assertThat; import org.commonmark.node.FencedCodeBlock; -import org.commonmark.node.Node; import org.commonmark.parser.Parser; import org.commonmark.renderer.html.HtmlRenderer; import org.commonmark.testutil.RenderingTestCase; @@ -16,7 +15,13 @@ public class FencedCodeBlockParserTest extends RenderingTestCase { @Test public void backtickInfo() { - Node document = PARSER.parse("```info ~ test\ncode\n```"); + var s = + """ + ```info ~ test + code + ``` + """; + var document = PARSER.parse(s); FencedCodeBlock codeBlock = (FencedCodeBlock) document.getFirstChild(); assertThat(codeBlock.getInfo()).isEqualTo("info ~ test"); assertThat(codeBlock.getLiteral()).isEqualTo("code\n"); @@ -25,34 +30,78 @@ public void backtickInfo() { @Test public void backtickInfoDoesntAllowBacktick() { assertRendering( - "```info ` test\ncode\n```", - "

```info ` test\ncode

\n
\n"); + """ + ```info ` test + code + ``` + """, + """ +

```info ` test + code

+
+ """); } @Test public void backtickAndTildeCantBeMixed() { - assertRendering("``~`\ncode\n``~`", "

~` code ~`

\n"); + assertRendering( + """ + ``~` + code + ``~` + """, + """ +

~` code ~`

+ """); } @Test public void closingCanHaveSpacesAfter() { - assertRendering("```\ncode\n``` ", "
code\n
\n"); + assertRendering( + """ + ``` + code + ``` \s + """, + """ +
code
+                
+ """); } @Test public void closingCanNotHaveNonSpaces() { - assertRendering("```\ncode\n``` a", "
code\n``` a\n
\n"); + assertRendering( + """ + ``` + code + ``` a + """, + """ +
code
+                ``` a
+                
+ """); } @Test public void issue151() { assertRendering( - "```\nthis code\n\nshould not have BRs or paragraphs in it\nok\n```", - "
this code\n"
-                        + "\n"
-                        + "should not have BRs or paragraphs in it\n"
-                        + "ok\n"
-                        + "
\n"); + """ + ``` + this code + + should not have BRs or paragraphs in it + ok + ``` + """, + """ +
this code
+
+                should not have BRs or paragraphs in it
+                ok
+                
+ """); } @Override diff --git a/commonmark/src/test/java/org/commonmark/test/ListTightLooseTest.java b/commonmark/src/test/java/org/commonmark/test/ListTightLooseTest.java index e606d467e..047508436 100644 --- a/commonmark/src/test/java/org/commonmark/test/ListTightLooseTest.java +++ b/commonmark/src/test/java/org/commonmark/test/ListTightLooseTest.java @@ -7,149 +7,241 @@ public class ListTightLooseTest extends CoreRenderingTestCase { @Test public void tight() { assertRendering( - "- foo\n" + "- bar\n" + "+ baz\n", - "
    \n" - + "
  • foo
  • \n" - + "
  • bar
  • \n" - + "
\n" - + "
    \n" - + "
  • baz
  • \n" - + "
\n"); + """ + - foo + - bar + + baz + """, + """ +
    +
  • foo
  • +
  • bar
  • +
+
    +
  • baz
  • +
+ """); } @Test public void loose() { assertRendering( - "- foo\n" + "\n" + "- bar\n" + "\n" + "\n" + "- baz\n", - "
    \n" - + "
  • \n" - + "

    foo

    \n" - + "
  • \n" - + "
  • \n" - + "

    bar

    \n" - + "
  • \n" - + "
  • \n" - + "

    baz

    \n" - + "
  • \n" - + "
\n"); + """ + - foo + + - bar + + + - baz + """, + """ +
    +
  • +

    foo

    +
  • +
  • +

    bar

    +
  • +
  • +

    baz

    +
  • +
+ """); } @Test public void looseNested() { assertRendering( - "- foo\n" + " - bar\n" + "\n" + "\n" + " baz", - "
    \n" - + "
  • foo\n" - + "
      \n" - + "
    • \n" - + "

      bar

      \n" - + "

      baz

      \n" - + "
    • \n" - + "
    \n" - + "
  • \n" - + "
\n"); + """ + - foo + - bar + + + baz + """, + """ +
    +
  • foo +
      +
    • +

      bar

      +

      baz

      +
    • +
    +
  • +
+ """); } @Test public void looseNested2() { assertRendering( - "- a\n" + " - b\n" + "\n" + " c\n" + "- d\n", - "
    \n" - + "
  • a\n" - + "
      \n" - + "
    • \n" - + "

      b

      \n" - + "

      c

      \n" - + "
    • \n" - + "
    \n" - + "
  • \n" - + "
  • d
  • \n" - + "
\n"); + """ + - a + - b + + c + - d + """, + """ +
    +
  • a +
      +
    • +

      b

      +

      c

      +
    • +
    +
  • +
  • d
  • +
+ """); } @Test public void looseOuter() { assertRendering( - "- foo\n" + " - bar\n" + "\n" + "\n" + " baz", - "
    \n" - + "
  • \n" - + "

    foo

    \n" - + "
      \n" - + "
    • bar
    • \n" - + "
    \n" - + "

    baz

    \n" - + "
  • \n" - + "
\n"); + """ + - foo + - bar + + + baz + """, + """ +
    +
  • +

    foo

    +
      +
    • bar
    • +
    +

    baz

    +
  • +
+ """); } @Test public void looseListItem() { assertRendering( - "- one\n" + "\n" + " two\n", - "
    \n" + "
  • \n" + "

    one

    \n" + "

    two

    \n" + "
  • \n" + "
\n"); + """ + - one + + two + """, + """ +
    +
  • +

    one

    +

    two

    +
  • +
+ """); } @Test public void tightWithBlankLineAfter() { assertRendering( - "- foo\n" + "- bar\n" + "\n", - "
    \n" + "
  • foo
  • \n" + "
  • bar
  • \n" + "
\n"); + """ + - foo + - bar + + """, + """ +
    +
  • foo
  • +
  • bar
  • +
+ """); } @Test public void tightListWithCodeBlock() { assertRendering( - "- a\n" + "- ```\n" + " b\n" + "\n" + "\n" + " ```\n" + "- c\n", - "
    \n" - + "
  • a
  • \n" - + "
  • \n" - + "
    b\n"
    -                        + "\n"
    -                        + "\n"
    -                        + "
    \n" - + "
  • \n" - + "
  • c
  • \n" - + "
\n"); + """ + - a + - ``` + b + + + ``` + - c + """, + """ +
    +
  • a
  • +
  • +
    b
    +
    +
    +                
    +
  • +
  • c
  • +
+ """); } @Test public void tightListWithCodeBlock2() { assertRendering( - "* foo\n" + " ```\n" + " bar\n" + "\n" + " ```\n" + " baz\n", - "
    \n" - + "
  • foo\n" - + "
    bar\n"
    -                        + "\n"
    -                        + "
    \n" - + "baz
  • \n" - + "
\n"); + """ + * foo + ``` + bar + + ``` + baz + """, + """ +
    +
  • foo +
    bar
    +
    +                
    + baz
  • +
+ """); } @Test public void looseEmptyListItem() { assertRendering( - "* a\n" + "*\n" + "\n" + "* c", - "
    \n" - + "
  • \n" - + "

    a

    \n" - + "
  • \n" - + "
  • \n" - + "
  • \n" - + "

    c

    \n" - + "
  • \n" - + "
\n"); + """ + * a + * + + * c""", + """ +
    +
  • +

    a

    +
  • +
  • +
  • +

    c

    +
  • +
+ """); } @Test public void looseBlankLineAfterCodeBlock() { assertRendering( - "1. ```\n" + " foo\n" + " ```\n" + "\n" + " bar", - "
    \n" - + "
  1. \n" - + "
    foo\n"
    -                        + "
    \n" - + "

    bar

    \n" - + "
  2. \n" - + "
\n"); + """ + 1. ``` + foo + ``` + + bar + """, + """ +
    +
  1. +
    foo
    +                
    +

    bar

    +
  2. +
+ """); } } diff --git a/commonmark/src/test/java/org/commonmark/test/SpecialInputTest.java b/commonmark/src/test/java/org/commonmark/test/SpecialInputTest.java index c3d535e72..8dcdbebe5 100644 --- a/commonmark/src/test/java/org/commonmark/test/SpecialInputTest.java +++ b/commonmark/src/test/java/org/commonmark/test/SpecialInputTest.java @@ -56,69 +56,222 @@ public void indentedCodeBlockWithMixedTabsAndSpaces() { @Test public void tightListInBlockQuote() { assertRendering( - "> *\n> * a", "
\n
    \n
  • \n
  • a
  • \n
\n
\n"); + """ + > * + > * a + """, + """ +
+
    +
  • +
  • a
  • +
+
+ """); } @Test public void looseListInBlockQuote() { // Second line in block quote is considered blank for purpose of loose list assertRendering( - "> *\n>\n> * a", - "
\n
    \n
  • \n
  • \n

    a

    \n
  • \n
\n
\n"); + """ + > * + > + > * a + """, + """ +
+
    +
  • +
  • +

    a

    +
  • +
+
+ """); } @Test public void lineWithOnlySpacesAfterListBullet() { - assertRendering("- \n \n foo\n", "
    \n
  • \n
\n

foo

\n"); + assertRendering( + """ + - \s + \s + foo + """, + """ +
    +
  • +
+

foo

+ """); } @Test public void listWithTwoSpacesForFirstBullet() { // We have two spaces after the bullet, but no content. With content, the next line would be // required - assertRendering("* \n foo\n", "
    \n
  • foo
  • \n
\n"); + assertRendering( + """ + * \s + foo + """, + """ +
    +
  • foo
  • +
+ """); } @Test public void orderedListMarkerOnly() { - assertRendering("2.", "
    \n
  1. \n
\n"); + assertRendering( + """ + 2. + """, + """ +
    +
  1. +
+ """); } @Test public void columnIsInTabOnPreviousLine() { assertRendering( - "- foo\n\n\tbar\n\n# baz\n", - "
    \n
  • \n

    foo

    \n

    bar

    \n
  • \n
\n

baz

\n"); + """ + - foo + + \tbar + + # baz + """, + """ +
    +
  • +

    foo

    +

    bar

    +
  • +
+

baz

+ """); assertRendering( - "- foo\n\n\tbar\n# baz\n", - "
    \n
  • \n

    foo

    \n

    bar

    \n
  • \n
\n

baz

\n"); + """ + - foo + + \tbar + # baz + """, + """ +
    +
  • +

    foo

    +

    bar

    +
  • +
+

baz

+ """); } @Test public void linkLabelWithBracket() { - assertRendering("[a[b]\n\n[a[b]: /", "

[a[b]

\n

[a[b]: /

\n"); - assertRendering("[a]b]\n\n[a]b]: /", "

[a]b]

\n

[a]b]: /

\n"); - assertRendering("[a[b]]\n\n[a[b]]: /", "

[a[b]]

\n

[a[b]]: /

\n"); + assertRendering( + """ + [a[b] + + [a[b]: / + """, + """ +

[a[b]

+

[a[b]: /

+ """); + assertRendering( + """ + [a]b] + + [a]b]: / + """, + """ +

[a]b]

+

[a]b]: /

+ """); + assertRendering( + """ + [a[b]] + + [a[b]]: / + """, + """ +

[a[b]]

+

[a[b]]: /

+ """); } @Test public void linkLabelLength() { String label1 = "a".repeat(999); assertRendering( - "[foo][" + label1 + "]\n\n[" + label1 + "]: /", "

foo

\n"); + """ + [foo][%s] + + [%s]: / + """ + .formatted(label1, label1), + """ +

foo

+ """); assertRendering( - "[foo][x" + label1 + "]\n\n[x" + label1 + "]: /", - "

[foo][x" + label1 + "]

\n

[x" + label1 + "]: /

\n"); + """ + [foo][x%s] + + [x%s]: / + """ + .formatted(label1, label1), + """ +

[foo][x%s]

+

[x%s]: /

+ """ + .formatted(label1, label1)); assertRendering( - "[foo][\n" + label1 + "]\n\n[\n" + label1 + "]: /", - "

[foo][\n" + label1 + "]

\n

[\n" + label1 + "]: /

\n"); + """ + [foo][ + %s] + + [ + %s]: / + """ + .formatted(label1, label1), + """ +

[foo][ + %s]

+

[ + %s]: /

+ """ + .formatted(label1, label1)); String label2 = "a\n".repeat(499); assertRendering( - "[foo][" + label2 + "]\n\n[" + label2 + "]: /", "

foo

\n"); + """ + [foo][%s] + + [%s]: / + """ + .formatted(label2, label2), + """ +

foo

+ """); assertRendering( - "[foo][12" + label2 + "]\n\n[12" + label2 + "]: /", - "

[foo][12" + label2 + "]

\n

[12" + label2 + "]: /

\n"); + """ + [foo][12%s] + + [12%s]: / + """ + .formatted(label2, label2), + """ +

[foo][12%s]

+

[12%s]: /

+ """ + .formatted(label2, label2)); } @Test @@ -143,9 +296,25 @@ public void linkReferenceBackslash() { // Backslash escapes ']', so not a valid link label assertRendering("[\\]: test", "

[]: test

\n"); // Backslash is a literal, so valid - assertRendering("[a\\b]\n\n[a\\b]: test", "

a\\b

\n"); + assertRendering( + """ + [a\\b] + + [a\\b]: test + """, + """ +

a\\b

+ """); // Backslash escapes `]` but there's another `]`, valid - assertRendering("[a\\]]\n\n[a\\]]: test", "

a]

\n"); + assertRendering( + """ + [a\\]] + + [a\\]]: test + """, + """ +

a]

+ """); } // commonmark/cmark#177 @@ -170,22 +339,29 @@ public void renderEvenRegexpProducesStackoverflow() { @Test public void deeplyIndentedList() { assertRendering( - "* one\n" + " * two\n" + " * three\n" + " * four", - "
    \n" - + "
  • one\n" - + "
      \n" - + "
    • two\n" - + "
        \n" - + "
      • three\n" - + "
          \n" - + "
        • four
        • \n" - + "
        \n" - + "
      • \n" - + "
      \n" - + "
    • \n" - + "
    \n" - + "
  • \n" - + "
\n"); + """ + * one + * two + * three + * four + """, + """ +
    +
  • one +
      +
    • two +
        +
      • three +
          +
        • four
        • +
        +
      • +
      +
    • +
    +
  • +
+ """); } @Test @@ -193,7 +369,15 @@ public void trailingTabs() { // The tab is not treated as 4 spaces here and so does not result in a hard line break, but // is just preserved. // This matches what commonmark.js did at the time of writing. - assertRendering("a\t\nb\n", "

a\t\nb

\n"); + assertRendering( + """ + a\t + b + """, + """ +

a\t + b

+ """); } @Test @@ -209,36 +393,67 @@ public void unicodePunctuationEmphasis() { @Test public void htmlBlockInterruptingList() { assertRendering( - "- \n", - "
    \n" - + "
  • \n" - + "
  • \n" - + "
\n"); + """ + - + """, + """ +
    +
  • +
  • +
+ """); assertRendering( - "- \n", - "
    \n" - + "
  • \n" - + "\n"); + """ + - + """, + """ +
      +
    • + + """); } @Test public void emphasisAfterHardLineBreak() { assertRendering( - "Hello \n" + "**Bar**\n" + "Foo\n", - "

      Hello
      \n" + "Bar\n" + "Foo

      \n"); + """ + Hello \s + **Bar** + Foo + """, + """ +

      Hello
      + Bar + Foo

      + """); assertRendering( - "Hello \n" + "**Bar** \n" + "Foo\n", - "

      Hello
      \n" + "Bar
      \n" + "Foo

      \n"); + """ + Hello \s + **Bar** \s + Foo + """, + """ +

      Hello
      + Bar
      + Foo

      + """); } } diff --git a/commonmark/src/test/java/org/commonmark/test/TextContentRendererTest.java b/commonmark/src/test/java/org/commonmark/test/TextContentRendererTest.java index d0b5bbfdc..f72723843 100644 --- a/commonmark/src/test/java/org/commonmark/test/TextContentRendererTest.java +++ b/commonmark/src/test/java/org/commonmark/test/TextContentRendererTest.java @@ -32,17 +32,56 @@ public void textContentText() { assertCompact(s, "foo bar"); assertStripped(s, "foo bar"); - s = "foo foo\n\nbar\nbar"; - assertCompact(s, "foo foo\nbar\nbar"); - assertSeparate(s, "foo foo\n\nbar\nbar"); + s = + """ + foo foo + + bar + bar"""; + assertCompact( + s, + """ + foo foo + bar + bar"""); + assertSeparate( + s, + """ + foo foo + + bar + bar"""); assertStripped(s, "foo foo bar bar"); } @Test public void textContentHeading() { - assertCompact("# Heading\n\nFoo", "Heading\nFoo"); - assertSeparate("# Heading\n\nFoo", "Heading\n\nFoo"); - assertStripped("# Heading\n\nFoo", "Heading: Foo"); + assertCompact( + """ + # Heading + + Foo + """, + """ + Heading + Foo"""); + assertSeparate( + """ + # Heading + + Foo + """, + """ + Heading + + Foo"""); + assertStripped( + """ + # Heading + + Foo + """, + "Heading: Foo"); } @Test @@ -57,9 +96,29 @@ public void textContentEmphasis() { assertCompact(s, "foo foo bar bar"); assertStripped(s, "foo foo bar bar"); - s = "foo\n***foo***\nbar\n\n***bar***"; - assertCompact(s, "foo\nfoo\nbar\nbar"); - assertSeparate(s, "foo\nfoo\nbar\n\nbar"); + s = + """ + foo + ***foo*** + bar + + ***bar*** + """; + assertCompact( + s, + """ + foo + foo + bar + bar"""); + assertSeparate( + s, + """ + foo + foo + bar + + bar"""); assertStripped(s, "foo foo bar bar"); } @@ -67,9 +126,30 @@ public void textContentEmphasis() { public void textContentQuotes() { String s; - s = "foo\n>foo\nbar\n\nbar"; - assertCompact(s, "foo\n«foo\nbar»\nbar"); - assertSeparate(s, "foo\n\n«foo\nbar»\n\nbar"); + s = + """ + foo + >foo + bar + + bar + """; + assertCompact( + s, + """ + foo + «foo + bar» + bar"""); + assertSeparate( + s, + """ + foo + + «foo + bar» + + bar"""); assertStripped(s, "foo «foo bar» bar"); } @@ -94,52 +174,236 @@ public void textContentImages() { public void textContentLists() { String s; - s = "foo\n* foo\n* bar\n\nbar"; - assertCompact(s, "foo\n* foo\n* bar\nbar"); - assertSeparate(s, "foo\n\n* foo\n* bar\n\nbar"); + s = + """ + foo + * foo + * bar + + bar"""; + assertCompact( + s, + """ + foo + * foo + * bar + bar"""); + assertSeparate( + s, + """ + foo + + * foo + * bar + + bar"""); assertStripped(s, "foo foo bar bar"); - s = "foo\n- foo\n- bar\n\nbar"; - assertCompact(s, "foo\n- foo\n- bar\nbar"); - assertSeparate(s, "foo\n\n- foo\n- bar\n\nbar"); + s = + """ + foo + - foo + - bar + + bar + """; + assertCompact( + s, + """ + foo + - foo + - bar + bar"""); + assertSeparate( + s, + """ + foo + + - foo + - bar + + bar"""); assertStripped(s, "foo foo bar bar"); - s = "foo\n1. foo\n2. bar\n\nbar"; - assertCompact(s, "foo\n1. foo\n2. bar\nbar"); - assertSeparate(s, "foo\n\n1. foo\n2. bar\n\nbar"); + s = + """ + foo + 1. foo + 2. bar + + bar + """; + assertCompact( + s, + """ + foo + 1. foo + 2. bar + bar"""); + assertSeparate( + s, + """ + foo + + 1. foo + 2. bar + + bar"""); assertStripped(s, "foo 1. foo 2. bar bar"); - s = "foo\n0) foo\n1) bar\n\nbar"; - assertCompact(s, "foo\n0) foo\n1) bar\nbar"); - assertSeparate(s, "foo\n0) foo\n\n1) bar\n\nbar"); + s = + """ + foo + 0) foo + 1) bar + + bar + """; + assertCompact( + s, + """ + foo + 0) foo + 1) bar + bar"""); + assertSeparate( + s, + """ + foo + 0) foo + + 1) bar + + bar"""); assertStripped(s, "foo 0) foo 1) bar bar"); - s = "bar\n1. foo\n 1. bar\n2. foo"; - assertCompact(s, "bar\n1. foo\n 1. bar\n2. foo"); - assertSeparate(s, "bar\n\n1. foo\n 1. bar\n2. foo"); + s = + """ + bar + 1. foo + 1. bar + 2. foo + """; + assertCompact( + s, + """ + bar + 1. foo + 1. bar + 2. foo"""); + assertSeparate( + s, + """ + bar + + 1. foo + 1. bar + 2. foo"""); assertStripped(s, "bar 1. foo 1. bar 2. foo"); - s = "bar\n* foo\n - bar\n* foo"; - assertCompact(s, "bar\n* foo\n - bar\n* foo"); - assertSeparate(s, "bar\n\n* foo\n - bar\n* foo"); + s = + """ + bar + * foo + - bar + * foo + """; + assertCompact( + s, + """ + bar + * foo + - bar + * foo"""); + assertSeparate( + s, + """ + bar + + * foo + - bar + * foo"""); assertStripped(s, "bar foo bar foo"); - s = "bar\n* foo\n 1. bar\n 2. bar\n* foo"; - assertCompact(s, "bar\n* foo\n 1. bar\n 2. bar\n* foo"); - assertSeparate(s, "bar\n\n* foo\n 1. bar\n 2. bar\n* foo"); + s = + """ + bar + * foo + 1. bar + 2. bar + * foo + """; + assertCompact( + s, + """ + bar + * foo + 1. bar + 2. bar + * foo"""); + assertSeparate( + s, + """ + bar + + * foo + 1. bar + 2. bar + * foo"""); assertStripped(s, "bar foo 1. bar 2. bar foo"); - s = "bar\n1. foo\n * bar\n * bar\n2. foo"; - assertCompact(s, "bar\n1. foo\n * bar\n * bar\n2. foo"); - assertSeparate(s, "bar\n\n1. foo\n * bar\n * bar\n2. foo"); + s = + """ + bar + 1. foo + * bar + * bar + 2. foo + """; + assertCompact( + s, + """ + bar + 1. foo + * bar + * bar + 2. foo"""); + assertSeparate( + s, + """ + bar + + 1. foo + * bar + * bar + 2. foo"""); assertStripped(s, "bar 1. foo bar bar 2. foo"); // For a loose list (not tight) - s = "foo\n\n* bar\n\n* baz"; + s = + """ + foo + + * bar + + * baz + """; // Compact ignores loose - assertCompact(s, "foo\n* bar\n* baz"); + assertCompact( + s, + """ + foo + * bar + * baz"""); // Separate preserves it - assertSeparate(s, "foo\n\n* bar\n\n* baz"); + assertSeparate( + s, + """ + foo + + * bar + + * baz"""); assertStripped(s, "foo bar baz"); } @@ -151,14 +415,43 @@ public void textContentCode() { @Test public void textContentCodeBlock() { String s; - s = "foo\n```\nfoo\nbar\n```\nbar"; + s = + """ + foo + ``` + foo + bar + ``` + bar + """; assertCompact(s, "foo\nfoo\nbar\nbar"); assertSeparate(s, "foo\n\nfoo\nbar\n\nbar"); assertStripped(s, "foo foo bar bar"); - s = "foo\n\n foo\n bar\nbar"; - assertCompact(s, "foo\nfoo\n bar\nbar"); - assertSeparate(s, "foo\n\nfoo\n bar\n\nbar"); + s = + """ + foo + + foo + bar + bar + """; + assertCompact( + s, + """ + foo + foo + bar + bar"""); + assertSeparate( + s, + """ + foo + + foo + bar + + bar"""); assertStripped(s, "foo foo bar bar"); } @@ -166,32 +459,74 @@ public void textContentCodeBlock() { public void textContentBreaks() { String s; - s = "foo\nbar"; - assertCompact(s, "foo\nbar"); - assertSeparate(s, "foo\nbar"); + s = + """ + foo + bar + """; + assertCompact( + s, + """ + foo + bar"""); + assertSeparate( + s, + """ + foo + bar"""); assertStripped(s, "foo bar"); - s = "foo \nbar"; - assertCompact(s, "foo\nbar"); - assertSeparate(s, "foo\nbar"); + s = + """ + foo \s + bar + """; + assertCompact( + s, + """ + foo + bar"""); + assertSeparate( + s, + """ + foo + bar"""); assertStripped(s, "foo bar"); - s = "foo\n___\nbar"; - assertCompact(s, "foo\n***\nbar"); - assertSeparate(s, "foo\n\n***\n\nbar"); + s = + """ + foo + ___ + bar + """; + assertCompact( + s, + """ + foo + *** + bar"""); + assertSeparate( + s, + """ + foo + + *** + + bar"""); assertStripped(s, "foo bar"); } @Test public void textContentHtml() { String html = - "\n" - + " \n" - + " \n" - + " \n" - + "
      \n" - + " foobar\n" - + "
      "; + """ + + + + +
      + foobar +
      """; assertCompact(html, html); assertSeparate(html, html); @@ -201,10 +536,18 @@ public void textContentHtml() { @Test public void testContentNestedLists() { - var s = "List:\n" + "1. 2) 3. \n" + "end"; + var s = + """ + List: + 1. 2) 3.\s + end"""; assertCompact(s, s); - var s2 = "1. A\n 1) B\n 1. Test"; + var s2 = + """ + 1. A + 1) B + 1. Test"""; assertCompact(s2, s2); } diff --git a/pom.xml b/pom.xml index 359a85143..1556a92ae 100644 --- a/pom.xml +++ b/pom.xml @@ -43,6 +43,7 @@ 3.14.0 11 + 17