Skip to content

Commit

Permalink
Add test for / postfix -> match only folders, fix that
Browse files Browse the repository at this point in the history
  • Loading branch information
aligator committed Nov 29, 2021
1 parent 78e5e0d commit fe4b2a7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
2 changes: 1 addition & 1 deletion nogo.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func (n *NoGo) match(path string, isDir bool, noParents bool) (match bool, becau
for _, rule := range g.rules {
newRes := rule.MatchPath(path)

if newRes.Found {
if newRes.Found && ((newRes.OnlyFolder && isDir) || !newRes.OnlyFolder) {
because = newRes
because.ParentMatch = i < len(pathToCheck)-1
}
Expand Down
43 changes: 28 additions & 15 deletions nogo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ var (
Regexp: []*regexp.Regexp{regexp.MustCompile(`^aFolder/ignoredFile$`)},
Pattern: "aFolder/ignoredFile",
},
{
Regexp: []*regexp.Regexp{regexp.MustCompile(`^(.*/)?ignoredFolder$`)},
Pattern: "ignoredFolder/",
OnlyFolder: true,
},
{
Regexp: []*regexp.Regexp{regexp.MustCompile(`^(.*/)?ignoredFolder-notAFolder$`)},
Pattern: "ignoredFolder-notAFolder/",
OnlyFolder: true,
},
},
},
{
Expand Down Expand Up @@ -108,22 +118,25 @@ var (
var testFS = map[string]struct {
data string
ignoredBy *Result
isDir bool // TODO: currently there is no test for a dir...
isDir bool
}{
".gitignore": {"globallyIgnored\naPartiallyIgnoredFolder/**\n!aPartiallyIgnoredFolder/.gitignore\naFolder/ignoredFile", nil, false},
"globallyIgnored": {"", &Result{Rule: TestFSGroups[0].rules[0], Found: true, ParentMatch: false}, false},
"aFile": {"", nil, false},
"aFolder/ignoredFile": {"", &Result{Rule: TestFSGroups[0].rules[3], Found: true, ParentMatch: false}, false},
"aFolder/notIgnored": {"", nil, false},
"aFolder/locallyIgnoredFile": {"", &Result{Rule: TestFSGroups[1].rules[0], Found: true, ParentMatch: false}, false},
"aFolder/.gitignore": {"/locallyIgnoredFile\n/ignoredSubFolder", nil, false},
"aFolder/ignoredSubFolder/aFile": {"", &Result{Rule: TestFSGroups[1].rules[1], Found: true, ParentMatch: true}, false},
"aFolder/ignoredSubFolder/anotherFile": {"", &Result{Rule: TestFSGroups[1].rules[1], Found: true, ParentMatch: true}, false},
"aPartiallyIgnoredFolder/.gitignore": {"!unignoredFile", &Result{Rule: TestFSGroups[0].rules[2], Found: true, ParentMatch: false}, false},
"aPartiallyIgnoredFolder/unignoredFile": {"", &Result{Rule: TestFSGroups[2].rules[0], Found: true, ParentMatch: false}, false},
"aPartiallyIgnoredFolder/ignoredFile": {"", &Result{Rule: TestFSGroups[0].rules[1], Found: true, ParentMatch: false}, false},
"aPartiallyIgnoredFolder/ignoredFolder/.gitignore": {"notParsed as it is in an ignored folder", &Result{Rule: TestFSGroups[0].rules[1], Found: true, ParentMatch: false}, false},
"aFolder/anotherFolder/globallyIgnored": {"", &Result{Rule: TestFSGroups[0].rules[0], Found: true, ParentMatch: false}, false},
".gitignore": {"globallyIgnored\naPartiallyIgnoredFolder/**\n!aPartiallyIgnoredFolder/.gitignore\naFolder/ignoredFile\nignoredFolder/\nignoredFolder-notAFolder/", nil, false},
"ignoredFolder": {"", &Result{Rule: TestFSGroups[0].rules[4], Found: true, ParentMatch: false}, true},
"ignoredFolder-notAFolder": {"", nil, false},
"globallyIgnored": {"", &Result{Rule: TestFSGroups[0].rules[0], Found: true, ParentMatch: false}, false},
"aFile": {"", nil, false},
"aFolder/ignoredFile": {"", &Result{Rule: TestFSGroups[0].rules[3], Found: true, ParentMatch: false}, false},
"aFolder/ignoredFolder": {"", nil, false}, // aFolder/ignoredFolder is actually no folder -> not ignored
"aFolder/notIgnored": {"", nil, false},
"aFolder/locallyIgnoredFile": {"", &Result{Rule: TestFSGroups[1].rules[0], Found: true, ParentMatch: false}, false},
"aFolder/.gitignore": {"/locallyIgnoredFile\n/ignoredSubFolder", nil, false},
"aFolder/ignoredSubFolder/aFile": {"", &Result{Rule: TestFSGroups[1].rules[1], Found: true, ParentMatch: true}, false},
"aFolder/ignoredSubFolder/anotherFile": {"", &Result{Rule: TestFSGroups[1].rules[1], Found: true, ParentMatch: true}, false},
"aPartiallyIgnoredFolder/.gitignore": {"!unignoredFile", &Result{Rule: TestFSGroups[0].rules[2], Found: true, ParentMatch: false}, false},
"aPartiallyIgnoredFolder/unignoredFile": {"", &Result{Rule: TestFSGroups[2].rules[0], Found: true, ParentMatch: false}, false},
"aPartiallyIgnoredFolder/ignoredFile": {"", &Result{Rule: TestFSGroups[0].rules[1], Found: true, ParentMatch: false}, false},
"aPartiallyIgnoredFolder/ignoredFolder/.gitignore": {"notParsed as it is in an ignored folder", &Result{Rule: TestFSGroups[0].rules[1], Found: true, ParentMatch: false}, false},
"aFolder/anotherFolder/globallyIgnored": {"", &Result{Rule: TestFSGroups[0].rules[0], Found: true, ParentMatch: false}, false},
"aFolder/anotherFolder/globallyIgnored/aFileInGloballyIgnored": {"", &Result{Rule: TestFSGroups[0].rules[0], Found: true, ParentMatch: true}, false},

"glob-tests/.gitignore": {"/file*withStar\n/question?mark??file???\n/file[a-z]with[!0-9]ranges\n/file**withDoubleStar\n**/foo\nany/**\nsomething/**/more", nil, false},
Expand Down

0 comments on commit fe4b2a7

Please sign in to comment.