You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ba...@apache.org on 2008/05/11 23:07:02 UTC
svn commit: r655373 - in
/james/jsieve/trunk/src/test/java/org/apache/jsieve/junit: HeaderTest.java
comparator/ comparator/ComparatorUtilsTest.java
Author: bago
Date: Sun May 11 14:07:01 2008
New Revision: 655373
URL: http://svn.apache.org/viewvc?rev=655373&view=rev
Log:
Few tests for the new :matches sieve to java regex comparator.
Added:
james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/comparator/
james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/comparator/ComparatorUtilsTest.java (with props)
Modified:
james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/HeaderTest.java
Modified: james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/HeaderTest.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/HeaderTest.java?rev=655373&r1=655372&r2=655373&view=diff
==============================================================================
--- james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/HeaderTest.java (original)
+++ james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/HeaderTest.java Sun May 11 14:07:01 2008
@@ -339,7 +339,7 @@
*/
public void testSquareBracketsInMatch() {
boolean isTestPassed = false;
- String script = "if header :matches \"X-Caffeine\" \"[test]*\" {throwTestException;}";
+ String script = "if header :matches \"X-Caffeine\" \"[test*\" {throwTestException;}";
try {
SieveMailAdapter mail = (SieveMailAdapter) JUnitUtils.createMail();
mail.getMessage().addHeader("X-Caffeine", "[test] my subject");
Added: james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/comparator/ComparatorUtilsTest.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/comparator/ComparatorUtilsTest.java?rev=655373&view=auto
==============================================================================
--- james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/comparator/ComparatorUtilsTest.java (added)
+++ james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/comparator/ComparatorUtilsTest.java Sun May 11 14:07:01 2008
@@ -0,0 +1,75 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.jsieve.junit.comparator;
+
+import org.apache.jsieve.comparators.ComparatorUtils;
+import org.apache.jsieve.exception.SievePatternException;
+
+import junit.framework.TestCase;
+
+public class ComparatorUtilsTest extends TestCase {
+
+ public void testMatchesStringString() throws SievePatternException {
+ String sievematch = "[test] ?\\\\?\\?*\\\\*\\*\\";
+ assertTrue(ComparatorUtils.matches("[test] a\\x?foo\\bar*\\",
+ sievematch));
+ assertFalse(ComparatorUtils.matches("[test] ab\\x?foo\\bar*\\",
+ sievematch));
+ assertFalse(ComparatorUtils.matches("[test]a\\x?foo\\bar*\\",
+ sievematch));
+ assertFalse(ComparatorUtils.matches("[tst] a\\x?foo\\bar*\\",
+ sievematch));
+ assertFalse(ComparatorUtils.matches("[test] a\\\\x?foo\\bar*\\",
+ sievematch));
+ assertFalse(ComparatorUtils.matches("[test] a\\?foo\\bar*\\",
+ sievematch));
+ assertFalse(ComparatorUtils.matches("[test] a\\xafoo\\bar*\\",
+ sievematch));
+ assertTrue(ComparatorUtils.matches("[test] a\\x?\\bar*\\",
+ sievematch));
+ assertTrue(ComparatorUtils.matches("[test] a\\x?foo\\\\bar*\\",
+ sievematch));
+ assertFalse(ComparatorUtils.matches("[test] a\\x?foobar*\\",
+ sievematch));
+ assertFalse(ComparatorUtils.matches("[test] a\\x?foo\\bar.\\",
+ sievematch));
+ assertFalse(ComparatorUtils.matches("[test] a\\x?foo\\bar*\\\\",
+ sievematch));
+ assertFalse(ComparatorUtils.matches("[test] a\\x?foo\\bar*",
+ sievematch));
+ }
+
+ /**
+ * The ":matches" version specifies a wildcard match using the characters
+ * "*" and "?". "*" matches zero or more characters, and "?" matches a
+ * single character. "?" and "*" may be escaped as "\\?" and "\\*" in
+ * strings to match against themselves. The first backslash escapes the
+ * second backslash; together, they escape the "*". This is awkward, but it
+ * is commonplace in several programming languages that use globs and
+ * regular expressions.
+ */
+ public void testSieveToJavaRegex() {
+ String sievematch = "[test] ?\\\\?\\?*\\\\*\\*\\";
+ String res = ComparatorUtils.sieveToJavaRegex(sievematch);
+ String expected = "\\[test\\] .\\\\.\\?.*\\\\.*\\*\\\\";
+ assertEquals(expected, res);
+ }
+
+}
Propchange: james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/comparator/ComparatorUtilsTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/comparator/ComparatorUtilsTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org