aboutsummaryrefslogtreecommitdiff
path: root/pkg/u/file_test.go
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2024-07-07 20:28:42 +0200
committerGabriel A. Giovanini <mail@gabrielgio.me>2024-07-07 21:44:29 +0200
commit44bc8e4078a09857ad86691a83e7ba7d4e3a69c4 (patch)
tree6788cafeaac286d381cc69e1917dab6ae58d1f85 /pkg/u/file_test.go
parent8dff852753a1c4a708fd87e3cbb0f4844803aa95 (diff)
downloadcerrado-44bc8e4078a09857ad86691a83e7ba7d4e3a69c4.tar.gz
cerrado-44bc8e4078a09857ad86691a83e7ba7d4e3a69c4.tar.bz2
cerrado-44bc8e4078a09857ad86691a83e7ba7d4e3a69c4.zip
ref: Simplify path builder code
Diffstat (limited to 'pkg/u/file_test.go')
-rw-r--r--pkg/u/file_test.go59
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)
+ }
+
+ })
+ }
+}