1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 package org.eclipse.jgit.ignore;
44
45 import static org.junit.Assert.assertEquals;
46 import static org.junit.Assert.assertFalse;
47 import static org.junit.Assert.assertNotEquals;
48 import static org.junit.Assert.assertTrue;
49
50 import org.eclipse.jgit.ignore.internal.Strings;
51 import org.junit.Test;
52
53 public class BasicRuleTest {
54
55 @Test
56 public void test() {
57 FastIgnoreRule rule1 = new FastIgnoreRule("/hello/[a]/");
58 FastIgnoreRule rule2 = new FastIgnoreRule("/hello/[a]/");
59 FastIgnoreRule rule3 = new FastIgnoreRule("!/hello/[a]/");
60 FastIgnoreRule rule4 = new FastIgnoreRule("/hello/[a]");
61 assertTrue(rule1.dirOnly());
62 assertTrue(rule3.dirOnly());
63 assertFalse(rule4.dirOnly());
64 assertFalse(rule1.getNegation());
65 assertTrue(rule3.getNegation());
66 assertNotEquals(rule1, null);
67 assertEquals(rule1, rule1);
68 assertEquals(rule1, rule2);
69 assertNotEquals(rule1, rule3);
70 assertNotEquals(rule1, rule4);
71 assertEquals(rule1.hashCode(), rule2.hashCode());
72 assertNotEquals(rule1.hashCode(), rule3.hashCode());
73 assertEquals(rule1.toString(), rule2.toString());
74 assertNotEquals(rule1.toString(), rule3.toString());
75 }
76
77 @Test
78 public void testDirectoryPattern() {
79 assertTrue(Strings.isDirectoryPattern("/"));
80 assertTrue(Strings.isDirectoryPattern("/ "));
81 assertTrue(Strings.isDirectoryPattern("/ "));
82 assertFalse(Strings.isDirectoryPattern(" "));
83 assertFalse(Strings.isDirectoryPattern(""));
84 }
85
86 @Test
87 public void testStripTrailingChar() {
88 assertEquals("", Strings.stripTrailing("/", '/'));
89 assertEquals("", Strings.stripTrailing("///", '/'));
90 assertEquals("a", Strings.stripTrailing("a/", '/'));
91 assertEquals("a", Strings.stripTrailing("a///", '/'));
92 assertEquals("a/ ", Strings.stripTrailing("a/ ", '/'));
93 }
94
95 @Test
96 public void testStripTrailingWhitespace() {
97 assertEquals("", Strings.stripTrailingWhitespace(""));
98 assertEquals("", Strings.stripTrailingWhitespace(" "));
99 assertEquals("a", Strings.stripTrailingWhitespace("a"));
100 assertEquals("a", Strings.stripTrailingWhitespace("a "));
101 assertEquals("a", Strings.stripTrailingWhitespace("a "));
102 assertEquals("a", Strings.stripTrailingWhitespace("a \t"));
103 }
104 }