}
/**
- * 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) {
@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
class HtmlEmphasisChannel extends RegexChannel<MarkdownOutput> {
public HtmlEmphasisChannel() {
- super("\\*[^\n\r\\*\\s]++\\*");
+ super("\\*[^\\s\\*][^\n\r]+?[^\\s\\*]\\*");
}
@Override
@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
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