]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2384 Fix a bug on HtmlListChannel which was due to CodeBuffer.length() method...
authorFreddy Mallet <freddy.mallet@gmail.com>
Tue, 26 Apr 2011 14:21:59 +0000 (16:21 +0200)
committerFreddy Mallet <freddy.mallet@gmail.com>
Tue, 26 Apr 2011 14:21:59 +0000 (16:21 +0200)
sonar-channel/src/main/java/org/sonar/channel/CodeBuffer.java
sonar-channel/src/test/java/org/sonar/channel/CodeBufferTest.java
sonar-markdown/src/main/java/org/sonar/markdown/HtmlEmphasisChannel.java
sonar-markdown/src/test/java/org/sonar/markdown/MarkdownEngineTest.java

index 2358e0bfa4457a60ced2dce097505a29442f7016..50359838d72a5f42df576dd6bf9d5bb200e604a5 100644 (file)
@@ -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) {
index e5befb2efcb56b2d3737def7305feb66f21e0981..471b16bd97545d0e665f6b776695aa37b1d11037 100644 (file)
@@ -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
index 392a37aa345818414c4a1d0bf9be79a3bc145a4a..d59b3f3adb2f9e23a8592e989c822d28b485446a 100644 (file)
@@ -29,7 +29,7 @@ import org.sonar.channel.RegexChannel;
 class HtmlEmphasisChannel extends RegexChannel<MarkdownOutput> {
 
   public HtmlEmphasisChannel() {
-    super("\\*[^\n\r\\*\\s]++\\*");
+    super("\\*[^\\s\\*][^\n\r]+?[^\\s\\*]\\*");
   }
 
   @Override
index 9579828af9bcfe5bcfdd3afe4e79841cbbcb7342..cf4a0f1b726a63526187ad45736fc5b2977995d7 100644 (file)
@@ -39,6 +39,7 @@ public class MarkdownEngineTest {
   @Test
   public void shouldDecorateList() {
     assertThat(MarkdownEngine.convertToHtml("  * one\r* two\r\n* three\n * \n *five"), is("<ul><li>one</li>\r<li>two</li>\r\n<li>three</li>\n<li> </li>\n</ul> *five"));
+    assertThat(MarkdownEngine.convertToHtml("  * one\r* two"), is("<ul><li>one</li>\r<li>two</li></ul>"));
   }
 
   @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("emphase<em>inside</em>word"));
-
-    // not supported yet
-    // assertThat(MarkdownEngine.convertToHtml("\\*surrounded by literal asterisks\\*"), is("\\*surrounded by literal asterisks\\*"));
-
+    assertThat(MarkdownEngine.convertToHtml("*Emphase many words*"), is("<em>Emphase many words</em>"));
   }
 
   @Test