-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisit_test.go
53 lines (41 loc) · 911 Bytes
/
visit_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package pathutil
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestVisitFlat(t *testing.T) {
path, err := New("examples/tree")
assert.Nil(t, err)
flat_expected := map[string]int{
"examples/tree/4": 0,
}
flat := make(map[string]int)
path.Visit(
func(path Path) {
flat[path.String()] = 0
},
VisitOpt{},
)
assert.Equal(t, flat_expected, flat, "flat files")
}
func TestVisitRecurse(t *testing.T) {
path, err := New("examples/tree")
assert.Nil(t, err)
flat_expected := map[string]int{
"examples/tree/a": 0,
"examples/tree/a/1": 0,
"examples/tree/a/b": 0,
"examples/tree/a/b/2": 0,
"examples/tree/c": 0,
"examples/tree/c/3": 0,
"examples/tree/4": 0,
}
flat := make(map[string]int)
path.Visit(
func(path Path) {
flat[path.String()] = 0
},
VisitOpt{Recurse: true},
)
assert.Equal(t, flat_expected, flat, "flat files")
}