From 44bc8e4078a09857ad86691a83e7ba7d4e3a69c4 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Sun, 7 Jul 2024 20:28:42 +0200 Subject: ref: Simplify path builder code --- pkg/u/file_test.go | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 pkg/u/file_test.go (limited to 'pkg/u/file_test.go') 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) + } + + }) + } +} -- cgit v1.2.3