[logback-dev] svn commit: r1007 - in logback/trunk/logback-core/src: main/java/ch/qos/logback/core/boolex test/java/ch/qos/logback/core/boolex
noreply.seb at qos.ch
noreply.seb at qos.ch
Mon Nov 27 20:24:39 CET 2006
Author: seb
Date: Mon Nov 27 20:24:38 2006
New Revision: 1007
Added:
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/boolex/
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/boolex/MatcherTest.java
Modified:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/boolex/Matcher.java
Log:
Modified the Matcher to use the find() method instead of the matches() method.
Added a test case verifying its behaviour
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/boolex/Matcher.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/boolex/Matcher.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/boolex/Matcher.java Mon Nov 27 20:24:38 2006
@@ -42,6 +42,7 @@
code |= Pattern.UNICODE_CASE;
}
+ //code |= Pattern.DOTALL;
pattern = Pattern.compile(regex, code);
start = true;
@@ -71,7 +72,7 @@
public boolean matches(String input) throws EvaluationException {
if(start) {
java.util.regex.Matcher matcher = pattern.matcher(input);
- return matcher.matches();
+ return matcher.find();
} else {
throw new EvaluationException("Matcher ["+regex+"] not started");
}
Added: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/boolex/MatcherTest.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/boolex/MatcherTest.java Mon Nov 27 20:24:38 2006
@@ -0,0 +1,64 @@
+package ch.qos.logback.core.boolex;
+
+import junit.framework.TestCase;
+import ch.qos.logback.core.Context;
+import ch.qos.logback.core.ContextBase;
+
+public class MatcherTest extends TestCase {
+
+ Context context;
+ Matcher matcher;
+
+ public void setUp() throws Exception {
+ context = new ContextBase();
+ matcher = new Matcher();
+ matcher.setContext(context);
+ matcher.setName("testMatcher");
+ super.setUp();
+ }
+
+ public void tearDown() throws Exception {
+ matcher = null;
+ super.tearDown();
+ }
+
+ public void testFullRegion() throws Exception {
+ matcher.setRegex(".*test.*");
+ matcher.start();
+ assertTrue(matcher.matches("test"));
+ assertTrue(matcher.matches("xxxxtest"));
+ assertTrue(matcher.matches("testxxxx"));
+ assertTrue(matcher.matches("xxxxtestxxxx"));
+ }
+
+ public void testPartRegion() throws Exception {
+ matcher.setRegex("test");
+ matcher.start();
+ assertTrue(matcher.matches("test"));
+ assertTrue(matcher.matches("xxxxtest"));
+ assertTrue(matcher.matches("testxxxx"));
+ assertTrue(matcher.matches("xxxxtestxxxx"));
+ }
+
+ public void testCaseInsensitive() throws Exception {
+ matcher.setRegex("test");
+ matcher.setCaseSensitive(false);
+ matcher.start();
+
+ assertTrue(matcher.matches("TEST"));
+ assertTrue(matcher.matches("tEst"));
+ assertTrue(matcher.matches("tESt"));
+ assertTrue(matcher.matches("TesT"));
+ }
+
+ public void testCaseSensitive() throws Exception {
+ matcher.setRegex("test");
+ matcher.setCaseSensitive(true);
+ matcher.start();
+
+ assertFalse(matcher.matches("TEST"));
+ assertFalse(matcher.matches("tEst"));
+ assertFalse(matcher.matches("tESt"));
+ assertFalse(matcher.matches("TesT"));
+ }
+}
More information about the logback-dev
mailing list