github.com/elves/elvish@v0.15.0/pkg/edit/editor_test.go (about) 1 package edit 2 3 import ( 4 "reflect" 5 "testing" 6 7 "github.com/elves/elvish/pkg/store" 8 ) 9 10 func TestEditor_AddsHistoryAfterAccepting(t *testing.T) { 11 f := setup() 12 defer f.Cleanup() 13 14 feedInput(f.TTYCtrl, "echo x\n") 15 f.Wait() 16 17 testCommands(t, f.Store, "echo x") 18 } 19 20 func TestEditor_DoesNotAddEmptyCommandToHistory(t *testing.T) { 21 f := setup() 22 defer f.Cleanup() 23 24 feedInput(f.TTYCtrl, "\n") 25 f.Wait() 26 27 testCommands(t, f.Store /* no commands */) 28 } 29 30 func testCommands(t *testing.T, store store.Store, wantCmds ...string) { 31 t.Helper() 32 cmds, err := store.Cmds(0, 1024) 33 if err != nil { 34 panic(err) 35 } 36 if !reflect.DeepEqual(cmds, wantCmds) { 37 t.Errorf("got cmds %v, want %v", cmds, wantCmds) 38 } 39 }