diff options
Diffstat (limited to 'sonar-channel/src/test')
3 files changed, 21 insertions, 40 deletions
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 471b16bd975..387978fe069 100644 --- a/sonar-channel/src/test/java/org/sonar/channel/CodeBufferTest.java +++ b/sonar-channel/src/test/java/org/sonar/channel/CodeBufferTest.java @@ -117,20 +117,6 @@ public class CodeBufferTest { } @Test - public void testPush() { - CodeReader reader = new CodeReader("12", defaulConfiguration); - assertEquals('1', (char) reader.pop()); - reader.push("a"); - assertEquals('a', (char) reader.peek()); - reader.push("45"); - assertEquals("45a2", new String(reader.peek(4))); - for (int i = 0; i < 4; i++) { - reader.pop(); - } - assertEquals( -1, reader.pop()); - } - - @Test public void testCharAtIndexOutOfBoundsException() { CodeBuffer reader = new CodeBuffer("12345", defaulConfiguration); assertEquals(reader.charAt(5), (char) -1); @@ -210,14 +196,6 @@ public class CodeBufferTest { } @Test - public void theLengthShouldBeIntegerMaxValueWhenTheBufferCantContainAllCharacters() { - String myCode = "myCode"; - CodeReaderConfiguration conf = new CodeReaderConfiguration(); - conf.setBufferCapacity(2); - assertThat(new CodeBuffer(myCode, conf).length(), is(Integer.MAX_VALUE)); - } - - @Test public void testSeveralCodeReaderFilter() throws Exception { CodeReaderConfiguration configuration = new CodeReaderConfiguration(); configuration.setCodeReaderFilters(new ReplaceNumbersFilter(), new ReplaceCharFilter()); diff --git a/sonar-channel/src/test/java/org/sonar/channel/CodeReaderTest.java b/sonar-channel/src/test/java/org/sonar/channel/CodeReaderTest.java index a748cfa6f83..b6f1d0b8289 100644 --- a/sonar-channel/src/test/java/org/sonar/channel/CodeReaderTest.java +++ b/sonar-channel/src/test/java/org/sonar/channel/CodeReaderTest.java @@ -84,24 +84,6 @@ public class CodeReaderTest { } @Test - public void testPeekToAndReachingTheBufferLimit() { - CodeReaderConfiguration configuration = new CodeReaderConfiguration(); - configuration.setBufferCapacity(10); - CodeReader reader = new CodeReader("word1 word2 word2", configuration); - for (int i = 0; i < 6; i++) { - reader.pop(); - } - StringBuilder result = new StringBuilder(); - reader.peekTo(new EndMatcher() { - - public boolean match(int endFlag) { - return ' ' == (char) endFlag; - } - }, result); - assertEquals("word2", result.toString()); - } - - @Test public void testPopToWithRegex() { CodeReader reader = new CodeReader(new StringReader("123ABC")); StringBuilder token = new StringBuilder(); diff --git a/sonar-channel/src/test/java/org/sonar/channel/RegexChannelTest.java b/sonar-channel/src/test/java/org/sonar/channel/RegexChannelTest.java index 35d9c936b78..322899266ab 100644 --- a/sonar-channel/src/test/java/org/sonar/channel/RegexChannelTest.java +++ b/sonar-channel/src/test/java/org/sonar/channel/RegexChannelTest.java @@ -33,7 +33,28 @@ public class RegexChannelTest { dispatcher.consume(new CodeReader("my word"), output); assertThat(output.toString(), is("<w>my</w> <w>word</w>")); } + + @Test + public void shouldMatchTokenLongerThanBuffer() { + ChannelDispatcher<StringBuilder> dispatcher = ChannelDispatcher.builder().addChannel(new MyLiteralChannel()).build(); + StringBuilder output = new StringBuilder(); + + dispatcher.consume(new CodeReader("\"bonjour\""), output); + assertThat(output.toString(), is("<literal>\"bonjour\"</literal>")); + } + + private static class MyLiteralChannel extends RegexChannel<StringBuilder> { + + public MyLiteralChannel() { + super("\"[^\"]*+\""); + } + @Override + protected void consume(CharSequence token, StringBuilder output) { + output.append("<literal>" + token + "</literal>"); + } + } + private static class MyWordChannel extends RegexChannel<StringBuilder> { public MyWordChannel() { |