1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.jsieve.parser;
20
21 import java.util.List;
22
23 import junit.framework.TestCase;
24
25 import org.apache.jsieve.utils.JUnitUtils;
26
27 public class SieveNodeCommentTest extends TestCase {
28
29 protected void setUp() throws Exception {
30 super.setUp();
31 }
32
33 protected void tearDown() throws Exception {
34 super.tearDown();
35 }
36
37 public void testGetNoCommentsBefore() throws Exception {
38 SieveNode node = (SieveNode) JUnitUtils.parse("if address :contains [\"To\", \"From\"] \"Fish!\"{ }");
39 List comments = node.getPrecedingComments();
40 assertNotNull(comments);
41 assertEquals(0, comments.size());
42 }
43
44 public void testGetBracketCommentsBefore() throws Exception {
45 SieveNode node = (SieveNode) JUnitUtils.parse("/* A Comment *//* Another comment */if address :contains [\"To\", \"From\"] \"Fish!\"{ }");
46 List comments = node.getPrecedingComments();
47 assertNotNull(comments);
48 assertEquals(2, comments.size());
49 assertEquals(" A Comment ", comments.get(0));
50 assertEquals(" Another comment ", comments.get(1));
51 }
52
53 public void testGetHashCommentsBefore() throws Exception {
54 SieveNode node = (SieveNode) JUnitUtils.parse("/* A Comment */#A Line Comment\nif address :contains [\"To\", \"From\"] \"Fish!\"{ }");
55 List comments = node.getPrecedingComments();
56 assertNotNull(comments);
57 assertEquals(2, comments.size());
58 assertEquals(" A Comment ", comments.get(0));
59 assertEquals("A Line Comment", comments.get(1));
60 }
61
62 public void testGetHashCommentsBeforeCRLF() throws Exception {
63 SieveNode node = (SieveNode) JUnitUtils.parse("/* A Comment */#A Line Comment\r\nif address :contains [\"To\", \"From\"] \"Fish!\"{ }");
64 List comments = node.getPrecedingComments();
65 assertNotNull(comments);
66 assertEquals(2, comments.size());
67 assertEquals(" A Comment ", comments.get(0));
68 assertEquals("A Line Comment", comments.get(1));
69 }
70
71
72 public void testGetLastCommentNoneBefore() throws Exception {
73 SieveNode node = (SieveNode) JUnitUtils.parse("if address :contains [\"To\", \"From\"] \"Fish!\"{ }");
74 assertNull(node.getLastComment());
75 }
76
77 public void testGetBracketLastCommentBefore() throws Exception {
78 SieveNode node = (SieveNode) JUnitUtils.parse("/* A Comment *//* Another comment */if address :contains [\"To\", \"From\"] \"Fish!\"{ }");
79 assertEquals(" Another comment ", node.getLastComment());
80 }
81
82 public void testGetHashLastCommentBefore() throws Exception {
83 SieveNode node = (SieveNode) JUnitUtils.parse("/* A Comment */#A Line Comment\nif address :contains [\"To\", \"From\"] \"Fish!\"{ }");
84 assertEquals("A Line Comment", node.getLastComment());
85 }
86
87 public void testGetHashLastCommentBeforeCRLF() throws Exception {
88 SieveNode node = (SieveNode) JUnitUtils.parse("/* A Comment */#A Line Comment\r\nif address :contains [\"To\", \"From\"] \"Fish!\"{ }");;
89 assertEquals("A Line Comment", node.getLastComment());
90 }
91 }