reovim-module-vim 0.14.4

Vim policy module for reovim - keybindings and behavior
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
//! E2E tests for vim operator + text object bindings.
//!
//! Tests verify that operator+textobject combinations (diw, ciw, yiw, etc.)
//! work correctly through the full server/client gRPC v2 stack.
//!
//! These live in the vim module because they test vim keybindings
//! (`operator_modes.rs`), not the textobjects module itself.
//!
//! # Test Coverage Matrix
//!
//! ```text
//!  Text Object  | d (delete) | c (change) | y (yank) | StepTest
//! ──────────────┼────────────┼────────────┼──────────┼──────────
//!  iw  word     |     x      |     x      |    x     |    x
//!  aw  word     |     x      |            |          |
//!  iW  WORD     |     x      |            |          |
//!  aW  WORD     |     x      |            |          |
//!  i"  dquote   |     x      |     x      |    x     |
//!  a"  dquote   |     x      |            |          |
//!  i'  squote   |     x      |            |          |
//!  a'  squote   |     x      |            |          |
//!  i`  backtick |     x      |            |          |
//!  i(  paren    |     x      |     x      |          |
//!  a(  paren    |     x      |            |          |
//!  i[  bracket  |     x      |     x      |          |
//!  a[  bracket  |     x      |            |          |
//!  i{  brace    |     x      |     x      |          |
//!  a{  brace    |     x      |            |          |
//!  i<  angle    |     x      |            |          |
//!  a<  angle    |     x      |            |          |
//!  ip  para     |     x      |            |          |
//!  ap  para     |     x      |            |          |
//! ──────────────┼────────────┼────────────┼──────────┼──────────
//!  Total        |    19      |     5      |    2     |    2
//! ```
//!
//! # Running Tests
//!
//! ```bash
//! cargo test -p reovim-module-vim --test textobjects
//! ```

use reovim_testing::{IntegrationTest, StepTest};

// ============================================================================
// Delete + Word Text Objects
// ============================================================================

/// Test `diw` deletes inner word.
#[tokio::test]
async fn test_diw_delete_inner_word() {
    let result = IntegrationTest::with_modules(&["textobjects"])
        .await
        .with_buffer("hello world test")
        .with_cursor_at(0, 7) // On 'o' of 'world'
        .send_keys("diw")
        .run()
        .await;
    result.assert_buffer_eq("hello  test");
}

/// Test `daw` deletes a word (with surrounding whitespace).
#[tokio::test]
async fn test_daw_delete_a_word() {
    let result = IntegrationTest::with_modules(&["textobjects"])
        .await
        .with_buffer("hello world test")
        .with_cursor_at(0, 6) // On 'w' of 'world'
        .send_keys("daw")
        .run()
        .await;
    result.assert_buffer_eq("hello test");
}

