2019-12-18 18:38:21 +08:00
|
|
|
package edit
|
2019-11-03 09:22:56 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-01-27 09:28:38 +08:00
|
|
|
"src.elv.sh/pkg/cli"
|
2021-02-12 02:49:00 +08:00
|
|
|
"src.elv.sh/pkg/cli/tk"
|
2019-11-03 09:22:56 +08:00
|
|
|
)
|
|
|
|
|
2019-11-04 07:27:16 +08:00
|
|
|
func TestInsertAtDot(t *testing.T) {
|
2019-11-08 23:49:43 +08:00
|
|
|
f := setup()
|
|
|
|
defer f.Cleanup()
|
2019-11-04 07:27:16 +08:00
|
|
|
|
2021-02-12 02:49:00 +08:00
|
|
|
cli.SetCodeBuffer(f.Editor.app, tk.CodeBuffer{Content: "ab", Dot: 1})
|
2019-11-08 23:49:43 +08:00
|
|
|
evals(f.Evaler, `edit:insert-at-dot XYZ`)
|
2019-11-04 07:27:16 +08:00
|
|
|
|
2021-02-12 02:49:00 +08:00
|
|
|
testCodeBuffer(t, f.Editor, tk.CodeBuffer{Content: "aXYZb", Dot: 4})
|
2019-11-04 07:27:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestReplaceInput(t *testing.T) {
|
2019-11-08 23:49:43 +08:00
|
|
|
f := setup()
|
|
|
|
defer f.Cleanup()
|
2019-11-04 07:27:16 +08:00
|
|
|
|
2021-02-12 02:49:00 +08:00
|
|
|
cli.SetCodeBuffer(f.Editor.app, tk.CodeBuffer{Content: "ab", Dot: 1})
|
2019-11-08 23:49:43 +08:00
|
|
|
evals(f.Evaler, `edit:replace-input XYZ`)
|
2019-11-04 07:27:16 +08:00
|
|
|
|
2021-02-12 02:49:00 +08:00
|
|
|
testCodeBuffer(t, f.Editor, tk.CodeBuffer{Content: "XYZ", Dot: 3})
|
2019-11-04 07:27:16 +08:00
|
|
|
}
|
|
|
|
|
2019-11-03 09:22:56 +08:00
|
|
|
func TestDot(t *testing.T) {
|
2019-11-08 23:49:43 +08:00
|
|
|
f := setup()
|
|
|
|
defer f.Cleanup()
|
2019-11-03 09:22:56 +08:00
|
|
|
|
2021-02-12 02:49:00 +08:00
|
|
|
cli.SetCodeBuffer(f.Editor.app, tk.CodeBuffer{Content: "code", Dot: 4})
|
2019-11-08 23:49:43 +08:00
|
|
|
evals(f.Evaler, `edit:-dot = 0`)
|
2019-11-04 07:27:16 +08:00
|
|
|
|
2021-02-12 02:49:00 +08:00
|
|
|
testCodeBuffer(t, f.Editor, tk.CodeBuffer{Content: "code", Dot: 0})
|
2019-11-03 09:22:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCurrentCommand(t *testing.T) {
|
2019-11-08 23:49:43 +08:00
|
|
|
f := setup()
|
|
|
|
defer f.Cleanup()
|
2019-11-03 09:22:56 +08:00
|
|
|
|
2019-11-08 23:49:43 +08:00
|
|
|
evals(f.Evaler, `edit:current-command = code`)
|
2019-11-04 07:27:16 +08:00
|
|
|
|
2021-02-12 02:49:00 +08:00
|
|
|
testCodeBuffer(t, f.Editor, tk.CodeBuffer{Content: "code", Dot: 4})
|
2019-11-04 07:27:16 +08:00
|
|
|
}
|
|
|
|
|
2021-02-12 02:49:00 +08:00
|
|
|
func testCodeBuffer(t *testing.T, ed *Editor, wantBuf tk.CodeBuffer) {
|
2019-11-04 07:27:16 +08:00
|
|
|
t.Helper()
|
2021-02-12 02:49:00 +08:00
|
|
|
if buf := cli.CodeBuffer(ed.app); buf != wantBuf {
|
2019-11-03 09:22:56 +08:00
|
|
|
t.Errorf("content = %v, want %v", buf, wantBuf)
|
|
|
|
}
|
|
|
|
}
|