2019-08-26 01:13:25 +08:00
|
|
|
package cliedit
|
|
|
|
|
2019-11-09 22:56:54 +08:00
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/elves/elvish/cli/el/layout"
|
|
|
|
"github.com/elves/elvish/cli/term"
|
|
|
|
"github.com/elves/elvish/edit/ui"
|
|
|
|
"github.com/elves/elvish/store/storedefs"
|
|
|
|
"github.com/elves/elvish/styled"
|
|
|
|
)
|
|
|
|
|
2019-08-26 01:13:25 +08:00
|
|
|
/*
|
|
|
|
func TestInitListing_Binding(t *testing.T) {
|
|
|
|
// Test that the binding variable in the returned namespace indeed refers to
|
|
|
|
// the BindingMap returned.
|
|
|
|
_, binding, ns := initListing(&fakeApp{})
|
|
|
|
if ns["binding"].Get() != *binding {
|
|
|
|
t.Errorf("The binding var in the ns is not the same as the BindingMap")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2019-11-09 22:56:54 +08:00
|
|
|
// Smoke tests for individual addons.
|
2019-08-26 01:13:25 +08:00
|
|
|
|
2019-11-09 22:56:54 +08:00
|
|
|
func TestHistlistAddon(t *testing.T) {
|
|
|
|
f := setupWithOpt(setupOpt{StoreOp: func(s storedefs.Store) {
|
|
|
|
s.AddCmd("echo 1")
|
|
|
|
s.AddCmd("echo 2")
|
|
|
|
}})
|
|
|
|
f.TTYCtrl.SetSize(24, 30) // Set width to 30
|
|
|
|
defer f.Cleanup()
|
2019-08-26 01:13:25 +08:00
|
|
|
|
2019-11-09 22:56:54 +08:00
|
|
|
f.TTYCtrl.Inject(term.K('R', ui.Ctrl))
|
2019-11-16 08:00:06 +08:00
|
|
|
wantBuf := bbAddon(" HISTORY (dedup on) ").
|
2019-11-09 22:56:54 +08:00
|
|
|
WriteStyled(styled.MarkLines(
|
|
|
|
" 0 echo 1",
|
|
|
|
" 1 echo 2 ", styles,
|
|
|
|
"##############################",
|
|
|
|
)).Buffer()
|
|
|
|
f.TTYCtrl.TestBuffer(t, wantBuf)
|
2019-08-26 01:13:25 +08:00
|
|
|
}
|
|
|
|
|
2019-11-09 22:56:54 +08:00
|
|
|
func TestLastCmdAddon(t *testing.T) {
|
|
|
|
f := setupWithOpt(setupOpt{StoreOp: func(s storedefs.Store) {
|
|
|
|
s.AddCmd("echo hello world")
|
|
|
|
}})
|
|
|
|
f.TTYCtrl.SetSize(24, 30) // Set width to 30
|
|
|
|
defer f.Cleanup()
|
2019-08-26 01:13:25 +08:00
|
|
|
|
2019-11-09 22:56:54 +08:00
|
|
|
f.TTYCtrl.Inject(term.K(',', ui.Alt))
|
|
|
|
wantBuf := bbAddon("LASTCMD").
|
|
|
|
WriteStyled(styled.MarkLines(
|
|
|
|
" echo hello world ", styles,
|
|
|
|
"##############################",
|
|
|
|
" 0 echo",
|
|
|
|
" 1 hello",
|
|
|
|
" 2 world",
|
|
|
|
)).Buffer()
|
|
|
|
f.TTYCtrl.TestBuffer(t, wantBuf)
|
2019-08-26 01:13:25 +08:00
|
|
|
}
|
|
|
|
|
2019-11-09 22:56:54 +08:00
|
|
|
func TestLocationAddon(t *testing.T) {
|
|
|
|
f := setupWithOpt(setupOpt{StoreOp: func(s storedefs.Store) {
|
|
|
|
s.AddDir("/usr/bin", 1)
|
2019-11-15 05:30:19 +08:00
|
|
|
s.AddDir("/tmp", 1)
|
2019-11-09 22:56:54 +08:00
|
|
|
s.AddDir("/home/elf", 1)
|
|
|
|
}})
|
|
|
|
f.TTYCtrl.SetSize(24, 30) // Set width to 30
|
|
|
|
defer f.Cleanup()
|
2019-08-26 01:13:25 +08:00
|
|
|
|
2019-11-15 05:30:19 +08:00
|
|
|
evals(f.Evaler,
|
|
|
|
`edit:location:pinned = [/opt]`,
|
|
|
|
`edit:location:hidden = [/tmp]`)
|
2019-11-09 22:56:54 +08:00
|
|
|
f.TTYCtrl.Inject(term.K('L', ui.Ctrl))
|
2019-11-15 05:30:19 +08:00
|
|
|
|
2019-11-09 22:56:54 +08:00
|
|
|
wantBuf := bbAddon("LOCATION").
|
|
|
|
WriteStyled(styled.MarkLines(
|
2019-11-15 05:30:19 +08:00
|
|
|
" * /opt ", styles,
|
2019-11-09 22:56:54 +08:00
|
|
|
"##############################",
|
2019-11-15 05:30:19 +08:00
|
|
|
" 10 /home/elf",
|
2019-11-09 22:56:54 +08:00
|
|
|
" 10 /usr/bin",
|
|
|
|
)).Buffer()
|
|
|
|
f.TTYCtrl.TestBuffer(t, wantBuf)
|
|
|
|
}
|
2019-08-26 01:13:25 +08:00
|
|
|
|
2019-11-09 22:56:54 +08:00
|
|
|
func bbAddon(name string) *ui.BufferBuilder {
|
|
|
|
return ui.NewBufferBuilder(30).
|
|
|
|
WritePlain("~> ").Newline().
|
|
|
|
WriteStyled(layout.ModeLine(name, true)).SetDotToCursor().Newline()
|
2019-08-26 01:13:25 +08:00
|
|
|
}
|