aboutsummaryrefslogtreecommitdiff
path: root/internal/cli/path_prefix_test.go
diff options
context:
space:
mode:
authortsne <tsne.dev@outlook.com>2026-07-06 16:52:20 +0200
committertsne <tsne.dev@outlook.com>2026-07-06 21:37:42 +0200
commit84da43998f7cc42cc72652333ac6e3d293abb23e (patch)
tree6610f82df854ae86f7f34152bb05fc712ef6f314 /internal/cli/path_prefix_test.go
downloadhopper-84da43998f7cc42cc72652333ac6e3d293abb23e.tar.gz
initialHEADmain
Diffstat (limited to 'internal/cli/path_prefix_test.go')
-rw-r--r--internal/cli/path_prefix_test.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/internal/cli/path_prefix_test.go b/internal/cli/path_prefix_test.go
new file mode 100644
index 0000000..bdb4e42
--- /dev/null
+++ b/internal/cli/path_prefix_test.go
@@ -0,0 +1,52 @@
+package cli
+
+import (
+ "errors"
+ "testing"
+)
+
+func TestPathPrefixValueSet(t *testing.T) {
+ cases := map[string]string{
+ "": "",
+ "/": "",
+ "foo": "foo",
+ "/foo": "foo",
+ "foo/": "foo",
+ "/foo/": "foo",
+ "foo//bar": "foo/bar",
+ "foo/./bar": "foo/bar",
+ "foo/bar/..": "foo",
+ "a/b/../c": "a/c",
+ }
+ for in, want := range cases {
+ var p string
+ v := &pathPrefixValue{p: &p}
+ if err := v.Set(in); err != nil {
+ t.Errorf("Set(%q): unexpected error %v", in, err)
+ continue
+ }
+ if p != want {
+ t.Errorf("Set(%q) = %q, want %q", in, p, want)
+ }
+ }
+}
+
+func TestPathPrefixValueSetEscapes(t *testing.T) {
+ for _, in := range []string{"..", "../x", "/../x", "foo/../../x"} {
+ var p string
+ v := &pathPrefixValue{p: &p}
+ var ue usageError
+ if err := v.Set(in); !errors.As(err, &ue) {
+ t.Errorf("Set(%q): expected usageError, got %v", in, err)
+ }
+ }
+}
+
+func TestPrefixedPath(t *testing.T) {
+ if got := prefixedPath("", "assets/x.js"); got != "assets/x.js" {
+ t.Errorf("empty prefix: got %q", got)
+ }
+ if got := prefixedPath("foo", "assets/x.js"); got != "foo/assets/x.js" {
+ t.Errorf("prefixed: got %q", got)
+ }
+}