Skip to content

Commit

Permalink
Improve test TestAPI/Extmarks/Batch
Browse files Browse the repository at this point in the history
Do not make assumptions about how nvim_buf_set_extmark() assigns IDs.

Validate that SetBufferExtmark returned the correct ID by relying on
existing test code code that compares the returned ID with the results
from BufferExmarks.
  • Loading branch information
garyburd committed May 14, 2024
1 parent 77f98f1 commit 1987893
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions nvim/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4303,17 +4303,13 @@ func testExtmarks(v *Nvim) func(*testing.T) {
}

const (
wantExtMarkID = 1
wantLine = 1
wantCol = 3
wantLine = 1
wantCol = 3
)
gotExtMarkID, err := v.SetBufferExtmark(Buffer(0), nsID, wantLine, wantCol, make(map[string]interface{}))
if err != nil {
t.Fatal(err)
}
if gotExtMarkID != wantExtMarkID {
t.Fatalf("got %d extMarkID but want %d", gotExtMarkID, wantExtMarkID)
}

extmarks, err := v.BufferExtmarks(Buffer(0), nsID, 0, -1, make(map[string]interface{}))
if err != nil {
Expand All @@ -4323,7 +4319,7 @@ func testExtmarks(v *Nvim) func(*testing.T) {
t.Fatalf("expected extmarks length to 1 but got %d", len(extmarks))
}
if extmarks[0].ID != gotExtMarkID {
t.Fatalf("got %d extMarkID but want %d", extmarks[0].ID, wantExtMarkID)
t.Fatalf("got %d extMarkID but want %d", extmarks[0].ID, gotExtMarkID)
}
if extmarks[0].Row != wantLine {
t.Fatalf("got %d extmarks Row but want %d", extmarks[0].Row, wantLine)
Expand Down Expand Up @@ -4382,18 +4378,14 @@ func testExtmarks(v *Nvim) func(*testing.T) {
}

const (
wantExtMarkID = 2
wantLine = 1
wantCol = 3
wantLine = 1
wantCol = 3
)
var gotExtMarkID int
b.SetBufferExtmark(Buffer(0), nsID, wantLine, wantCol, make(map[string]interface{}), &gotExtMarkID)
if err := b.Execute(); err != nil {
t.Fatal(err)
}
if gotExtMarkID != wantExtMarkID {
t.Fatalf("got %d extMarkID but want %d", gotExtMarkID, wantExtMarkID)
}

var extmarks []ExtMark
b.BufferExtmarks(Buffer(0), nsID, 0, -1, make(map[string]interface{}), &extmarks)
Expand All @@ -4405,7 +4397,7 @@ func testExtmarks(v *Nvim) func(*testing.T) {
t.Fatalf("expected extmarks length to 1 but got %d", len(extmarks))
}
if extmarks[0].ID != gotExtMarkID {
t.Fatalf("got %d extMarkID but want %d", extmarks[0].ID, wantExtMarkID)
t.Fatalf("got %d extMarkID but want %d", extmarks[0].ID, gotExtMarkID)
}
if extmarks[0].Row != wantLine {
t.Fatalf("got %d extmarks Row but want %d", extmarks[0].Row, wantLine)
Expand Down

0 comments on commit 1987893

Please sign in to comment.