Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added PathList.Equals method #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions list.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@ func (p *PathList) AsStrings() []string {
return res
}

// Equals returns true if the current PathList is equal to the
// PathList passed as argument
func (p *PathList) Equals(other PathList) bool {
if len(*p) != len(other) {
return false
}
for i, path := range *p {
if !path.EqualsTo(other[i]) {
return false
}
}
return true
}

// FilterDirs remove all entries except directories
func (p *PathList) FilterDirs() {
res := (*p)[:0]
Expand Down
3 changes: 3 additions & 0 deletions list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,15 @@ func TestListConstructors(t *testing.T) {
require.True(t, list3.ContainsEquivalentTo(New("d/../a")))

list4 := list3.Clone()
require.True(t, list3.Equals(list4))
require.Equal(t, "[a b c]", fmt.Sprintf("%s", list4))
list4.AddIfMissing(New("d"))
require.Equal(t, "[a b c d]", fmt.Sprintf("%s", list4))
list4.AddIfMissing(New("b"))
require.Equal(t, "[a b c d]", fmt.Sprintf("%s", list4))
list4.AddAllMissing(NewPathList("a", "e", "i", "o", "u"))
require.False(t, list3.Equals(list4))
require.False(t, list4.Equals(list3))
require.Equal(t, "[a b c d e i o u]", fmt.Sprintf("%s", list4))
}

Expand Down
Loading