Skip to content

Commit a1177b8

Browse files
committed
Fixed PathList.AddAllMissing
1 parent 7d89a09 commit a1177b8

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

list.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ func (p *PathList) AddIfMissing(path *Path) {
112112
(*p).Add(path)
113113
}
114114

115-
// AddAllMissing adds all paths to the PathList excluding the path already
115+
// AddAllMissing adds all paths to the PathList excluding the paths already
116116
// in the list
117-
func (p *PathList) AddAllMissing(paths PathList) {
118-
for _, path := range *p {
119-
(*p).AddIfMissing(path)
117+
func (p *PathList) AddAllMissing(pathsToAdd PathList) {
118+
for _, pathToAdd := range pathsToAdd {
119+
(*p).AddIfMissing(pathToAdd)
120120
}
121121
}
122122

list_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,13 @@ func TestListConstructors(t *testing.T) {
5555
require.False(t, list3.ContainsEquivalentTo(New("d")))
5656
require.True(t, list3.ContainsEquivalentTo(New("a")))
5757
require.True(t, list3.ContainsEquivalentTo(New("d/../a")))
58+
59+
list4 := list3.Clone()
60+
require.Equal(t, "[a b c]", fmt.Sprintf("%s", list4))
61+
list4.AddIfMissing(New("d"))
62+
require.Equal(t, "[a b c d]", fmt.Sprintf("%s", list4))
63+
list4.AddIfMissing(New("b"))
64+
require.Equal(t, "[a b c d]", fmt.Sprintf("%s", list4))
65+
list4.AddAllMissing(NewPathList("a", "e", "i", "o", "u"))
66+
require.Equal(t, "[a b c d e i o u]", fmt.Sprintf("%s", list4))
5867
}

0 commit comments

Comments
 (0)