aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-channel/src/test/java
diff options
context:
space:
mode:
authorFreddy Mallet <freddy.mallet@gmail.com>2011-04-23 00:47:42 +0200
committerFreddy Mallet <freddy.mallet@gmail.com>2011-04-23 00:47:42 +0200
commit591efdc554efe55cb0ab7f88e6d4c45b247987c3 (patch)
treea9cc0a95bc853488b2fb498d07f1506dce2a7a47 /sonar-channel/src/test/java
parent84159b5d85a0b99790ba8ea90e463076d541ed5c (diff)
downloadsonarqube-591efdc554efe55cb0ab7f88e6d4c45b247987c3.tar.gz
sonarqube-591efdc554efe55cb0ab7f88e6d4c45b247987c3.zip
SONAR-2384 First implementation : Create a markdown dedicated to Sonar needs
Diffstat (limited to 'sonar-channel/src/test/java')
-rw-r--r--sonar-channel/src/test/java/org/sonar/channel/RegexChannelTest.java58
1 files changed, 58 insertions, 0 deletions
diff --git a/sonar-channel/src/test/java/org/sonar/channel/RegexChannelTest.java b/sonar-channel/src/test/java/org/sonar/channel/RegexChannelTest.java
new file mode 100644
index 00000000000..7fb5c3a11ab
--- /dev/null
+++ b/sonar-channel/src/test/java/org/sonar/channel/RegexChannelTest.java
@@ -0,0 +1,58 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.channel;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+public class RegexChannelTest {
+
+ @Test
+ public void shouldMatch() {
+ ChannelDispatcher<StringBuilder> dispatcher = new ChannelDispatcher<StringBuilder>(new MyWordChannel(), new BlackholeChannel());
+ StringBuilder output = new StringBuilder();
+ dispatcher.consume(new CodeReader("my word"), output);
+ assertThat(output.toString(), is("<w>my</w> <w>word</w>"));
+ }
+
+ private class MyWordChannel extends RegexChannel<StringBuilder> {
+
+ public MyWordChannel() {
+ super("\\w++");
+ }
+
+ @Override
+ protected void consume(CharSequence token, StringBuilder output) {
+ output.append("<w>" + token + "</w>");
+ }
+ }
+
+ class BlackholeChannel extends Channel<StringBuilder> {
+
+ @Override
+ public boolean consume(CodeReader code, StringBuilder output) {
+ output.append((char) code.pop());
+ return true;
+ }
+ }
+
+}