Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

DirCacheBuilderIteratorTest.java 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (C) 2008, Google Inc. and others
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the Eclipse Distribution License v. 1.0 which is available at
  6. * https://www.eclipse.org/org/documents/edl-v10.php.
  7. *
  8. * SPDX-License-Identifier: BSD-3-Clause
  9. */
  10. package org.eclipse.jgit.dircache;
  11. import static org.junit.Assert.assertEquals;
  12. import static org.junit.Assert.assertFalse;
  13. import static org.junit.Assert.assertNotNull;
  14. import static org.junit.Assert.assertSame;
  15. import static org.junit.Assert.assertTrue;
  16. import java.util.Collections;
  17. import org.eclipse.jgit.junit.RepositoryTestCase;
  18. import org.eclipse.jgit.lib.FileMode;
  19. import org.eclipse.jgit.treewalk.TreeWalk;
  20. import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
  21. import org.junit.Test;
  22. public class DirCacheBuilderIteratorTest extends RepositoryTestCase {
  23. @Test
  24. public void testPathFilterGroup_DoesNotSkipTail() throws Exception {
  25. final DirCache dc = db.readDirCache();
  26. final FileMode mode = FileMode.REGULAR_FILE;
  27. final String[] paths = { "a-", "a/b", "a/c", "a/d", "a0b" };
  28. final DirCacheEntry[] ents = new DirCacheEntry[paths.length];
  29. for (int i = 0; i < paths.length; i++) {
  30. ents[i] = new DirCacheEntry(paths[i]);
  31. ents[i].setFileMode(mode);
  32. }
  33. {
  34. final DirCacheBuilder b = dc.builder();
  35. for (DirCacheEntry ent : ents) {
  36. b.add(ent);
  37. }
  38. b.finish();
  39. }
  40. final int expIdx = 2;
  41. final DirCacheBuilder b = dc.builder();
  42. try (TreeWalk tw = new TreeWalk(db)) {
  43. tw.addTree(new DirCacheBuildIterator(b));
  44. tw.setRecursive(true);
  45. tw.setFilter(PathFilterGroup.createFromStrings(Collections
  46. .singleton(paths[expIdx])));
  47. assertTrue("found " + paths[expIdx], tw.next());
  48. final DirCacheIterator c = tw.getTree(0, DirCacheIterator.class);
  49. assertNotNull(c);
  50. assertEquals(expIdx, c.ptr);
  51. assertSame(ents[expIdx], c.getDirCacheEntry());
  52. assertEquals(paths[expIdx], tw.getPathString());
  53. assertEquals(mode.getBits(), tw.getRawMode(0));
  54. assertSame(mode, tw.getFileMode(0));
  55. b.add(c.getDirCacheEntry());
  56. assertFalse("no more entries", tw.next());
  57. }
  58. b.finish();
  59. assertEquals(ents.length, dc.getEntryCount());
  60. for (int i = 0; i < ents.length; i++)
  61. assertSame(ents[i], dc.getEntry(i));
  62. }
  63. }