diff --git a/helix-term/tests/integration.rs b/helix-term/tests/integration.rs index 5e418cebd..7d908cb7d 100644 --- a/helix-term/tests/integration.rs +++ b/helix-term/tests/integration.rs @@ -19,6 +19,7 @@ mod test { mod auto_pairs; mod command_line; mod commands; + mod comments; mod languages; mod movement; mod splits; diff --git a/helix-term/tests/test/commands.rs b/helix-term/tests/test/commands.rs index 537bc4827..398ab025e 100644 --- a/helix-term/tests/test/commands.rs +++ b/helix-term/tests/test/commands.rs @@ -653,411 +653,6 @@ async fn test_join_selections_space() -> anyhow::Result<()> { Ok(()) } -/// Comment and uncomment -#[tokio::test(flavor = "multi_thread")] -async fn test_injected_comment_tokens_simple() -> anyhow::Result<()> { - // Uncomment inner injection - test(( - indoc! {r#"\ -

Comment toggle on this line should use the HTML comment token(s).

- - "#}, - ":lang html c", - indoc! {r#"\ -

Comment toggle on this line should use the HTML comment token(s).

- - "#}, - )) - .await?; - - // Comment inner injection - test(( - indoc! {r#"\ -

Comment toggle on this line should use the HTML comment token(s).

- - "#}, - ":lang html c", - indoc! {r#"\ -

Comment toggle on this line should use the HTML comment token(s).

- - "#}, - )) - .await?; - - // Block comment inner injection - test(( - indoc! {r#"\ -

Comment toggle on this line should use the HTML comment token(s).

- - "#}, - ":lang html C", - indoc! {r#"\ -

Comment toggle on this line should use the HTML comment token(s).

- - "#}, - )) - .await?; - - // Block uncomment inner injection - test(( - indoc! {r#"\ -

Comment toggle on this line should use the HTML comment token(s).

- - "#}, - ":lang html C", - indoc! {r#"\ -

Comment toggle on this line should use the HTML comment token(s).

- - "#}, - )) - .await?; - - Ok(()) -} - -/// Selections in different regions -#[tokio::test(flavor = "multi_thread")] -async fn test_injected_comment_tokens_multiple_selections() -> anyhow::Result<()> { - // Comments two different injection layers with different comments - test(( - indoc! {r#"\ -

Comment toggle #[|on this line ]#should use the HTML comment token(s).

- - "#}, - ":lang html c", - indoc! {r#"\ - - - "#}, - )) - .await?; - - // Uncomments two different injection layers with different comments - test(( - indoc! {r#"\ - - - "#}, - ":lang html c", - indoc! {r#"\ -

Comment toggle #[|on this line ]#should use the HTML comment token(s).

- - "#}, - )) - .await?; - - // Works with multiple selections - test(( - indoc! {r#"\ -

Comment toggle #(|on this line )#should use the HTML comment token(s).

- - "#}, - ":lang html c", - indoc! {r#"\ - - - "#}, - )) - .await?; - - // Works with nested injection layers: html, js then css - test(( - indoc! {r#"\ - - - "#}, - ":lang html c", - indoc! {r#"\ -

Comment toggle #(|on this line)# should use the HTML comment token(s).

- - "#}, - )) - .await?; - - // Works with block comment toggle across different layers - test(( - indoc! {r#"\ -

Comment toggle #(|on this line)# should use the HTML comment token(s).

- - "#}, - ":lang html C", - indoc! {r#"\ -

Comment toggle #(|)# should use the HTML comment token(s).

- - "#}, - )) - .await?; - - // Many selections on the same line - test(( - indoc! {r#"\ -

C#[|o]#mment t#(|o)#ggle #(|o)#n this line sh#(|o)#uld use the HTML c#(|o)#mment t#(|o)#ken(s).

- - "#}, - ":lang html C", - indoc! {r#"\ -

C#[|]#mment t#(|)#ggle #(|)#n this line sh#(|)#uld use the HTML c#(|)#mment t#(|)#ken(s).

- - "#}, - )) - .await?; - test(( - indoc! {r#"\ -

C#[|]#mment t#(|)#ggle #(|)#n this line sh#(|)#uld use the HTML c#(|)#mment t#(|)#ken(s).

- - "#}, - ":lang html C", - indoc! {r#"\ -

C#[|o]#mment t#(|o)#ggle #(|o)#n this line sh#(|o)#uld use the HTML c#(|o)#mment t#(|o)#ken(s).

- - "#}, - )) - .await?; - - // Many single-selections - test(( - indoc! {r#"\ -

C#[|o]#mment t#(|o)#ggle #(|o)#n this line sh#(|o)#uld use the HTML c#(|o)#mment t#(|o)#ken(s).

- - "#}, - ":lang html C", - indoc! {r#"\ -

C#[|]#mment t#(|)#ggle #(|)#n this line sh#(|)#uld use the HTML c#(|)#mment t#(|)#ken(s).

- - "#}, - )) - .await?; - test(( - indoc! {r#"\ -

C#[|]#mment t#(|)#ggle #(|)#n this line sh#(|)#uld use the HTML c#(|)#mment t#(|)#ken(s).

- - "#}, - ":lang html C", - indoc! {r#"\ -

C#[|o]#mment t#(|o)#ggle #(|o)#n this line sh#(|o)#uld use the HTML c#(|o)#mment t#(|o)#ken(s).

- - "#}, - )) - .await?; - - Ok(()) -} - -/// A selection that spans across several injections takes comment tokens -/// from the injection with the bigger scope -#[tokio::test(flavor = "multi_thread")] -async fn test_injected_comment_tokens_selection_across_different_layers() -> anyhow::Result<()> { - test(( - indoc! {r#"\ -

Comment tog#[|gle on this line should use the HTML comment token(s).

- - "#}, - ":lang html c", - indoc! {r#"\ - - - - foo(); - - "#}, - )) - .await?; - test(( - indoc! {r#"\ -

Comment tog#[|gle on this line should use the HTML comment token(s).

- - "#}, - ":lang html C", - indoc! {r#"\ -

Comment tog#[|]#le on this line should use the javascript comment token(s). - foo(); - - "#}, - )) - .await?; - - Ok(()) -} - -#[tokio::test(flavor = "multi_thread")] -async fn test_join_selections_comment() -> anyhow::Result<()> { - test(( - indoc! {"\ - /// #[a|]#bc - /// def - "}, - ":lang rustJ", - indoc! {"\ - /// #[a|]#bc def - "}, - )) - .await?; - - // Only join if the comment token matches the previous line. - test(( - indoc! {"\ - #[| // a - // b - /// c - /// d - e - /// f - // g]# - "}, - ":lang rustJ", - indoc! {"\ - #[| // a b /// c d e f // g]# - "}, - )) - .await?; - - test(( - "#[|\t// Join comments -\t// with indent]#", - ":lang goJ", - "#[|\t// Join comments with indent]#", - )) - .await?; - - Ok(()) -} - #[tokio::test(flavor = "multi_thread")] async fn test_read_file() -> anyhow::Result<()> { let mut file = tempfile::NamedTempFile::new()?; diff --git a/helix-term/tests/test/comments.rs b/helix-term/tests/test/comments.rs new file mode 100644 index 000000000..346c22f86 --- /dev/null +++ b/helix-term/tests/test/comments.rs @@ -0,0 +1,412 @@ +use helix_term::application::Application; + +use super::*; + +mod insert; +mod movement; +mod write; + +/// Comment and uncomment +#[tokio::test(flavor = "multi_thread")] +async fn test_injected_comment_tokens_simple() -> anyhow::Result<()> { + // Uncomment inner injection + test(( + indoc! {r#"\ +

Comment toggle on this line should use the HTML comment token(s).

+ + "#}, + ":lang html c", + indoc! {r#"\ +

Comment toggle on this line should use the HTML comment token(s).

+ + "#}, + )) + .await?; + + // Comment inner injection + test(( + indoc! {r#"\ +

Comment toggle on this line should use the HTML comment token(s).

+ + "#}, + ":lang html c", + indoc! {r#"\ +

Comment toggle on this line should use the HTML comment token(s).

+ + "#}, + )) + .await?; + + // Block comment inner injection + test(( + indoc! {r#"\ +

Comment toggle on this line should use the HTML comment token(s).

+ + "#}, + ":lang html C", + indoc! {r#"\ +

Comment toggle on this line should use the HTML comment token(s).

+ + "#}, + )) + .await?; + + // Block uncomment inner injection + test(( + indoc! {r#"\ +

Comment toggle on this line should use the HTML comment token(s).

+ + "#}, + ":lang html C", + indoc! {r#"\ +

Comment toggle on this line should use the HTML comment token(s).

+ + "#}, + )) + .await?; + + Ok(()) +} + +/// Selections in different regions +#[tokio::test(flavor = "multi_thread")] +async fn test_injected_comment_tokens_multiple_selections() -> anyhow::Result<()> { + // Comments two different injection layers with different comments + test(( + indoc! {r#"\ +

Comment toggle #[|on this line ]#should use the HTML comment token(s).

+ + "#}, + ":lang html c", + indoc! {r#"\ + + + "#}, + )) + .await?; + + // Uncomments two different injection layers with different comments + test(( + indoc! {r#"\ + + + "#}, + ":lang html c", + indoc! {r#"\ +

Comment toggle #[|on this line ]#should use the HTML comment token(s).

+ + "#}, + )) + .await?; + + // Works with multiple selections + test(( + indoc! {r#"\ +

Comment toggle #(|on this line )#should use the HTML comment token(s).

+ + "#}, + ":lang html c", + indoc! {r#"\ + + + "#}, + )) + .await?; + + // Works with nested injection layers: html, js then css + test(( + indoc! {r#"\ + + + "#}, + ":lang html c", + indoc! {r#"\ +

Comment toggle #(|on this line)# should use the HTML comment token(s).

+ + "#}, + )) + .await?; + + // Works with block comment toggle across different layers + test(( + indoc! {r#"\ +

Comment toggle #(|on this line)# should use the HTML comment token(s).

+ + "#}, + ":lang html C", + indoc! {r#"\ +

Comment toggle #(|)# should use the HTML comment token(s).

+ + "#}, + )) + .await?; + + // Many selections on the same line + test(( + indoc! {r#"\ +

C#[|o]#mment t#(|o)#ggle #(|o)#n this line sh#(|o)#uld use the HTML c#(|o)#mment t#(|o)#ken(s).

+ + "#}, + ":lang html C", + indoc! {r#"\ +

C#[|]#mment t#(|)#ggle #(|)#n this line sh#(|)#uld use the HTML c#(|)#mment t#(|)#ken(s).

+ + "#}, + )) + .await?; + test(( + indoc! {r#"\ +

C#[|]#mment t#(|)#ggle #(|)#n this line sh#(|)#uld use the HTML c#(|)#mment t#(|)#ken(s).

+ + "#}, + ":lang html C", + indoc! {r#"\ +

C#[|o]#mment t#(|o)#ggle #(|o)#n this line sh#(|o)#uld use the HTML c#(|o)#mment t#(|o)#ken(s).

+ + "#}, + )) + .await?; + + // Many single-selections + test(( + indoc! {r#"\ +

C#[|o]#mment t#(|o)#ggle #(|o)#n this line sh#(|o)#uld use the HTML c#(|o)#mment t#(|o)#ken(s).

+ + "#}, + ":lang html C", + indoc! {r#"\ +

C#[|]#mment t#(|)#ggle #(|)#n this line sh#(|)#uld use the HTML c#(|)#mment t#(|)#ken(s).

+ + "#}, + )) + .await?; + test(( + indoc! {r#"\ +

C#[|]#mment t#(|)#ggle #(|)#n this line sh#(|)#uld use the HTML c#(|)#mment t#(|)#ken(s).

+ + "#}, + ":lang html C", + indoc! {r#"\ +

C#[|o]#mment t#(|o)#ggle #(|o)#n this line sh#(|o)#uld use the HTML c#(|o)#mment t#(|o)#ken(s).

+ + "#}, + )) + .await?; + + Ok(()) +} + +/// A selection that spans across several injections takes comment tokens +/// from the injection with the bigger scope +#[tokio::test(flavor = "multi_thread")] +async fn test_injected_comment_tokens_selection_across_different_layers() -> anyhow::Result<()> { + test(( + indoc! {r#"\ +

Comment tog#[|gle on this line should use the HTML comment token(s).

+ + "#}, + ":lang html c", + indoc! {r#"\ + + + + foo(); + + "#}, + )) + .await?; + test(( + indoc! {r#"\ +

Comment tog#[|gle on this line should use the HTML comment token(s).

+ + "#}, + ":lang html C", + indoc! {r#"\ +

Comment tog#[|]#le on this line should use the javascript comment token(s). + foo(); + + "#}, + )) + .await?; + + Ok(()) +} + +#[tokio::test(flavor = "multi_thread")] +async fn test_join_selections_comment() -> anyhow::Result<()> { + test(( + indoc! {"\ + /// #[a|]#bc + /// def + "}, + ":lang rustJ", + indoc! {"\ + /// #[a|]#bc def + "}, + )) + .await?; + + // Only join if the comment token matches the previous line. + test(( + indoc! {"\ + #[| // a + // b + /// c + /// d + e + /// f + // g]# + "}, + ":lang rustJ", + indoc! {"\ + #[| // a b /// c d e f // g]# + "}, + )) + .await?; + + test(( + "#[|\t// Join comments +\t// with indent]#", + ":lang goJ", + "#[|\t// Join comments with indent]#", + )) + .await?; + + Ok(()) +}