1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.ignore;
11
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertFalse;
14 import static org.junit.Assert.assertNotEquals;
15 import static org.junit.Assert.assertTrue;
16
17 import org.eclipse.jgit.ignore.internal.Strings;
18 import org.junit.Test;
19
20 public class BasicRuleTest {
21
22 @Test
23 public void test() {
24 FastIgnoreRule rule1 = new FastIgnoreRule("/hello/[a]/");
25 FastIgnoreRule rule2 = new FastIgnoreRule("/hello/[a]/");
26 FastIgnoreRule rule3 = new FastIgnoreRule("!/hello/[a]/");
27 FastIgnoreRule rule4 = new FastIgnoreRule("/hello/[a]");
28 assertTrue(rule1.dirOnly());
29 assertTrue(rule3.dirOnly());
30 assertFalse(rule4.dirOnly());
31 assertFalse(rule1.getNegation());
32 assertTrue(rule3.getNegation());
33 assertNotEquals(rule1, null);
34 assertEquals(rule1, rule1);
35 assertEquals(rule1, rule2);
36 assertNotEquals(rule1, rule3);
37 assertNotEquals(rule1, rule4);
38 assertEquals(rule1.hashCode(), rule2.hashCode());
39 assertNotEquals(rule1.hashCode(), rule3.hashCode());
40 assertEquals(rule1.toString(), rule2.toString());
41 assertNotEquals(rule1.toString(), rule3.toString());
42 }
43
44 @Test
45 public void testDirectoryPattern() {
46 assertTrue(Strings.isDirectoryPattern("/"));
47 assertTrue(Strings.isDirectoryPattern("/ "));
48 assertTrue(Strings.isDirectoryPattern("/ "));
49 assertFalse(Strings.isDirectoryPattern(" "));
50 assertFalse(Strings.isDirectoryPattern(""));
51 }
52
53 @Test
54 public void testStripTrailingChar() {
55 assertEquals("", Strings.stripTrailing("/", '/'));
56 assertEquals("", Strings.stripTrailing("///", '/'));
57 assertEquals("a", Strings.stripTrailing("a/", '/'));
58 assertEquals("a", Strings.stripTrailing("a///", '/'));
59 assertEquals("a/ ", Strings.stripTrailing("a/ ", '/'));
60 }
61
62 @Test
63 public void testStripTrailingWhitespace() {
64 assertEquals("", Strings.stripTrailingWhitespace(""));
65 assertEquals("", Strings.stripTrailingWhitespace(" "));
66 assertEquals("a", Strings.stripTrailingWhitespace("a"));
67 assertEquals("a", Strings.stripTrailingWhitespace("a "));
68 assertEquals("a", Strings.stripTrailingWhitespace("a "));
69 assertEquals("a", Strings.stripTrailingWhitespace("a \t"));
70 }
71 }