diff options
author | Freddy Mallet <freddy.mallet@gmail.com> | 2011-04-26 16:21:59 +0200 |
---|---|---|
committer | Freddy Mallet <freddy.mallet@gmail.com> | 2011-04-26 16:21:59 +0200 |
commit | cb7d0ffc0a45a23674064a956414763372dba86d (patch) | |
tree | 249f5d1b19fc8318db077da628c67b23d77ef4ea /sonar-channel | |
parent | 43888ce6c210e5502bf8bb52e5762906aa50c70c (diff) | |
download | sonarqube-cb7d0ffc0a45a23674064a956414763372dba86d.tar.gz sonarqube-cb7d0ffc0a45a23674064a956414763372dba86d.zip |
SONAR-2384 Fix a bug on HtmlListChannel which was due to CodeBuffer.length() method and make the HtmlEmphasisChannel handle sentence
Diffstat (limited to 'sonar-channel')
-rw-r--r-- | sonar-channel/src/main/java/org/sonar/channel/CodeBuffer.java | 6 | ||||
-rw-r--r-- | sonar-channel/src/test/java/org/sonar/channel/CodeBufferTest.java | 11 |
2 files changed, 13 insertions, 4 deletions
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 |