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
44 package org.eclipse.jgit.dircache;
45
46 import static org.junit.Assert.assertEquals;
47 import static org.junit.Assert.assertNotNull;
48 import static org.junit.Assert.assertSame;
49
50 import org.eclipse.jgit.junit.RepositoryTestCase;
51 import org.eclipse.jgit.lib.FileMode;
52 import org.junit.Test;
53
54 public class DirCacheFindTest extends RepositoryTestCase {
55 @Test
56 public void testEntriesWithin() throws Exception {
57 final DirCache dc = db.readDirCache();
58
59 final String[] paths = { "a-", "a/b", "a/c", "a/d", "a0b" };
60 final DirCacheEntry[] ents = new DirCacheEntry[paths.length];
61 for (int i = 0; i < paths.length; i++) {
62 ents[i] = new DirCacheEntry(paths[i]);
63 ents[i].setFileMode(FileMode.REGULAR_FILE);
64 }
65 final int aFirst = 1;
66 final int aLast = 3;
67
68 final DirCacheBuilder b = dc.builder();
69 for (int i = 0; i < ents.length; i++)
70 b.add(ents[i]);
71 b.finish();
72
73 assertEquals(paths.length, dc.getEntryCount());
74 for (int i = 0; i < ents.length; i++)
75 assertSame(ents[i], dc.getEntry(i));
76
77 {
78 final DirCacheEntry[] aContents = dc.getEntriesWithin("a");
79 assertNotNull(aContents);
80 assertEquals(aLast - aFirst + 1, aContents.length);
81 for (int i = aFirst, j = 0; i <= aLast; i++, j++)
82 assertSame(ents[i], aContents[j]);
83 }
84 {
85 final DirCacheEntry[] aContents = dc.getEntriesWithin("a/");
86 assertNotNull(aContents);
87 assertEquals(aLast - aFirst + 1, aContents.length);
88 for (int i = aFirst, j = 0; i <= aLast; i++, j++)
89 assertSame(ents[i], aContents[j]);
90 }
91 {
92 final DirCacheEntry[] aContents = dc.getEntriesWithin("");
93 assertNotNull(aContents);
94 assertEquals(ents.length, aContents.length);
95 for (int i = 0; i < ents.length; i++)
96 assertSame(ents[i], aContents[i]);
97 }
98
99 assertNotNull(dc.getEntriesWithin("a-"));
100 assertEquals(0, dc.getEntriesWithin("a-").length);
101
102 assertNotNull(dc.getEntriesWithin("a0b"));
103 assertEquals(0, dc.getEntriesWithin("a0b-").length);
104
105 assertNotNull(dc.getEntriesWithin("zoo"));
106 assertEquals(0, dc.getEntriesWithin("zoo-").length);
107 }
108 }