1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.jsieve.comparators;
20
21 import junit.framework.TestCase;
22
23 import org.apache.jsieve.exception.FeatureException;
24 import org.apache.jsieve.parser.generated.ParseException;
25 import org.apache.jsieve.utils.JUnitUtils;
26
27 public class AsciiNumericTest extends TestCase {
28
29 AsciiNumeric subject;
30
31 protected void setUp() throws Exception {
32 super.setUp();
33 subject = new AsciiNumeric();
34 }
35
36 protected void tearDown() throws Exception {
37 super.tearDown();
38 }
39
40 public void testVerificationFailsWhenAsciiNumericIsNotRequired() throws Exception {
41 String script = "if header :contains :comparator \"i;ascii-numeric\" \"Subject\" \"69\" {stop;}";
42 try {
43 JUnitUtils.interpret(JUnitUtils.createMail(), script);
44 fail("Comparator must be declared in require statement");
45 } catch (ParseException e) {
46
47 }
48 }
49
50 public void testVerificationPassesWhenAsciiNumericIsRequired() throws Exception {
51 String script = "require [\"comparator-i;ascii-numeric\"]; if header :is :comparator \"i;ascii-numeric\" \"Subject\" \"69\" {stop;}";
52 JUnitUtils.interpret(JUnitUtils.createMail(), script);
53 }
54
55 public void testBasicNumbericEquality() throws Exception {
56 assertFalse(subject.equals("1", "2"));
57 assertTrue(subject.equals("1", "1"));
58 }
59
60 public void testEqualityShouldIgnoreTrailingCharacters() throws Exception {
61 assertTrue(subject.equals("01", "1A"));
62 assertTrue(subject.equals("1", "00000000000000001A"));
63 assertTrue(subject.equals("234S", "234YTGSDBBSD"));
64 }
65
66 public void testEqualityShouldIgnoreLeadingZeros() throws Exception {
67 assertTrue(subject.equals("01", "1"));
68 assertTrue(subject.equals("000001", "1"));
69 assertFalse(subject.equals("000001", "10"));
70 }
71
72 public void testStingsThatDoNotStartWithADigitRepresentPositiveInfinityWhenUsedInEquality() throws Exception {
73 assertFalse(subject.equals("1", "A4"));
74 assertFalse(subject.equals("x", "4"));
75 assertTrue(subject.equals("GT", "A4"));
76 }
77
78 public void testSubstringIsNotSupported() throws Exception {
79 try {
80 subject.contains("234234", "34");
81 fail("Substring is unsupported");
82 } catch (FeatureException e) {
83
84 }
85 }
86
87 public void testMatchNotSupported() throws Exception {
88 try {
89 subject.matches("234234", "34");
90 fail("Substring is unsupported");
91 } catch (FeatureException e) {
92
93 }
94 }
95 }