Skip to content

Commit a6f4509

Browse files
committed
nvim: add extmarks testcase
1 parent 9e6bef5 commit a6f4509

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

nvim/nvim_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,64 @@ func TestAPI(t *testing.T) {
609609
t.Fatal("expected result to nil")
610610
}
611611
})
612+
613+
t.Run("extmarks", func(t *testing.T) {
614+
clearBuffer(t, v, 0) // clear curret buffer text
615+
616+
lines := [][]byte{[]byte("hello"), []byte("world")}
617+
if err := v.SetBufferLines(Buffer(0), 0, -1, true, lines); err != nil {
618+
t.Fatal(err)
619+
}
620+
621+
nsID, err := v.CreateNamespace("test_extmarks")
622+
if err != nil {
623+
t.Fatal(err)
624+
}
625+
const (
626+
extMarkID = 10
627+
wantLine = 1
628+
wantCol = 3
629+
)
630+
gotExtMarkID, err := v.SetBufferExtmark(Buffer(0), nsID, extMarkID, wantLine, wantCol, make(map[string]interface{}))
631+
if err != nil {
632+
t.Fatal(err)
633+
}
634+
if gotExtMarkID != extMarkID {
635+
t.Fatalf("got %d extMarkID but want %d", gotExtMarkID, extMarkID)
636+
}
637+
638+
extmarks, err := v.BufferExtmarks(Buffer(0), nsID, 0, -1, make(map[string]interface{}))
639+
if err != nil {
640+
t.Fatal(err)
641+
}
642+
if len(extmarks) > 1 {
643+
t.Fatalf("expected extmarks length to 1 but %d", len(extmarks))
644+
}
645+
if extmarks[0].ExtmarkID != gotExtMarkID {
646+
t.Fatalf("got %d extMarkID but want %d", extmarks[0].ExtmarkID, extMarkID)
647+
}
648+
if extmarks[0].Row != wantLine {
649+
t.Fatalf("got %d extmarks Row but want %d", extmarks[0].Row, wantLine)
650+
}
651+
if extmarks[0].Col != wantCol {
652+
t.Fatalf("got %d extmarks Col but want %d", extmarks[0].Col, wantCol)
653+
}
654+
655+
pos, err := v.BufferExtmarkByID(Buffer(0), nsID, gotExtMarkID)
656+
if err != nil {
657+
t.Fatal(err)
658+
}
659+
if pos[0] != wantLine {
660+
t.Fatalf("got %d extMark line but want %d", pos[0], wantLine)
661+
}
662+
if pos[1] != wantCol {
663+
t.Fatalf("got %d extMark col but want %d", pos[1], wantCol)
664+
}
665+
666+
if err := v.ClearBufferNamespace(Buffer(0), nsID, 0, -1); err != nil {
667+
t.Fatal(err)
668+
}
669+
})
612670
}
613671

614672
func TestDial(t *testing.T) {

0 commit comments

Comments
 (0)