-
Notifications
You must be signed in to change notification settings - Fork 0
/
separate_test.go
125 lines (106 loc) · 3.18 KB
/
separate_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package nef_test
import (
"io/fs"
"path/filepath"
. "github.com/onsi/ginkgo/v2" //nolint:revive // ok
. "github.com/onsi/gomega" //nolint:revive // ok
nef "github.com/snivilised/nefilim"
"github.com/snivilised/nefilim/internal/third/lo"
"github.com/snivilised/nefilim/test/luna"
)
var _ = Describe("Separate", Ordered, func() {
var (
fS nef.UniversalFS
calc nef.PathCalc
root, separate string
expectations = struct {
foo,
bar,
baz,
x,
y string
}{
foo: "foo.txt",
bar: "bar.txt",
baz: "baz.txt",
x: "x",
y: "y",
}
)
BeforeAll(func() {
root = luna.Repo("test")
separate = filepath.Join("scratch", "separate")
})
BeforeEach(func() {
scratch(root)
fS = nef.NewUniversalABS()
calc = fS.Calc()
})
When("directory contains mixed entries", func() {
It("🧪 should: separate files from directories", func() {
Expect(requires(fS, root, separate,
calc.Join(separate, expectations.foo),
calc.Join(separate, expectations.bar),
calc.Join(separate, expectations.baz),
)).To(Succeed())
Expect(requires(fS, root, filepath.Join(separate, "x"))).To(Succeed())
Expect(requires(fS, root, filepath.Join(separate, "y"))).To(Succeed())
full := filepath.Join(root, separate)
entries, err := fS.ReadDir(full)
Expect(err).To(Succeed())
files, directories := nef.Separate(entries)
fileNames := lo.Map(files, func(entry fs.DirEntry, _ int) string {
return entry.Name()
})
Expect(fileNames).To(ContainElements(
expectations.foo, expectations.bar, expectations.baz,
))
dirNames := lo.Map(directories, func(entry fs.DirEntry, _ int) string {
return entry.Name()
})
Expect(dirNames).To(ContainElements(
expectations.x, expectations.y,
))
})
})
When("directory contains only file entries", func() {
It("🧪 should: return files", func() {
Expect(requires(fS, root, separate,
calc.Join(separate, expectations.foo),
calc.Join(separate, expectations.bar),
calc.Join(separate, expectations.baz),
)).To(Succeed())
full := filepath.Join(root, separate)
entries, err := fS.ReadDir(full)
Expect(err).To(Succeed())
files, directories := nef.Separate(entries)
fileNames := lo.Map(files, func(entry fs.DirEntry, _ int) string {
return entry.Name()
})
Expect(fileNames).To(ContainElements(
expectations.foo, expectations.bar, expectations.baz,
))
Expect(directories).NotTo(BeNil())
Expect(directories).To(BeEmpty())
})
})
When("directory contains only directory entries", func() {
It("🧪 should: return files", func() {
Expect(requires(fS, root, separate)).To(Succeed())
Expect(requires(fS, root, filepath.Join(separate, "x"))).To(Succeed())
Expect(requires(fS, root, filepath.Join(separate, "y"))).To(Succeed())
full := filepath.Join(root, separate)
entries, err := fS.ReadDir(full)
Expect(err).To(Succeed())
files, directories := nef.Separate(entries)
Expect(files).NotTo(BeNil())
Expect(files).To(BeEmpty())
dirNames := lo.Map(directories, func(entry fs.DirEntry, _ int) string {
return entry.Name()
})
Expect(dirNames).To(ContainElements(
expectations.x, expectations.y,
))
})
})
})