From 87197ece2c16cabfe863772eb2cb2bc641ecb0e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89amonn=20McManus?= Date: Thu, 30 Apr 2026 06:48:11 -0700 Subject: [PATCH] Add a test case to ensure that line wrapping doesn't split Markdown links. It would be wrong to introduce space, including a line break, between the `]` and the `(` of `[foo](bar)`. PiperOrigin-RevId: 908143630 --- .../java/JavadocFormattingTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/core/src/test/java/com/google/googlejavaformat/java/JavadocFormattingTest.java b/core/src/test/java/com/google/googlejavaformat/java/JavadocFormattingTest.java index 1e44c4394..b2332ee15 100644 --- a/core/src/test/java/com/google/googlejavaformat/java/JavadocFormattingTest.java +++ b/core/src/test/java/com/google/googlejavaformat/java/JavadocFormattingTest.java @@ -1831,6 +1831,25 @@ class Test {} doFormatTest(input, expected); } + @Test + public void markdownLinkWrapping() { + assume().that(MARKDOWN_JAVADOC_SUPPORTED).isTrue(); + String input = +""" +/// enough text to cause the following link to need to be wrapped [foo](http://very.long/url/that/will/need/to/be/wrapped) +class Test {} +"""; + // It would be wrong to wrap between the ] and the (, and fortunately we don't. + // https://spec.commonmark.org/0.31.2/#example-511 + String expected = +""" +/// enough text to cause the following link to need to be wrapped +/// [foo](http://very.long/url/that/will/need/to/be/wrapped) +class Test {} +"""; + doFormatTest(input, expected); + } + @Test public void markdownThematicBreaks() { assume().that(MARKDOWN_JAVADOC_SUPPORTED).isTrue();