1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.jsieve.comparator;
21
22 import junit.framework.TestCase;
23
24 import org.apache.jsieve.comparators.ComparatorUtils;
25 import org.apache.jsieve.exception.SievePatternException;
26
27 public class ComparatorUtilsTest extends TestCase {
28
29 public void testMatchesStringString() throws SievePatternException {
30 String sievematch = "[test] ?\\\\?\\?*\\\\*\\*\\";
31 assertTrue(ComparatorUtils.matches("[test] a\\x?foo\\bar*\\",
32 sievematch));
33 assertFalse(ComparatorUtils.matches("[test] ab\\x?foo\\bar*\\",
34 sievematch));
35 assertFalse(ComparatorUtils.matches("[test]a\\x?foo\\bar*\\",
36 sievematch));
37 assertFalse(ComparatorUtils.matches("[tst] a\\x?foo\\bar*\\",
38 sievematch));
39 assertFalse(ComparatorUtils.matches("[test] a\\\\x?foo\\bar*\\",
40 sievematch));
41 assertFalse(ComparatorUtils.matches("[test] a\\?foo\\bar*\\",
42 sievematch));
43 assertFalse(ComparatorUtils.matches("[test] a\\xafoo\\bar*\\",
44 sievematch));
45 assertTrue(ComparatorUtils.matches("[test] a\\x?\\bar*\\", sievematch));
46 assertTrue(ComparatorUtils.matches("[test] a\\x?foo\\\\bar*\\",
47 sievematch));
48 assertFalse(ComparatorUtils
49 .matches("[test] a\\x?foobar*\\", sievematch));
50 assertFalse(ComparatorUtils.matches("[test] a\\x?foo\\bar.\\",
51 sievematch));
52 assertFalse(ComparatorUtils.matches("[test] a\\x?foo\\bar*\\\\",
53 sievematch));
54 assertFalse(ComparatorUtils
55 .matches("[test] a\\x?foo\\bar*", sievematch));
56 }
57
58
59
60
61
62
63
64
65
66
67 public void testSieveToJavaRegex() {
68 String sievematch = "[test] ?\\\\?\\?*\\\\*\\*\\";
69 String res = ComparatorUtils.sieveToJavaRegex(sievematch);
70 String expected = "\\[test\\] .\\\\.\\?.*\\\\.*\\*\\\\";
71 assertEquals(expected, res);
72 }
73
74 }