Skip to content

Commit f3ef3e8

Browse files
committed
nvim: add BufferMark testcase
Signed-off-by: Koichi Shiraishi <[email protected]>
1 parent d8c9fc8 commit f3ef3e8

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

nvim/api_test.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,42 @@ func testBuffer(v *Nvim) func(*testing.T) {
645645
t.Fatalf("expected buffer is valid but got %t", valid)
646646
}
647647
})
648+
649+
t.Run("BufferMark", func(t *testing.T) {
650+
lines := [][]byte{
651+
[]byte("a"),
652+
[]byte("bit of"),
653+
[]byte("text"),
654+
}
655+
if err := v.SetBufferLines(Buffer(0), -1, -1, true, lines); err != nil {
656+
t.Fatal(err)
657+
}
658+
if err := v.SetWindowCursor(Window(0), [2]int{3, 4}); err != nil {
659+
t.Fatal(err)
660+
}
661+
if err := v.Command("mark v"); err != nil {
662+
t.Fatal(err)
663+
}
664+
665+
const (
666+
wantLine = 3
667+
wantCol = 0
668+
)
669+
pos, err := v.BufferMark(Buffer(0), "v")
670+
if err != nil {
671+
t.Fatal(err)
672+
}
673+
if pos[0] != wantLine {
674+
t.Fatalf("got %d extMark line but want %d", pos[0], wantLine)
675+
}
676+
if pos[1] != wantCol {
677+
t.Fatalf("got %d extMark col but want %d", pos[1], wantCol)
678+
}
679+
680+
t.Cleanup(func() {
681+
clearBuffer(t, v, Buffer(0))
682+
})
683+
})
648684
})
649685

650686
t.Run("Batch", func(t *testing.T) {
@@ -903,6 +939,45 @@ func testBuffer(v *Nvim) func(*testing.T) {
903939
t.Fatalf("expected buffer is valid but got %t", valid)
904940
}
905941
})
942+
943+
t.Run("BufferMark", func(t *testing.T) {
944+
b := v.NewBatch()
945+
946+
lines := [][]byte{
947+
[]byte("a"),
948+
[]byte("bit of"),
949+
[]byte("text"),
950+
}
951+
b.SetBufferLines(Buffer(0), -1, -1, true, lines)
952+
if err := b.Execute(); err != nil {
953+
t.Fatal(err)
954+
}
955+
b.SetWindowCursor(Window(0), [2]int{3, 4})
956+
b.Command("mark v")
957+
if err := b.Execute(); err != nil {
958+
t.Fatal(err)
959+
}
960+
961+
const (
962+
wantLine = 3
963+
wantCol = 0
964+
)
965+
var pos [2]int
966+
b.BufferMark(Buffer(0), "v", &pos)
967+
if err := b.Execute(); err != nil {
968+
t.Fatal(err)
969+
}
970+
if pos[0] != wantLine {
971+
t.Fatalf("got %d extMark line but want %d", pos[0], wantLine)
972+
}
973+
if pos[1] != wantCol {
974+
t.Fatalf("got %d extMark col but want %d", pos[1], wantCol)
975+
}
976+
977+
t.Cleanup(func() {
978+
clearBuffer(t, v, Buffer(0))
979+
})
980+
})
906981
})
907982
}
908983
}

0 commit comments

Comments
 (0)