start using tree
This commit is contained in:
@@ -16,7 +16,7 @@ type Tree struct {
|
||||
}
|
||||
|
||||
// New creates a new tree from a given path.
|
||||
func New(paths []string) *Tree {
|
||||
func New(paths ...string) *Tree {
|
||||
t := &Tree{name: ".", children: []*Tree{}}
|
||||
for _, path := range paths {
|
||||
t.Add(path)
|
||||
|
||||
@@ -18,6 +18,11 @@ func TestTree(t *testing.T) {
|
||||
paths: []string{},
|
||||
matchFalse: []string{"a", "b"},
|
||||
},
|
||||
{
|
||||
name: "directory",
|
||||
paths: []string{"a/b"},
|
||||
matchTrue: []string{"a/b/"},
|
||||
},
|
||||
{
|
||||
name: "a few sequences",
|
||||
paths: []string{"a", "b", "c/b/a"},
|
||||
@@ -28,7 +33,7 @@ func TestTree(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
tree := New(tt.paths)
|
||||
tree := New(tt.paths...)
|
||||
|
||||
for _, path := range tt.matchTrue {
|
||||
t.Run(path, func(t *testing.T) {
|
||||
@@ -48,8 +53,8 @@ func TestTree(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTreeMerge(t *testing.T) {
|
||||
tree1 := New([]string{"bin/ar", "var/cache/apt"})
|
||||
tree2 := New([]string{"bin/ar", "bin/busybox", "usr/share/doc"})
|
||||
tree1 := New("bin/ar", "var/cache/apt")
|
||||
tree2 := New("bin/ar", "bin/busybox", "usr/share/doc")
|
||||
tree1.Merge(tree2)
|
||||
assert.Equal(t, "./bin/ar:./bin/busybox:./usr/share/doc:./var/cache/apt", tree1.String())
|
||||
assert.Equal(t, "./bin/ar:./bin/busybox:./usr/share/doc", tree2.String())
|
||||
@@ -85,7 +90,7 @@ func TestString(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
tree := New(tt.paths)
|
||||
tree := New(tt.paths...)
|
||||
assert.Equal(t, tt.wantStr, tree.String())
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user