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
|
// go:build unit
package u
import "testing"
func TestPathing(t *testing.T) {
testCases := []struct {
name string
in []any
out string
}{
{
name: "root",
in: []any{},
out: "",
},
{
name: "empty",
in: []any{
"/",
[]string{"/", "/"},
"/",
[]string{"/"},
},
out: "",
},
{
name: "empty",
in: []any{
"usr",
[]string{"/share/", "lib"},
"/demo",
[]string{"/out//"},
},
out: "/usr/share/lib/demo/out",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
r := NewPathing()
for _, v := range tc.in {
switch s := v.(type) {
case string:
r = r.AddPath(s)
case []string:
r = r.AddPaths(s)
}
}
path := r.Done()
if tc.out != path {
t.Errorf("String mismatch: wanted %s got %s", tc.out, path)
}
})
}
}
|