diff options
Diffstat (limited to 'pkg/u/file_test.go')
-rw-r--r-- | pkg/u/file_test.go | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/pkg/u/file_test.go b/pkg/u/file_test.go new file mode 100644 index 0000000..b7d6975 --- /dev/null +++ b/pkg/u/file_test.go @@ -0,0 +1,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) + } + + }) + } +} |