Skip to content

Commit

Permalink
+ bothname and leadingspace tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
zealic committed Jan 30, 2019
1 parent c8dfbb0 commit 310ade8
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 4 deletions.
4 changes: 2 additions & 2 deletions ignorefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ func (f *Ignorefile) FromReader(reader io.Reader) error {
if strings.HasPrefix(pattern, "#") {
continue
}
pattern = strings.TrimSpace(pattern)
pattern = strings.TrimRight(pattern, " ")
if pattern == "" {
continue
}
// normalize absolute paths to paths relative to the context
// (taking care of '!' prefix)
invert := pattern[0] == '!'
if invert {
pattern = strings.TrimSpace(pattern[1:])
pattern = strings.TrimRight(pattern[1:], " ")
}
if len(pattern) > 0 {
pattern = filepath.Clean(pattern)
Expand Down
35 changes: 33 additions & 2 deletions matcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestMatches_Nested(t *testing.T) {
"inner/inner2/.xignore", "inner/inner2/jess.ini",
}, result.UnmatchedFiles)
require.Empty(t, result.MatchedDirs)
require.Equal(t, result.UnmatchedDirs, []string{"inner", "inner/inner2"})
require.Equal(t, []string{"inner", "inner/inner2"}, result.UnmatchedDirs)
}

func TestMatches_ByName(t *testing.T) {
Expand All @@ -138,5 +138,36 @@ func TestMatches_ByName(t *testing.T) {
}, result.MatchedFiles)
require.Equal(t, []string{".xignore"}, result.UnmatchedFiles)
require.Equal(t, []string{}, result.MatchedDirs)
require.Equal(t, result.UnmatchedDirs, []string{"aa", "aa/a1", "aa/a1/a2", "bb"})
require.Equal(t, []string{"aa", "aa/a1", "aa/a1/a2", "bb"}, result.UnmatchedDirs)
}

func TestMatches_Bothname(t *testing.T) {
matcher := NewSystemMatcher()
result, err := matcher.Matches("testdata/bothname", &MatchesOptions{
Ignorefile: ".xignore",
})
require.NoError(t, err)

require.Equal(t, []string{
"foo/loss.txt", "loss.txt/1.log", "loss.txt/2.log",
}, result.MatchedFiles)
require.Equal(t, []string{".xignore"}, result.UnmatchedFiles)
require.Equal(t, []string{"loss.txt"}, result.MatchedDirs)
require.Equal(t, []string{"foo"}, result.UnmatchedDirs)
}

func TestMatches_LeadingSpace(t *testing.T) {
matcher := NewSystemMatcher()
result, err := matcher.Matches("testdata/leadingspace", &MatchesOptions{
Ignorefile: ".xignore",
})
require.NoError(t, err)

require.Equal(t, []string{
" what.txt",
"inner2/ what.txt",
}, result.MatchedFiles)
require.Equal(t, []string{".xignore", "inner/ what.txt"}, result.UnmatchedFiles)
require.Equal(t, []string{}, result.MatchedDirs)
require.Equal(t, []string{"inner", "inner2"}, result.UnmatchedDirs)
}
1 change: 1 addition & 0 deletions testdata/bothname/.xignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
loss.txt
Empty file added testdata/bothname/foo/loss.txt
Empty file.
Empty file.
Empty file.
Empty file added testdata/leadingspace/ what.txt
Empty file.
2 changes: 2 additions & 0 deletions testdata/leadingspace/.xignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
what.txt
!inner/ what.txt
Empty file.
Empty file.

0 comments on commit 310ade8

Please sign in to comment.