Skip to content

Commit

Permalink
nvim: add SetBufferMark and DeleteBufferMark testcases
Browse files Browse the repository at this point in the history
Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
  • Loading branch information
zchee committed Dec 11, 2021
1 parent ee3653e commit bedf397
Showing 1 changed file with 61 additions and 15 deletions.
76 changes: 61 additions & 15 deletions nvim/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,18 +661,28 @@ func testBuffer(v *Nvim) func(*testing.T) {
if err := v.SetBufferLines(Buffer(0), -1, -1, true, lines); err != nil {
t.Fatal(err)
}
t.Cleanup(func() {
clearBuffer(t, v, Buffer(0))
})

if err := v.SetWindowCursor(Window(0), [2]int{3, 4}); err != nil {
t.Fatal(err)
}
if err := v.Command("mark v"); err != nil {
t.Fatal(err)
}

const (
mark = "V"
wantLine = 3
wantCol = 0
)
pos, err := v.BufferMark(Buffer(0), "v")
set, err := v.SetBufferMark(Buffer(0), mark, wantLine, wantCol, make(map[string]interface{}))
if err != nil {
t.Fatal(err)
}
if !set {
t.Fatalf("could not set %s mark", mark)
}

pos, err := v.BufferMark(Buffer(0), mark)
if err != nil {
t.Fatal(err)
}
Expand All @@ -683,9 +693,21 @@ func testBuffer(v *Nvim) func(*testing.T) {
t.Fatalf("got %d extMark col but want %d", pos[1], wantCol)
}

t.Cleanup(func() {
clearBuffer(t, v, Buffer(0))
})
deleted, err := v.DeleteBufferMark(Buffer(0), mark)
if err != nil {
t.Fatal(err)
}
if !deleted {
t.Fatalf("could not delete %s mark", mark)
}

pos2, err := v.BufferMark(Buffer(0), mark)
if err != nil {
t.Fatal(err)
}
if pos2[0] != 0 || pos2[1] != 0 {
t.Fatalf("got %d mark but want zero", pos2)
}
})
})

Expand Down Expand Up @@ -961,18 +983,28 @@ func testBuffer(v *Nvim) func(*testing.T) {
if err := b.Execute(); err != nil {
t.Fatal(err)
}
t.Cleanup(func() {
clearBuffer(t, v, Buffer(0))
})

b.SetWindowCursor(Window(0), [2]int{3, 4})
b.Command("mark v")
if err := b.Execute(); err != nil {
t.Fatal(err)
}

const (
mark = "V"
wantLine = 3
wantCol = 0
)
var set bool
b.SetBufferMark(Buffer(0), mark, wantLine, wantCol, make(map[string]interface{}), &set)
if err := b.Execute(); err != nil {
t.Fatal(err)
}
if !set {
t.Fatalf("could not set %s mark", mark)
}

var pos [2]int
b.BufferMark(Buffer(0), "v", &pos)
b.BufferMark(Buffer(0), mark, &pos)
if err := b.Execute(); err != nil {
t.Fatal(err)
}
Expand All @@ -983,9 +1015,23 @@ func testBuffer(v *Nvim) func(*testing.T) {
t.Fatalf("got %d extMark col but want %d", pos[1], wantCol)
}

t.Cleanup(func() {
clearBuffer(t, v, Buffer(0))
})
var deleted bool
b.DeleteBufferMark(Buffer(0), mark, &deleted)
if err := b.Execute(); err != nil {
t.Fatal(err)
}
if !deleted {
t.Fatalf("could not delete %s mark", mark)
}

var pos2 [2]int
b.BufferMark(Buffer(0), mark, &pos2)
if err := b.Execute(); err != nil {
t.Fatal(err)
}
if pos2[0] != 0 || pos2[1] != 0 {
t.Fatalf("got %d mark but want zero", pos2)
}
})
})
}
Expand Down

0 comments on commit bedf397

Please sign in to comment.