From 676a139f5ab7850294e05f1b64f8bcc60a8ed951 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 13 Jun 2024 18:17:36 +0200 Subject: [PATCH] Added PathList.Equals method --- list.go | 14 ++++++++++++++ list_test.go | 3 +++ 2 files changed, 17 insertions(+) diff --git a/list.go b/list.go index fbab13c..585d2fe 100644 --- a/list.go +++ b/list.go @@ -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] diff --git a/list_test.go b/list_test.go index eaafc82..45919e2 100644 --- a/list_test.go +++ b/list_test.go @@ -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)) }