/// Test `di"` deletes inside double quotes.
#[tokio::test]
async fn test_di_double_quote_delete_inside() {
    let result = IntegrationTest::with_modules(&["textobjects"])
        .await
        .with_buffer(r#"say "hello" please"#)
        .with_cursor_at(0, 5) // On '"'
        .send_keys("di\"")
        .run()
        .await;
    result.assert_buffer_eq(r#"say "" please"#);
}

/// Test `ci{` changes inside braces.
#[tokio::test]
async fn test_ci_brace_change_inside() {
    let result = IntegrationTest::with_modules(&["textobjects"])
        .await
        .with_buffer("fn() { old }")
        .with_cursor_at(0, 7) // Inside braces
        .send_keys("ci{new<Esc>")
        .run()
        .await;
    result.assert_buffer_eq("fn() {new}");
}

// ============================================================================
// Delete + Big Word Text Objects
// ============================================================================

/// Test `diW` deletes inner WORD (non-whitespace sequence).
#[tokio::test]
async fn test_di_big_word() {
    let result = IntegrationTest::with_modules(&["textobjects"])
        .await
        .with_buffer("hello foo.bar test")
        .with_cursor_at(0, 7) // On '.' of 'foo.bar'
        .send_keys("diW")
        .run()
        .await;
    result.assert_buffer_eq("hello  test");
}

/// Test `daW` deletes a WORD with surrounding whitespace.
#[tokio::test]
async fn test_da_big_word() {
    let result = IntegrationTest::with_modules(&["textobjects"])
        .await
        .with_buffer("hello foo.bar test")
        .with_cursor_at(0, 7) // On '.' of 'foo.bar'
        .send_keys("daW")
        .run()
        .await;
    result.assert_buffer_eq("hello test");
}

// ============================================================================
// Delete + Quote Text Objects
// ============================================================================

/// Test `da"` deletes around double quotes (including quotes).
#[tokio::test]
async fn test_da_double_quote() {
    let result = IntegrationTest::with_modules(&["textobjects"])
        .await
        .with_buffer(r#"say "hello" please"#)
        .with_cursor_at(0, 5) // Inside quotes
        .send_keys("da\"")
        .run()
        .await;
    result.assert_buffer_eq("say  please");
}

/// Test `di'` deletes inside single quotes.
#[tokio::test]
async fn test_di_single_quote() {
    let result = IntegrationTest::with_modules(&["textobjects"])
        .await
        .with_buffer("say 'hello' please")
        .with_cursor_at(0, 5) // Inside quotes
        .send_keys("di'")
        .run()
        .await;
    result.assert_buffer_eq("say '' please");
}

/// Test `da'` deletes around single quotes.
#[tokio::test]
async fn test_da_single_quote() {
    let result = IntegrationTest::with_modules(&["textobjects"])
        .await
        .with_buffer("say 'hello' please")
        .with_cursor_at(0, 5) // Inside quotes
        .send_keys("da'")
        .run()
        .await;
    result.assert_buffer_eq("say  please");
}

/// Test `di`` ` deletes inside backticks.
#[tokio::test]
async fn test_di_backtick() {
    let result = IntegrationTest::with_modules(&["textobjects"])
        .await
        .with_buffer("say `hello` please")
        .with_cursor_at(0, 5) // Inside backticks
        .send_keys("di`")
        .run()
        .await;
    result.assert_buffer_eq("say `` please");
}

// ============================================================================
// Delete + Bracket Text Objects
// ============================================================================

/// Test `di(` deletes inside parentheses.
#[tokio::test]
async fn test_di_paren() {
    let result = IntegrationTest::with_modules(&["textobjects"])
        .await
        .with_buffer("fn(arg1, arg2)")
        .with_cursor_at(0, 4) // Inside parens
        .send_keys("di(")
        .run()
        .await;
    result.assert_buffer_eq("fn()");
}

/// Test `da(` deletes around parentheses.
#[tokio::test]
async fn test_da_paren() {
    let result = IntegrationTest::with_modules(&["textobjects"])
        .await
        .with_buffer("fn(arg1, arg2) end")
        .with_cursor_at(0, 4) // Inside parens
        .send_keys("da(")
        .run()
        .await;
    result.assert_buffer_eq("fn end");
}

/// Test `di[` deletes inside square brackets.
#[tokio::test]
async fn test_di_bracket() {
    let result = IntegrationTest::with_modules(&["textobjects"])
        .await
        .with_buffer("arr[1, 2, 3]")
        .with_cursor_at(0, 5) // Inside brackets
        .send_keys("di[")
        .run()
        .await;
    result.assert_buffer_eq("arr[]");
}

/// Test `da[` deletes around square brackets.
#[tokio::test]
async fn test_da_bracket() {
    let result = IntegrationTest::with_modules(&["textobjects"])
        .await
        .with_buffer("arr[1, 2, 3] end")
        .with_cursor_at(0, 5) // Inside brackets
        .send_keys("da[")
        .run()
        .await;
    result.assert_buffer_eq("arr end");
}

/// Test `di{` deletes inside braces.
#[tokio::test]
async fn test_di_brace() {
    let result = IntegrationTest::with_modules(&["textobjects"])
        .await
        .with_buffer("fn() { body }")
        .with_cursor_at(0, 7) // Inside braces
        .send_keys("di{")
        .run()
        .await;
    result.assert_buffer_eq("fn() {}");
}

/// Test `da{` deletes around braces.
#[tokio::test]
async fn test_da_brace() {
    let result = IntegrationTest::with_modules(&["textobjects"])
        .await
        .with_buffer("fn() { body } end")
        .with_cursor_at(0, 7) // Inside braces
        .send_keys("da{")
        .run()
        .await;
    result.assert_buffer_eq("fn()  end");
}

/// Test `di<` deletes inside angle brackets.
/// Note: `<lt>` is vim notation for literal `<`.
#[tokio::test]
async fn test_di_angle() {
    let result = IntegrationTest::with_modules(&["textobjects"])
        .await
        .with_buffer("<div>content</div>")
        .with_cursor_at(0, 1) // Inside angle brackets
        .send_keys("di<lt>")
        .run()
        .await;
    result.assert_buffer_eq("<>content</div>");
}

/// Test `da<` deletes around angle brackets.
/// Note: `<lt>` is vim notation for literal `<`.
#[tokio::test]
async fn test_da_angle() {
    let result = IntegrationTest::with_modules(&["textobjects"])
        .await
        .with_buffer("<div> rest")
        .with_cursor_at(0, 1) // Inside angle brackets
        .send_keys("da<lt>")
        .run()
        .await;
    result.assert_buffer_eq(" rest");
}

// ============================================================================
// Delete + Paragraph Text Objects
// ============================================================================

/// Test `dip` deletes inner paragraph (contiguous non-blank lines).
#[tokio::test]
async fn test_dip_paragraph() {
    let result = IntegrationTest::with_modules(&["textobjects"])
        .await
        .with_buffer("line1\nline2\n\nline3")
        .send_keys("dip")
        .run()
        .await;
    result.assert_buffer_contains("line3");
}

/// Test `dap` deletes a paragraph (including surrounding blank lines).
#[tokio::test]
async fn test_dap_paragraph() {
    let result = IntegrationTest::with_modules(&["textobjects"])
        .await
        .with_buffer("line1\nline2\n\nline3")
        .send_keys("dap")
        .run()
        .await;
    result.assert_buffer_eq("line3");
}

// ============================================================================
// Change + Text Objects
// ============================================================================

/// Test `ciw` changes inner word.
#[tokio::test]
async fn test_ciw_change_word() {
    let result = IntegrationTest::with_modules(&["textobjects"])
        .await
        .with_buffer("old word here")
        .with_cursor_at(0, 4) // On 'w' of 'word'
        .send_keys("ciwnew<Esc>")
        .run()
        .await;
    result.assert_buffer_eq("old new here");
}

/// Test `ci"` changes inside double quotes.
#[tokio::test]
async fn test_ci_double_quote() {
    let result = IntegrationTest::with_modules(&["textobjects"])
        .await
        .with_buffer(r#"say "old" please"#)
        .with_cursor_at(0, 5) // Inside quotes
        .send_keys("ci\"new<Esc>")
        .run()
        .await;
    result.assert_buffer_eq(r#"say "new" please"#);
}

/// Test `ci(` changes inside parentheses.
#[tokio::test]
async fn test_ci_paren() {
    let result = IntegrationTest::with_modules(&["textobjects"])
        .await
        .with_buffer("fn(old)")
        .with_cursor_at(0, 3) // Inside parens
        .send_keys("ci(x<Esc>")
        .run()
        .await;
    result.assert_buffer_eq("fn(x)");
}

/// Test `ci[` changes inside square brackets.
#[tokio::test]
async fn test_ci_bracket() {
    let result = IntegrationTest::with_modules(&["textobjects"])
        .await
        .with_buffer("a[old]")
        .with_cursor_at(0, 2) // Inside brackets
        .send_keys("ci[x<Esc>")
        .run()
        .await;
    result.assert_buffer_eq("a[x]");
}

// ============================================================================
// Yank + Text Objects (verified via paste)
// ============================================================================

/// Test `yiw` yanks inner word, verified by pasting.
#[tokio::test]
async fn test_yiw_paste() {
    let result = IntegrationTest::with_modules(&["textobjects"])
        .await
        .with_buffer("hello world")
        .send_keys("yiw$p")
        .run()
        .await;
    result.assert_buffer_contains("hello");
    // Buffer should have "hello" at start and appended after last char
    let content = &result.buffer_content;
    assert!(
        content.matches("hello").count() >= 2,
        "Expected 'hello' to appear at least twice after yiw$p, got: {content}"
    );
}

/// Test `yi"` yanks inside quotes, verified by pasting.
#[tokio::test]
async fn test_yi_quote_paste() {
    let result = IntegrationTest::with_modules(&["textobjects"])
        .await
        .with_buffer(r#"say "hi" end"#)
        .with_cursor_at(0, 5) // Inside quotes
        .send_keys("yi\"$p")
        .run()
        .await;
    result.assert_buffer_contains("hi");
}

// ============================================================================
// StepTest: Mode Transitions
// ============================================================================

/// Test delete + text object mode transitions: d enters delete mode, iw completes.
#[tokio::test]
async fn test_delete_textobj_mode_transition() {
    let trace = StepTest::with_modules(&["textobjects"])
        .await
        .with_buffer("hello world test")
        .with_cursor_at(0, 6)
        .step("d")
        .expect_mode_contains("delete")
        .step("iw")
        .expect_buffer("hello  test")
        .run()
        .await;
    trace.assert_ok();
}

/// Test change + text object enters insert mode after completion.
#[tokio::test]
async fn test_change_textobj_enters_insert() {
    let trace = StepTest::with_modules(&["textobjects"])
        .await
        .with_buffer("hello world test")
        .with_cursor_at(0, 6)
        .step("c")
        .expect_mode_contains("change")
        .step("iw")
        .expect_mode_contains("insert")
        .run()
        .await;
    trace.assert_ok();
}