diff options
Diffstat (limited to 'internal/engine')
| -rw-r--r-- | internal/engine/facts.go | 4 | ||||
| -rw-r--r-- | internal/engine/facts_test.go | 17 |
2 files changed, 19 insertions, 2 deletions
diff --git a/internal/engine/facts.go b/internal/engine/facts.go index 423bfd9..5790e95 100644 --- a/internal/engine/facts.go +++ b/internal/engine/facts.go @@ -185,11 +185,11 @@ func (f *facts) Duplicate(dirs []string) (string, bool, error) { } // displayOriginal reports orig relative to root when it lies inside root, -// else as an absolute path. +// else home-abbreviated (xdg.Abbrev), as every other user-visible path is. func displayOriginal(orig, root string) string { rel, err := filepath.Rel(root, orig) if err != nil || rel == ".." || strings.HasPrefix(rel, ".."+string(filepath.Separator)) { - return orig + return xdg.Abbrev(orig) } return filepath.ToSlash(rel) } diff --git a/internal/engine/facts_test.go b/internal/engine/facts_test.go index c511804..7d844a0 100644 --- a/internal/engine/facts_test.go +++ b/internal/engine/facts_test.go @@ -75,3 +75,20 @@ func TestContentKeepsRawWithTwoVariants(t *testing.T) { t.Fatalf("second variant: got %q, %v, want the unfolded original (raw text must still be available)", got, err) } } + +// TestDisplayOriginalAbbreviatesHome: a duplicate's original is shown +// root-relative inside the root, and home-abbreviated outside it, the way +// every other user-visible path is; a path outside $HOME stays absolute. +func TestDisplayOriginalAbbreviatesHome(t *testing.T) { + h := sandbox(t) + root := filepath.Join(h, "downloads") + for _, tt := range []struct{ orig, want string }{ + {filepath.Join(root, "x", "a.pdf"), "x/a.pdf"}, + {filepath.Join(h, "docs", "work", "a.pdf"), "~/docs/work/a.pdf"}, + {"/srv/share/a.pdf", "/srv/share/a.pdf"}, + } { + if got := displayOriginal(tt.orig, root); got != tt.want { + t.Errorf("displayOriginal(%q) = %q, want %q", tt.orig, got, tt.want) + } + } +} |
