@@ -16,6 +16,72 @@ import (
1616
1717
1818
19+ func TestDisplayPath (t * testing.T ) {
20+ t .Parallel ()
21+
22+ base := t .TempDir ()
23+ cwd := filepath .Join (base , "projects" , "lstk" )
24+ home := filepath .Join (base , "home" )
25+
26+ tests := []struct {
27+ name string
28+ abs string
29+ cwd string
30+ home string
31+ want string
32+ }{
33+ {
34+ name : "under cwd" ,
35+ abs : filepath .Join (cwd , "snap.zip" ),
36+ cwd : cwd , home : home ,
37+ want : "./snap.zip" ,
38+ },
39+ {
40+ name : "under cwd subdir" ,
41+ abs : filepath .Join (cwd , "exports" , "snap.zip" ),
42+ cwd : cwd , home : home ,
43+ want : "./exports/snap.zip" ,
44+ },
45+ {
46+ name : "under home but not cwd" ,
47+ abs : filepath .Join (home , "snap.zip" ),
48+ cwd : cwd , home : home ,
49+ want : "~/snap.zip" ,
50+ },
51+ {
52+ name : "under home subdir" ,
53+ abs : filepath .Join (home , "downloads" , "snap.zip" ),
54+ cwd : cwd , home : home ,
55+ want : "~/downloads/snap.zip" ,
56+ },
57+ {
58+ name : "unrelated to both" ,
59+ abs : filepath .Join (base , "other" , "snap.zip" ),
60+ cwd : cwd , home : home ,
61+ want : filepath .Join (base , "other" , "snap.zip" ),
62+ },
63+ {
64+ name : "empty cwd falls back to home" ,
65+ abs : filepath .Join (home , "snap.zip" ),
66+ cwd : "" , home : home ,
67+ want : "~/snap.zip" ,
68+ },
69+ {
70+ name : "empty cwd and home returns absolute" ,
71+ abs : filepath .Join (base , "snap.zip" ),
72+ cwd : "" , home : "" ,
73+ want : filepath .Join (base , "snap.zip" ),
74+ },
75+ }
76+
77+ for _ , tc := range tests {
78+ t .Run (tc .name , func (t * testing.T ) {
79+ t .Parallel ()
80+ assert .Equal (t , tc .want , snapshot .DisplayPath (tc .abs , tc .cwd , tc .home ))
81+ })
82+ }
83+ }
84+
1985func TestParseDestination (t * testing.T ) {
2086 t .Parallel ()
2187 wd , err := os .Getwd ()
0 commit comments