@@ -254,4 +254,87 @@ describe("markdown-tools Commands", function()
254
254
-- For now, just check it was called.
255
255
select_template_spy :revert ()
256
256
end )
257
+
258
+ it (" should continue unordered list item on Enter" , function ()
259
+ -- Setup initial list item
260
+ vim .api .nvim_buf_set_lines (0 , 0 , - 1 , false , { " - List item 1" })
261
+ vim .api .nvim_win_set_cursor (0 , { 1 , # " - List item 1" }) -- Cursor at the end
262
+
263
+ -- Directly call the list continuation function
264
+ require (" markdown-tools.lists" ).continue_list_on_enter ()
265
+
266
+ -- Wait for potential async operations (though likely not needed now)
267
+ vim .wait (10 )
268
+
269
+ -- Assert new list item is created and cursor is positioned correctly
270
+ local expected_content = " - List item 1\n - "
271
+ luassert .equals (expected_content , get_buffer_content ())
272
+
273
+ -- Expect cursor at #marker - 1 due to observed test environment behavior
274
+ local expected_cursor = { 2 , # " - " - 1 } -- {2, 1}
275
+ local actual_cursor = vim .api .nvim_win_get_cursor (0 )
276
+ luassert .same (expected_cursor , actual_cursor )
277
+ end )
278
+
279
+ it (" should continue ordered list item on Enter" , function ()
280
+ -- Setup initial list item
281
+ vim .api .nvim_buf_set_lines (0 , 0 , - 1 , false , { " 1. List item 1" })
282
+ vim .api .nvim_win_set_cursor (0 , { 1 , # " 1. List item 1" }) -- Cursor at the end
283
+
284
+ -- Directly call the list continuation function
285
+ require (" markdown-tools.lists" ).continue_list_on_enter ()
286
+
287
+ -- Wait for potential async operations
288
+ vim .wait (10 )
289
+
290
+ -- Assert new list item is created and cursor is positioned correctly
291
+ local expected_content = " 1. List item 1\n 2. "
292
+ luassert .equals (expected_content , get_buffer_content ())
293
+
294
+ -- Expect cursor at #marker - 1 due to observed test environment behavior
295
+ local expected_cursor = { 2 , # " 2. " - 1 } -- {2, 2}
296
+ local actual_cursor = vim .api .nvim_win_get_cursor (0 )
297
+ luassert .same (expected_cursor , actual_cursor )
298
+ end )
299
+
300
+ it (" should continue checkbox list item on Enter" , function ()
301
+ -- Setup initial list item
302
+ vim .api .nvim_buf_set_lines (0 , 0 , - 1 , false , { " - [ ] List item 1" })
303
+ vim .api .nvim_win_set_cursor (0 , { 1 , # " - [ ] List item 1" }) -- Cursor at the end
304
+
305
+ -- Directly call the list continuation function
306
+ require (" markdown-tools.lists" ).continue_list_on_enter ()
307
+
308
+ -- Wait for potential async operations
309
+ vim .wait (10 )
310
+
311
+ -- Assert new list item is created and cursor is positioned correctly
312
+ local expected_content = " - [ ] List item 1\n - [ ] "
313
+ luassert .equals (expected_content , get_buffer_content ())
314
+
315
+ -- Expect cursor at #marker - 1 due to observed test environment behavior
316
+ local expected_cursor = { 2 , # " - [ ] " - 1 } -- {2, 5}
317
+ local actual_cursor = vim .api .nvim_win_get_cursor (0 )
318
+ luassert .same (expected_cursor , actual_cursor )
319
+ end )
320
+
321
+ it (" should remove list marker on Enter on empty list item" , function ()
322
+ -- Setup empty list item
323
+ vim .api .nvim_buf_set_lines (0 , 0 , - 1 , false , { " - List item 1" , " - " })
324
+ vim .api .nvim_win_set_cursor (0 , { 2 , # " - " }) -- Cursor at the end of the empty item marker
325
+
326
+ -- Directly call the list continuation function
327
+ require (" markdown-tools.lists" ).continue_list_on_enter ()
328
+
329
+ -- Wait for potential async operations
330
+ vim .wait (10 )
331
+
332
+ -- Assert the list marker is removed and an empty line is inserted
333
+ local expected_content = " - List item 1\n " -- The "- " line should be replaced by ""
334
+ luassert .equals (expected_content , get_buffer_content ())
335
+
336
+ local expected_cursor = { 2 , 0 } -- Line 2, column 0 (0-based)
337
+ local actual_cursor = vim .api .nvim_win_get_cursor (0 )
338
+ luassert .same (expected_cursor , actual_cursor )
339
+ end )
257
340
end )
0 commit comments