github.com/elves/elvish@v0.15.0/pkg/edit/state_api_test.go (about) 1 package edit 2 3 import ( 4 "testing" 5 6 "github.com/elves/elvish/pkg/cli" 7 ) 8 9 func TestInsertAtDot(t *testing.T) { 10 f := setup() 11 defer f.Cleanup() 12 13 cli.SetCodeBuffer(f.Editor.app, cli.CodeBuffer{Content: "ab", Dot: 1}) 14 evals(f.Evaler, `edit:insert-at-dot XYZ`) 15 16 testCodeBuffer(t, f.Editor, cli.CodeBuffer{Content: "aXYZb", Dot: 4}) 17 } 18 19 func TestReplaceInput(t *testing.T) { 20 f := setup() 21 defer f.Cleanup() 22 23 cli.SetCodeBuffer(f.Editor.app, cli.CodeBuffer{Content: "ab", Dot: 1}) 24 evals(f.Evaler, `edit:replace-input XYZ`) 25 26 testCodeBuffer(t, f.Editor, cli.CodeBuffer{Content: "XYZ", Dot: 3}) 27 } 28 29 func TestDot(t *testing.T) { 30 f := setup() 31 defer f.Cleanup() 32 33 cli.SetCodeBuffer(f.Editor.app, cli.CodeBuffer{Content: "code", Dot: 4}) 34 evals(f.Evaler, `edit:-dot = 0`) 35 36 testCodeBuffer(t, f.Editor, cli.CodeBuffer{Content: "code", Dot: 0}) 37 } 38 39 func TestCurrentCommand(t *testing.T) { 40 f := setup() 41 defer f.Cleanup() 42 43 evals(f.Evaler, `edit:current-command = code`) 44 45 testCodeBuffer(t, f.Editor, cli.CodeBuffer{Content: "code", Dot: 4}) 46 } 47 48 func testCodeBuffer(t *testing.T, ed *Editor, wantBuf cli.CodeBuffer) { 49 t.Helper() 50 if buf := cli.GetCodeBuffer(ed.app); buf != wantBuf { 51 t.Errorf("content = %v, want %v", buf, wantBuf) 52 } 53 }