github.com/elves/elvish@v0.15.0/pkg/edit/listing_windows_test.go (about) 1 package edit 2 3 import ( 4 "os" 5 "path/filepath" 6 "reflect" 7 "regexp" 8 "sort" 9 "testing" 10 11 "github.com/elves/elvish/pkg/cli/term" 12 "github.com/elves/elvish/pkg/store" 13 "github.com/elves/elvish/pkg/testutil" 14 "github.com/elves/elvish/pkg/ui" 15 ) 16 17 func TestLocationAddon(t *testing.T) { 18 f := setup(storeOp(func(s store.Store) { 19 s.AddDir(`C:\usr\bin`, 1) 20 s.AddDir(`C:\tmp`, 1) 21 s.AddDir(`C:\home\elf`, 1) 22 })) 23 defer f.Cleanup() 24 25 evals(f.Evaler, 26 `edit:location:pinned = ['C:\opt']`, 27 `edit:location:hidden = ['C:\tmp']`) 28 f.TTYCtrl.Inject(term.K('L', ui.Ctrl)) 29 30 f.TestTTY(t, 31 "~> \n", 32 " LOCATION ", Styles, 33 "********** ", term.DotHere, "\n", 34 ` * C:\opt `+"\n", Styles, 35 "++++++++++++++++++++++++++++++++++++++++++++++++++", 36 ` 10 C:\home\elf`+"\n", 37 ` 10 C:\usr\bin`, 38 ) 39 } 40 41 func TestLocationAddon_Workspace(t *testing.T) { 42 f := setup(storeOp(func(s store.Store) { 43 s.AddDir(`C:\usr\bin`, 1) 44 s.AddDir(`ws\bin`, 1) 45 s.AddDir(`other-ws\bin`, 1) 46 })) 47 defer f.Cleanup() 48 testutil.ApplyDir( 49 testutil.Dir{ 50 "ws1": testutil.Dir{ 51 "bin": testutil.Dir{}, 52 "tmp": testutil.Dir{}}}) 53 err := os.Chdir(`ws1\tmp`) 54 if err != nil { 55 t.Skip("chdir:", err) 56 } 57 58 evals(f.Evaler, 59 `edit:location:workspaces = [&ws='`+ 60 regexp.QuoteMeta(f.Home)+`\\'ws.]`) 61 62 f.TTYCtrl.Inject(term.K('L', ui.Ctrl)) 63 f.TestTTY(t, 64 `~\ws1\tmp> `+"\n", 65 " LOCATION ", Styles, 66 "********** ", term.DotHere, "\n", 67 ` 10 ws\bin `+"\n", Styles, 68 "++++++++++++++++++++++++++++++++++++++++++++++++++", 69 ` 10 C:\usr\bin`, 70 ) 71 72 f.TTYCtrl.Inject(term.K(ui.Enter)) 73 f.TestTTY(t, `~\ws1\bin> `, term.DotHere) 74 } 75 76 func TestLocation_AddDir(t *testing.T) { 77 f := setup() 78 defer f.Cleanup() 79 testutil.ApplyDir( 80 testutil.Dir{ 81 "bin": testutil.Dir{}, 82 "ws1": testutil.Dir{ 83 "bin": testutil.Dir{}}}) 84 evals(f.Evaler, 85 `edit:location:workspaces = [&ws='`+ 86 regexp.QuoteMeta(f.Home)+`\\'ws.]`) 87 88 chdir := func(path string) { 89 err := f.Evaler.Chdir(path) 90 if err != nil { 91 t.Skip("chdir:", err) 92 } 93 } 94 chdir("bin") 95 chdir(`..\ws1\bin`) 96 97 entries, err := f.Store.Dirs(map[string]struct{}{}) 98 if err != nil { 99 t.Error("unable to list dir history:", err) 100 } 101 dirs := make([]string, len(entries)) 102 for i, entry := range entries { 103 dirs[i] = entry.Path 104 } 105 106 wantDirs := []string{ 107 filepath.Join(f.Home, "bin"), 108 filepath.Join(f.Home, "ws1", "bin"), 109 filepath.Join("ws", "bin"), 110 } 111 112 sort.Strings(dirs) 113 sort.Strings(wantDirs) 114 if !reflect.DeepEqual(dirs, wantDirs) { 115 t.Errorf("got dirs %v, want %v", dirs, wantDirs) 116 } 117 }