From: Freddy Mallet Date: Tue, 26 Apr 2011 14:21:59 +0000 (+0200) Subject: SONAR-2384 Fix a bug on HtmlListChannel which was due to CodeBuffer.length() method... X-Git-Tag: 2.8~125 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=cb7d0ffc0a45a23674064a956414763372dba86d;p=sonarqube.git SONAR-2384 Fix a bug on HtmlListChannel which was due to CodeBuffer.length() method and make the HtmlEmphasisChannel handle sentence --- diff --git a/sonar-channel/src/main/java/org/sonar/channel/CodeBuffer.java b/sonar-channel/src/main/java/org/sonar/channel/CodeBuffer.java index 2358e0bfa44..50359838d72 100644 --- a/sonar-channel/src/main/java/org/sonar/channel/CodeBuffer.java +++ b/sonar-channel/src/main/java/org/sonar/channel/CodeBuffer.java @@ -240,14 +240,14 @@ public class CodeBuffer implements CharSequence { } /** - * Warning : this method always returns Integer.MAX_VALUE as the length of the stream can't be known before having consumed all - * characters. + * Warning : this method returns Integer.MAX_VALUE when the buffer is fully used + * as the length of the stream can't be known before having consumed all characters. * * Integer.MAX_VALUE is returned to prevent regular expression matchers to stop consuming the stream of characters (see * http://jira.codehaus.org/browse/SONAR-2010) */ public final int length() { - return (bufferSize == bufferCapacity ? Integer.MAX_VALUE : bufferSize); + return (bufferSize == bufferCapacity ? Integer.MAX_VALUE : bufferSize - bufferPosition); } public final CharSequence subSequence(int start, int end) { diff --git a/sonar-channel/src/test/java/org/sonar/channel/CodeBufferTest.java b/sonar-channel/src/test/java/org/sonar/channel/CodeBufferTest.java index e5befb2efcb..471b16bd975 100644 --- a/sonar-channel/src/test/java/org/sonar/channel/CodeBufferTest.java +++ b/sonar-channel/src/test/java/org/sonar/channel/CodeBufferTest.java @@ -197,7 +197,16 @@ public class CodeBufferTest { @Test public void theLengthShouldBeTheSameThanTheStringLength() { String myCode = "myCode"; - assertThat(new CodeBuffer(myCode, new CodeReaderConfiguration()).length(), is(myCode.length())); + assertThat(new CodeBuffer(myCode, new CodeReaderConfiguration()).length(), is(6)); + } + + @Test + public void theLengthShouldDecreaseEachTimeTheInputStreamIsConsumed() { + String myCode = "myCode"; + CodeBuffer codeBuffer = new CodeBuffer(myCode, new CodeReaderConfiguration()); + codeBuffer.pop(); + codeBuffer.pop(); + assertThat(codeBuffer.length(), is(4)); } @Test diff --git a/sonar-markdown/src/main/java/org/sonar/markdown/HtmlEmphasisChannel.java b/sonar-markdown/src/main/java/org/sonar/markdown/HtmlEmphasisChannel.java index 392a37aa345..d59b3f3adb2 100644 --- a/sonar-markdown/src/main/java/org/sonar/markdown/HtmlEmphasisChannel.java +++ b/sonar-markdown/src/main/java/org/sonar/markdown/HtmlEmphasisChannel.java @@ -29,7 +29,7 @@ import org.sonar.channel.RegexChannel; class HtmlEmphasisChannel extends RegexChannel { public HtmlEmphasisChannel() { - super("\\*[^\n\r\\*\\s]++\\*"); + super("\\*[^\\s\\*][^\n\r]+?[^\\s\\*]\\*"); } @Override diff --git a/sonar-markdown/src/test/java/org/sonar/markdown/MarkdownEngineTest.java b/sonar-markdown/src/test/java/org/sonar/markdown/MarkdownEngineTest.java index 9579828af9b..cf4a0f1b726 100644 --- a/sonar-markdown/src/test/java/org/sonar/markdown/MarkdownEngineTest.java +++ b/sonar-markdown/src/test/java/org/sonar/markdown/MarkdownEngineTest.java @@ -39,6 +39,7 @@ public class MarkdownEngineTest { @Test public void shouldDecorateList() { assertThat(MarkdownEngine.convertToHtml(" * one\r* two\r\n* three\n * \n *five"), is(" *five")); + assertThat(MarkdownEngine.convertToHtml(" * one\r* two"), is("")); } @Test @@ -56,10 +57,7 @@ public class MarkdownEngineTest { assertThat(MarkdownEngine.convertToHtml("Not *emphase * because of whitespace"), is("Not *emphase * because of whitespace")); assertThat(MarkdownEngine.convertToHtml("Not * emphase* because of whitespace"), is("Not * emphase* because of whitespace")); assertThat(MarkdownEngine.convertToHtml("emphase*inside*word"), is("emphaseinsideword")); - - // not supported yet - // assertThat(MarkdownEngine.convertToHtml("\\*surrounded by literal asterisks\\*"), is("\\*surrounded by literal asterisks\\*")); - + assertThat(MarkdownEngine.convertToHtml("*Emphase many words*"), is("Emphase many words")); } @Test