From 0b9c56c76952cc93dea74b386938154158f407dd Mon Sep 17 00:00:00 2001 From: Dinesh Bolkensteyn Date: Thu, 20 Oct 2011 20:50:42 +0200 Subject: SONAR-2923 and SONAR-2632: Remove sonar-channel buffer restriction and character pushback feature --- .../java/org/sonar/channel/CodeBufferTest.java | 22 ---------------------- .../java/org/sonar/channel/CodeReaderTest.java | 18 ------------------ .../java/org/sonar/channel/RegexChannelTest.java | 21 +++++++++++++++++++++ 3 files changed, 21 insertions(+), 40 deletions(-) (limited to 'sonar-channel/src/test') 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 @@ -116,20 +116,6 @@ public class CodeBufferTest { assertEquals('6', reader.charAt(5)); } - @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); @@ -209,14 +195,6 @@ public class CodeBufferTest { assertThat(codeBuffer.length(), is(4)); } - @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(); 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 @@ -83,24 +83,6 @@ public class CodeReaderTest { assertThat(previousCursor.getLine(), is(1)); } - @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")); 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("my word")); } + + @Test + public void shouldMatchTokenLongerThanBuffer() { + ChannelDispatcher dispatcher = ChannelDispatcher.builder().addChannel(new MyLiteralChannel()).build(); + StringBuilder output = new StringBuilder(); + + dispatcher.consume(new CodeReader("\"bonjour\""), output); + assertThat(output.toString(), is("\"bonjour\"")); + } + + private static class MyLiteralChannel extends RegexChannel { + + public MyLiteralChannel() { + super("\"[^\"]*+\""); + } + @Override + protected void consume(CharSequence token, StringBuilder output) { + output.append("" + token + ""); + } + } + private static class MyWordChannel extends RegexChannel { public MyWordChannel() { -- cgit v1.2.3