cerrado @ master

 1// go:build unit
 2package u
 3
 4import "testing"
 5
 6func TestPathing(t *testing.T) {
 7	testCases := []struct {
 8		name string
 9		in   []any
10		out  string
11	}{
12		{
13			name: "root",
14			in:   []any{},
15			out:  "",
16		},
17		{
18			name: "empty",
19			in: []any{
20				"/",
21				[]string{"/", "/"},
22				"/",
23				[]string{"/"},
24			},
25			out: "",
26		},
27		{
28			name: "empty",
29			in: []any{
30				"usr",
31				[]string{"/share/", "lib"},
32				"/demo",
33				[]string{"/out//"},
34			},
35			out: "/usr/share/lib/demo/out",
36		},
37	}
38
39	for _, tc := range testCases {
40		t.Run(tc.name, func(t *testing.T) {
41			r := NewPathing()
42
43			for _, v := range tc.in {
44				switch s := v.(type) {
45				case string:
46					r = r.AddPath(s)
47				case []string:
48					r = r.AddPaths(s)
49				}
50			}
51
52			path := r.Done()
53			if tc.out != path {
54				t.Errorf("String mismatch: wanted %s got %s", tc.out, path)
55			}
56
57		})
58	}
59}