diff options
author | Jean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com> | 2013-04-12 12:42:28 +0200 |
---|---|---|
committer | Jean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com> | 2013-04-12 12:42:28 +0200 |
commit | 0c2675c8ee069e2fbb9aac2bda88792a41b20ce3 (patch) | |
tree | 81bb755f70396a79c2f2189fcc634d2b53d81918 /sonar-core | |
parent | 19a8496f9cfa0aa861a09fbf6e4fded5cd6b80f4 (diff) | |
download | sonarqube-0c2675c8ee069e2fbb9aac2bda88792a41b20ce3.tar.gz sonarqube-0c2675c8ee069e2fbb9aac2bda88792a41b20ce3.zip |
SONAR-3893 Added CR EOL support
Diffstat (limited to 'sonar-core')
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/source/HtmlTextWrapper.java | 8 | ||||
-rw-r--r-- | sonar-core/src/test/java/org/sonar/core/source/HtmlTextWrapperTest.java | 26 |
2 files changed, 32 insertions, 2 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/source/HtmlTextWrapper.java b/sonar-core/src/main/java/org/sonar/core/source/HtmlTextWrapper.java index ec5c17df42f..27be01d67e6 100644 --- a/sonar-core/src/main/java/org/sonar/core/source/HtmlTextWrapper.java +++ b/sonar-core/src/main/java/org/sonar/core/source/HtmlTextWrapper.java @@ -134,11 +134,15 @@ public class HtmlTextWrapper { } private boolean shouldReopenPendingTags(CharactersReader charactersReader) { - return charactersReader.getPreviousValue() == LF_END_OF_LINE && charactersReader.getCurrentValue() != LF_END_OF_LINE; + return (charactersReader.getPreviousValue() == LF_END_OF_LINE && charactersReader.getCurrentValue() != LF_END_OF_LINE) + || (charactersReader.getPreviousValue() == CR_END_OF_LINE && charactersReader.getCurrentValue() != CR_END_OF_LINE + && charactersReader.getCurrentValue() != LF_END_OF_LINE + ); } private boolean shouldStartNewLine(CharactersReader charactersReader) { - return charactersReader.getPreviousValue() == LF_END_OF_LINE; + return charactersReader.getPreviousValue() == LF_END_OF_LINE + || (charactersReader.getPreviousValue() == CR_END_OF_LINE && charactersReader.getCurrentValue() != LF_END_OF_LINE); } private void closeCompletedTags(CharactersReader charactersReader, int numberOfTagsToClose, diff --git a/sonar-core/src/test/java/org/sonar/core/source/HtmlTextWrapperTest.java b/sonar-core/src/test/java/org/sonar/core/source/HtmlTextWrapperTest.java index e90680ef6c1..140132cf835 100644 --- a/sonar-core/src/test/java/org/sonar/core/source/HtmlTextWrapperTest.java +++ b/sonar-core/src/test/java/org/sonar/core/source/HtmlTextWrapperTest.java @@ -227,8 +227,34 @@ public class HtmlTextWrapperTest { "<span class=\"cppd\"> *</span>", "<span class=\"cppd\"> * @since 2.13</span>", "<span class=\"cppd\"> */</span>"); + } + + @Test + public void should_support_cr_line_breaks() throws Exception { + + String crCodeSample = + "/**" + CR_END_OF_LINE + + "* @return metric generated by the decorator" + CR_END_OF_LINE + + "*/" + CR_END_OF_LINE + + "@DependedUpon" + CR_END_OF_LINE + + "public Metric generatesMetric() {" + CR_END_OF_LINE + + " return metric;" + CR_END_OF_LINE + + "}" + CR_END_OF_LINE; + HighlightingContext context = HighlightingContext.buildFrom("0,50,cppd;51,64,a;65,71,k;101,107,k;"); + HtmlTextWrapper htmlTextWrapper = new HtmlTextWrapper(); + List<String> htmlOutput = htmlTextWrapper.wrapTextWithHtml(crCodeSample, context); + + assertThat(htmlOutput).containsExactly( + "<span class=\"cppd\">/**</span>", + "<span class=\"cppd\">* @return metric generated by the decorator</span>", + "<span class=\"cppd\">*/</span>", + "<span class=\"a\">@DependedUpon</span>", + "<span class=\"k\">public</span> Metric generatesMetric() {", + " <span class=\"k\">return</span> metric;", + "}" + ); } } |