Skip to content

Commit 23e69e8

Browse files
author
Piotr Gołąb
committed
Unit test moving lines and selections
1 parent 8011c44 commit 23e69e8

File tree

2 files changed

+164
-1
lines changed

2 files changed

+164
-1
lines changed

helix-term/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ helix-dap = { version = "0.6", path = "../helix-dap" }
3232
helix-loader = { version = "0.6", path = "../helix-loader" }
3333

3434
anyhow = "1"
35-
once_cell = "1.15"
35+
once_cell = "1.16"
3636
itertools = "0.10.5"
3737

3838
which = "4.2"

helix-term/tests/test/commands.rs

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,166 @@ async fn test_multi_selection_paste() -> anyhow::Result<()> {
215215

216216
Ok(())
217217
}
218+
219+
// Line selection movement tests
220+
221+
#[tokio::test(flavor = "multi_thread")]
222+
async fn test_move_selection_single_selection_up() -> anyhow::Result<()> {
223+
test((
224+
platform_line(indoc! {"
225+
aaaaaa
226+
bbbbbb
227+
cc#[|c]#ccc
228+
dddddd
229+
"})
230+
.as_str(),
231+
"<C-up>",
232+
platform_line(indoc! {"
233+
aaaaaa
234+
cc#[|c]#ccc
235+
bbbbbb
236+
dddddd
237+
"})
238+
.as_str(),
239+
))
240+
.await?;
241+
Ok(())
242+
}
243+
244+
#[tokio::test(flavor = "multi_thread")]
245+
async fn test_move_selection_single_selection_down() -> anyhow::Result<()> {
246+
test((
247+
platform_line(indoc! {"
248+
aa#[|a]#aaa
249+
bbbbbb
250+
cccccc
251+
dddddd
252+
"})
253+
.as_str(),
254+
"<C-down>",
255+
platform_line(indoc! {"
256+
bbbbbb
257+
aa#[|a]#aaa
258+
cccccc
259+
dddddd
260+
"})
261+
.as_str(),
262+
))
263+
.await?;
264+
Ok(())
265+
}
266+
267+
#[tokio::test(flavor = "multi_thread")]
268+
async fn test_move_selection_single_selection_top_up() -> anyhow::Result<()> {
269+
// if already on top of the file and going up, nothing should change
270+
test((
271+
platform_line(indoc! {"
272+
aa#[|a]#aaa
273+
bbbbbb
274+
cccccc
275+
dddddd"})
276+
.as_str(),
277+
"<C-up>",
278+
platform_line(indoc! {"
279+
aa#[|a]#aaa
280+
bbbbbb
281+
cccccc
282+
dddddd"})
283+
.as_str(),
284+
))
285+
.await?;
286+
Ok(())
287+
}
288+
289+
#[tokio::test(flavor = "multi_thread")]
290+
async fn test_move_selection_single_selection_bottom_down() -> anyhow::Result<()> {
291+
// If going down on the bottom line, nothing should change
292+
// Note that platform_line is not used here, because it inserts trailing
293+
// linebreak, making it impossible to test
294+
test((
295+
"aaaaaa\nbbbbbb\ncccccc\ndd#[|d]#ddd",
296+
"<C-down><C-down>",
297+
"aaaaaa\nbbbbbb\ncccccc\ndd#[|d]#ddd",
298+
))
299+
.await?;
300+
301+
Ok(())
302+
}
303+
304+
#[tokio::test(flavor = "multi_thread")]
305+
async fn test_move_selection_block_down() -> anyhow::Result<()> {
306+
test((
307+
platform_line(indoc! {"
308+
#[|aaaaaa
309+
bbbbbb
310+
ccc]#ccc
311+
dddddd
312+
eeeeee
313+
"})
314+
.as_str(),
315+
"<C-down>",
316+
platform_line(indoc! {"
317+
dddddd
318+
#[|aaaaaa
319+
bbbbbb
320+
ccc]#ccc
321+
eeeeee
322+
"})
323+
.as_str(),
324+
))
325+
.await?;
326+
327+
Ok(())
328+
}
329+
330+
#[tokio::test(flavor = "multi_thread")]
331+
async fn test_move_selection_block_up() -> anyhow::Result<()> {
332+
test((
333+
platform_line(indoc! {"
334+
aaaaaa
335+
bb#[bbbb
336+
ccc|]#ccc
337+
dddddd
338+
eeeeee
339+
"})
340+
.as_str(),
341+
"<C-up>",
342+
platform_line(indoc! {"
343+
bb#[bbbb
344+
ccc|]#ccc
345+
aaaaaa
346+
dddddd
347+
eeeeee
348+
"})
349+
.as_str(),
350+
))
351+
.await?;
352+
353+
Ok(())
354+
}
355+
356+
#[tokio::test(flavor = "multi_thread")]
357+
async fn test_move_two_cursors_down() -> anyhow::Result<()> {
358+
test((
359+
platform_line(indoc! {"
360+
aaaaaa
361+
bb#[|b]#bbb
362+
cccccc
363+
d#(dd|)#ddd
364+
eeeeee
365+
"})
366+
.as_str(),
367+
"<C-down>",
368+
platform_line(indoc! {"
369+
aaaaaa
370+
cccccc
371+
bb#[|b]#bbb
372+
eeeeee
373+
d#(dd|)#ddd
374+
"})
375+
.as_str(),
376+
))
377+
.await?;
378+
379+
Ok(())
380+
}

0 commit comments

Comments
 (0)