src.elv.sh@v0.21.0-dev.0.20240515223629-06979efb9a2a/pkg/edit/editor_test.go (about) 1 package edit 2 3 import ( 4 "reflect" 5 "testing" 6 7 "src.elv.sh/pkg/store/storedefs" 8 "src.elv.sh/pkg/ui" 9 ) 10 11 func TestEditor_AddsHistoryAfterAccepting(t *testing.T) { 12 f := setup(t) 13 14 feedInput(f.TTYCtrl, "echo x\n") 15 f.Wait() 16 17 testCommands(t, f.Store, storedefs.Cmd{Text: "echo x", Seq: 1}) 18 } 19 20 func TestEditor_DoesNotAddEmptyCommandToHistory(t *testing.T) { 21 f := setup(t) 22 23 feedInput(f.TTYCtrl, "\n") 24 f.Wait() 25 26 testCommands(t, f.Store /* no commands */) 27 } 28 29 func TestEditor_Notify(t *testing.T) { 30 f := setup(t) 31 f.Editor.Notify(ui.T("note")) 32 f.TestTTYNotes(t, "note") 33 } 34 35 func testCommands(t *testing.T, store storedefs.Store, wantCmds ...storedefs.Cmd) { 36 t.Helper() 37 cmds, err := store.CmdsWithSeq(0, 1024) 38 if err != nil { 39 panic(err) 40 } 41 if !reflect.DeepEqual(cmds, wantCmds) { 42 t.Errorf("got cmds %v, want %v", cmds, wantCmds) 43 } 44 }