@@ -113,21 +113,8 @@ func testBufAttach(v *Nvim) func(*testing.T) {
113
113
return func (t * testing.T ) {
114
114
clearBuffer (t , v , 0 ) // clear curret buffer text
115
115
116
- type ChangedtickEvent struct {
117
- Buffer Buffer
118
- Changetick int64
119
- }
120
- type BufLinesEvent struct {
121
- Buffer Buffer
122
- Changetick int64
123
- FirstLine int64
124
- LastLine int64
125
- LineData string
126
- IsMultipart bool
127
- }
128
-
129
116
changedtickChan := make (chan * ChangedtickEvent )
130
- v .RegisterHandler ("nvim_buf_changedtick_event" , func (changedtickEvent ... interface {}) {
117
+ v .RegisterHandler (EventBufChangedtick , func (changedtickEvent ... interface {}) {
131
118
ev := & ChangedtickEvent {
132
119
Buffer : changedtickEvent [0 ].(Buffer ),
133
120
Changetick : changedtickEvent [1 ].(int64 ),
@@ -136,18 +123,28 @@ func testBufAttach(v *Nvim) func(*testing.T) {
136
123
})
137
124
138
125
bufLinesChan := make (chan * BufLinesEvent )
139
- v .RegisterHandler ("nvim_buf_lines_event" , func (bufLinesEvent ... interface {}) {
126
+ v .RegisterHandler (EventBufLines , func (bufLinesEvent ... interface {}) {
140
127
ev := & BufLinesEvent {
141
128
Buffer : bufLinesEvent [0 ].(Buffer ),
142
129
Changetick : bufLinesEvent [1 ].(int64 ),
143
130
FirstLine : bufLinesEvent [2 ].(int64 ),
144
131
LastLine : bufLinesEvent [3 ].(int64 ),
145
- LineData : fmt .Sprint (bufLinesEvent [4 ]),
146
132
IsMultipart : bufLinesEvent [5 ].(bool ),
147
133
}
134
+ for _ , line := range bufLinesEvent [4 ].([]interface {}) {
135
+ ev .LineData = append (ev .LineData , line .(string ))
136
+ }
148
137
bufLinesChan <- ev
149
138
})
150
139
140
+ bufDetachChan := make (chan * BufDetachEvent )
141
+ v .RegisterHandler (EventBufDetach , func (bufDetachEvent ... interface {}) {
142
+ ev := & BufDetachEvent {
143
+ Buffer : bufDetachEvent [0 ].(Buffer ),
144
+ }
145
+ bufDetachChan <- ev
146
+ })
147
+
151
148
ok , err := v .AttachBuffer (0 , false , make (map [string ]interface {})) // first 0 arg refers to the current buffer
152
149
if err != nil {
153
150
t .Fatal (err )
@@ -157,17 +154,20 @@ func testBufAttach(v *Nvim) func(*testing.T) {
157
154
}
158
155
159
156
changedtickExpected := & ChangedtickEvent {
160
- Buffer : 1 ,
157
+ Buffer : Buffer ( 1 ) ,
161
158
Changetick : 3 ,
162
159
}
163
160
bufLinesEventExpected := & BufLinesEvent {
164
- Buffer : 1 ,
161
+ Buffer : Buffer ( 1 ) ,
165
162
Changetick : 4 ,
166
163
FirstLine : 0 ,
167
164
LastLine : 1 ,
168
- LineData : "[test]" ,
165
+ LineData : [] string { "foo" , "bar" , "baz" , "qux" , "quux" , "quuz" } ,
169
166
IsMultipart : false ,
170
167
}
168
+ bufDetachEventExpected := & BufDetachEvent {
169
+ Buffer : Buffer (1 ),
170
+ }
171
171
172
172
var numEvent int64 // add and load should be atomically
173
173
errc := make (chan error )
@@ -176,7 +176,7 @@ func testBufAttach(v *Nvim) func(*testing.T) {
176
176
for {
177
177
select {
178
178
default :
179
- if atomic .LoadInt64 (& numEvent ) == 2 { // end buf_attach test when handle 2 event
179
+ if atomic .LoadInt64 (& numEvent ) == 3 { // end buf_attach test when handle 2 event
180
180
done <- struct {}{}
181
181
return
182
182
}
@@ -190,6 +190,11 @@ func testBufAttach(v *Nvim) func(*testing.T) {
190
190
errc <- fmt .Errorf ("bufLines = %+v, want %+v" , bufLines , expected )
191
191
}
192
192
atomic .AddInt64 (& numEvent , 1 )
193
+ case detach := <- bufDetachChan :
194
+ if expected := bufDetachEventExpected ; ! reflect .DeepEqual (detach , expected ) {
195
+ errc <- fmt .Errorf ("bufDetach = %+v, want %+v" , detach , expected )
196
+ }
197
+ atomic .AddInt64 (& numEvent , 1 )
193
198
}
194
199
}
195
200
}()
@@ -199,8 +204,12 @@ func testBufAttach(v *Nvim) func(*testing.T) {
199
204
close (errc )
200
205
}()
201
206
202
- test := []byte ("test" )
203
- if err := v .SetBufferLines (0 , 0 , - 1 , true , bytes .Fields (test )); err != nil { // first 0 arg refers to the current buffer
207
+ test := [][]byte {[]byte ("foo" ), []byte ("bar" ), []byte ("baz" ), []byte ("qux" ), []byte ("quux" ), []byte ("quuz" )}
208
+ if err := v .SetBufferLines (Buffer (0 ), 0 , - 1 , true , test ); err != nil { // first 0 arg refers to the current buffer
209
+ t .Fatal (err )
210
+ }
211
+
212
+ if detached , err := v .DetachBuffer (Buffer (0 )); err != nil || ! detached {
204
213
t .Fatal (err )
205
214
}
206
215
0 commit comments