Skip to content

Commit

Permalink
Add integration tests for line comment continuation
Browse files Browse the repository at this point in the history
  • Loading branch information
the-mikedavis authored and archseer committed Dec 5, 2024
1 parent 1e6fe00 commit fd3e889
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions helix-term/tests/test/commands/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,71 @@ async fn insert_newline_trim_trailing_whitespace() -> anyhow::Result<()> {

Ok(())
}

#[tokio::test(flavor = "multi_thread")]
async fn insert_newline_continue_line_comment() -> anyhow::Result<()> {
// `insert_newline` continues a single line comment
test((
indoc! {"\
// Hello world!#[|
]#
"},
":lang rust<ret>i<ret>",
indoc! {"\
// Hello world!
// #[|
]#
"},
))
.await?;

// The comment is not continued if the cursor is before the comment token. (Note that we
// are entering insert-mode with `I`.)
test((
indoc! {"\
// Hello world!#[|
]#
"},
":lang rust<ret>I<ret>",
indoc! {"\
\n#[/|]#/ Hello world!
"},
))
.await?;

// `insert_newline` again clears the whitespace on the first continued comment and continues
// the comment again.
test((
indoc! {"\
// Hello world!
// #[|
]#
"},
":lang rust<ret>i<ret>",
indoc! {"\
// Hello world!
//
// #[|
]#
"},
))
.await?;

// Line comment continuation and trailing whitespace is also trimmed when using
// `insert_newline` in the middle of a comment.
test((
indoc! {"\
//·hello····#[|·]#····world
"}
.replace('·', " "),
":lang rust<ret>i<ret>",
indoc! {"\
//·hello
//·#[|·]#····world
"}
.replace('·', " "),
))
.await?;

Ok(())
}

0 comments on commit fd3e889

Please sign in to comment.