Skip to content

Commit

Permalink
showcase eclipse-jgit#105
Browse files Browse the repository at this point in the history
  • Loading branch information
Jente Sondervorst committed Oct 25, 2024
1 parent 2e4b5b5 commit f14ea43
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,33 @@ public void fastIgnoreRuleForNestedDirectory() {
assertTrue(ignoreRule2.isMatch("/directory/nested/again", true, true)); // It matches the directory
// ^^^^^
}

@Test
public void fastIgnoreRuleForDirectory() {
FastIgnoreRule ignoreRule = new FastIgnoreRule("/directory/");
assertTrue(ignoreRule.isMatch("/directory/nested/", true, false));
assertTrue(ignoreRule.isMatch("/directory/nested.txt", false, false));
assertTrue(ignoreRule.isMatch("/directory/nested/test.txt", false, false));

//THIS IS RETURNING FALSE due to pathMatch being true
assertTrue(ignoreRule.isMatch("/directory/nested/", true, true));
assertTrue(ignoreRule.isMatch("/directory/nested.txt", false, true));
assertTrue(ignoreRule.isMatch("/directory/nested/test.txt", false, true));
}

@Test
public void theSolutionShouldSucceedOnThisTest() throws IOException {
IgnoreNode ignoreNode = new IgnoreNode();
StringBuilder gitignore = new StringBuilder()
.append("/directory/nested/").append("\n")
.append("/single/").append("\n");
ignoreNode.parse(new ByteArrayInputStream(gitignore.toString().getBytes()));

assertEquals(IgnoreNode.MatchResult.IGNORED, ignoreNode.isIgnored("/directory/nested/again/", true));
assertEquals(IgnoreNode.MatchResult.IGNORED, ignoreNode.isIgnored("/directory/nested/again.txt", false));
assertEquals(IgnoreNode.MatchResult.IGNORED, ignoreNode.isIgnored("/directory/nested/again/again.txt", false));
assertEquals(IgnoreNode.MatchResult.IGNORED, ignoreNode.isIgnored("/single/again/", true));
assertEquals(IgnoreNode.MatchResult.IGNORED, ignoreNode.isIgnored("/single/again.txt", false));
assertEquals(IgnoreNode.MatchResult.IGNORED, ignoreNode.isIgnored("/single/again/again.txt", false));
}
}

0 comments on commit f14ea43

Please sign in to comment.