test: write more tests for toggle comment, and add tests for toggle block comment

pull/12759/head
Nikita Revenco 2025-02-01 21:59:41 +00:00 committed by Nik Revenco
parent 7c24110061
commit 621dec74be
2 changed files with 142 additions and 38 deletions

View File

@ -653,22 +653,23 @@ async fn test_join_selections_space() -> anyhow::Result<()> {
Ok(()) Ok(())
} }
/// Comment and uncomment
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn test_injected_comments() -> anyhow::Result<()> { async fn test_injected_comment_tokens_simple() -> anyhow::Result<()> {
// Uncomment inner injection // Uncomment inner injection
test(( test((
indoc! {r#"\ indoc! {r#"\
<p>C-c on this line should use the HTML comment token(s).</p> <p>Comment toggle on this line should use the HTML comment token(s).</p>
<script type="text/javascript"> <script type="text/javascript">
// C-c#[| on this line s]#hould use the javascript comment token(s). // Comment toggle#[| on this line s]#hould use the javascript comment token(s).
foo(); foo();
</script> </script>
"#}, "#},
":lang html<ret><C-c>", ":lang html<ret> c",
indoc! {r#"\ indoc! {r#"\
<p>C-c on this line should use the HTML comment token(s).</p> <p>Comment toggle on this line should use the HTML comment token(s).</p>
<script type="text/javascript"> <script type="text/javascript">
C-c#[| on this line s]#hould use the javascript comment token(s). Comment toggle#[| on this line s]#hould use the javascript comment token(s).
foo(); foo();
</script> </script>
"#}, "#},
@ -678,37 +679,83 @@ async fn test_injected_comments() -> anyhow::Result<()> {
// Comment inner injection // Comment inner injection
test(( test((
indoc! {r#"\ indoc! {r#"\
<p>C-c on this line should use the HTML comment token(s).</p> <p>Comment toggle on this line should use the HTML comment token(s).</p>
<script type="text/javascript"> <script type="text/javascript">
C-c#[| on this line s]#hould use the javascript comment token(s). Comment toggle#[| on this line s]#hould use the javascript comment token(s).
foo(); foo();
</script> </script>
"#}, "#},
":lang html<ret><C-c>", ":lang html<ret> c",
indoc! {r#"\ indoc! {r#"\
<p>C-c on this line should use the HTML comment token(s).</p> <p>Comment toggle on this line should use the HTML comment token(s).</p>
<script type="text/javascript"> <script type="text/javascript">
// C-c#[| on this line s]#hould use the javascript comment token(s). // Comment toggle#[| on this line s]#hould use the javascript comment token(s).
foo(); foo();
</script> </script>
"#}, "#},
)) ))
.await?; .await?;
// Comments two different injection layers with different comments // Block comment inner injection
test(( test((
indoc! {r#"\ indoc! {r#"\
<p>C-c #[|on this line ]#should use the HTML comment token(s).</p> <p>Comment toggle on this line should use the HTML comment token(s).</p>
<script type="text/javascript"> <script type="text/javascript">
C-c #(|on this line )#should use the javascript comment token(s). Comment toggle#[| on this line s]#hould use the javascript comment token(s).
foo(); foo();
</script> </script>
"#}, "#},
":lang html<ret><C-c>", ":lang html<ret> C",
indoc! {r#"\ indoc! {r#"\
<!-- <p>C-c #[|on this line ]#should use the HTML comment token(s).</p> --> <p>Comment toggle on this line should use the HTML comment token(s).</p>
<script type="text/javascript"> <script type="text/javascript">
// C-c #(|on this line )#should use the javascript comment token(s). Comment toggle#[|/* on this line s*/]#hould use the javascript comment token(s).
foo();
</script>
"#},
))
.await?;
// Block uncomment inner injection
test((
indoc! {r#"\
<p>Comment toggle on this line should use the HTML comment token(s).</p>
<script type="text/javascript">
Comment toggle#[|/* on this line s*/]#hould use the javascript comment token(s).
foo();
</script>
"#},
":lang html<ret> C",
indoc! {r#"\
<p>Comment toggle on this line should use the HTML comment token(s).</p>
<script type="text/javascript">
Comment toggle#[| on this line s]#hould use the javascript comment token(s).
foo();
</script>
"#},
))
.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#"\
<p>Comment toggle #[|on this line ]#should use the HTML comment token(s).</p>
<script type="text/javascript">
Comment toggle #(|on this line )#should use the javascript comment token(s).
foo();
</script>
"#},
":lang html<ret> c",
indoc! {r#"\
<!-- <p>Comment toggle #[|on this line ]#should use the HTML comment token(s).</p> -->
<script type="text/javascript">
// Comment toggle #(|on this line )#should use the javascript comment token(s).
foo(); foo();
</script> </script>
"#}, "#},
@ -718,17 +765,17 @@ async fn test_injected_comments() -> anyhow::Result<()> {
// Uncomments two different injection layers with different comments // Uncomments two different injection layers with different comments
test(( test((
indoc! {r#"\ indoc! {r#"\
<!-- <p>C-c #[|on this line ]#should use the HTML comment token(s).</p> --> <!-- <p>Comment toggle #[|on this line ]#should use the HTML comment token(s).</p> -->
<script type="text/javascript"> <script type="text/javascript">
// C-c #(|on this line )#should use the javascript comment token(s). // Comment toggle #(|on this line )#should use the javascript comment token(s).
foo(); foo();
</script> </script>
"#}, "#},
":lang html<ret><C-c>", ":lang html<ret> c",
indoc! {r#"\ indoc! {r#"\
<p>C-c #[|on this line ]#should use the HTML comment token(s).</p> <p>Comment toggle #[|on this line ]#should use the HTML comment token(s).</p>
<script type="text/javascript"> <script type="text/javascript">
C-c #(|on this line )#should use the javascript comment token(s). Comment toggle #(|on this line )#should use the javascript comment token(s).
foo(); foo();
</script> </script>
"#}, "#},
@ -738,17 +785,17 @@ async fn test_injected_comments() -> anyhow::Result<()> {
// Works with multiple selections // Works with multiple selections
test(( test((
indoc! {r#"\ indoc! {r#"\
<p>C-c #(|on this line )#should use the HTML comment token(s).</p> <p>Comment toggle #(|on this line )#should use the HTML comment token(s).</p>
<script type="text/javascript"> <script type="text/javascript">
// C-c #[|on this line ]#should use the javascript comment token(s). // Comment toggle #[|on this line ]#should use the javascript comment token(s).
foo(); foo();
</script> </script>
"#}, "#},
":lang html<ret><C-c>", ":lang html<ret> c",
indoc! {r#"\ indoc! {r#"\
<!-- <p>C-c #(|on this line )#should use the HTML comment token(s).</p> --> <!-- <p>Comment toggle #(|on this line )#should use the HTML comment token(s).</p> -->
<script type="text/javascript"> <script type="text/javascript">
C-c #[|on this line ]#should use the javascript comment token(s). Comment toggle #[|on this line ]#should use the javascript comment token(s).
foo(); foo();
</script> </script>
"#}, "#},
@ -758,9 +805,9 @@ async fn test_injected_comments() -> anyhow::Result<()> {
// Works with nested injection layers: html, js then css // Works with nested injection layers: html, js then css
test(( test((
indoc! {r#"\ indoc! {r#"\
<!-- <p>C-c #(|on this line)# should use the HTML comment token(s).</p> --> <!-- <p>Comment toggle #(|on this line)# should use the HTML comment token(s).</p> -->
<script type="text/javascript"> <script type="text/javascript">
// C-c #(|on this line)# should use the javascript comment token(s). // Comment toggle #(|on this line)# should use the javascript comment token(s).
foo(); foo();
css` css`
h#[tml { h#[tml {
@ -769,11 +816,11 @@ async fn test_injected_comments() -> anyhow::Result<()> {
` `
</script> </script>
"#}, "#},
":lang html<ret><C-c>", ":lang html<ret> c",
indoc! {r#"\ indoc! {r#"\
<p>C-c #(|on this line)# should use the HTML comment token(s).</p> <p>Comment toggle #(|on this line)# should use the HTML comment token(s).</p>
<script type="text/javascript"> <script type="text/javascript">
C-c #(|on this line)# should use the javascript comment token(s). Comment toggle #(|on this line)# should use the javascript comment token(s).
foo(); foo();
css` css`
/* h#[tml { */ /* h#[tml { */
@ -785,9 +832,71 @@ async fn test_injected_comments() -> anyhow::Result<()> {
)) ))
.await?; .await?;
// Works with block comment toggle across different layers
test((
indoc! {r#"\
<p>Comment toggle #(|on this line )#should use the HTML comment token(s).</p>
<script type="text/javascript">
// Comment toggle #[|on this line ]#should use the javascript comment token(s).
foo();
</script>
"#},
":lang html<ret> C",
indoc! {r#"\
<p> C-c #(|<!-- on this line -->)# should use the HTML comment token(s). </p>
<script type="text/javascript">
// C-c #[|/* on this line */]# should use the javascript comment token(s).
foo();
</script>
"#},
))
.await?;
Ok(()) 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#"\
<p>Comment tog#[|gle on this line should use the HTML comment token(s).</p>
<script type="text/javascript">
// Comment togg]#le on this line should use the javascript comment token(s).
foo();
</script>
"#},
":lang html<ret> c",
indoc! {r#"\
<!-- <p>Comment tog#[|gle on this line should use the HTML comment token(s).</p> -->
<!-- <script type="text/javascript"> -->
<!-- // Comment togg]#le on this line should use the javascript comment token(s). -->
foo();
</script>
"#},
))
.await?;
test((
indoc! {r#"\
<p>Comment tog#[|gle on this line should use the HTML comment token(s).</p>
<script type="text/javascript">
// Comment togg]#le on this line should use the javascript comment token(s).
foo();
</script>
"#},
":lang html<ret> C",
indoc! {r#"\
<p>Comment tog#[|<!-- gle on this line should use the HTML comment token(s).</p>
<script type="text/javascript">
// Comment togg -->]#le on this line should use the javascript comment token(s).
foo();
</script>
"#},
))
.await?;
}
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn test_join_selections_comment() -> anyhow::Result<()> { async fn test_join_selections_comment() -> anyhow::Result<()> {
test(( test((

View File

@ -1,10 +1,5 @@
<!-- <p>C-c on this line should use the HTML comment token(s).</p> --> <p> C-c on this line should use the HTML comment token(s). </p>
<script type="text/javascript"> <script type="text/javascript">
// C-c on this line should use the javascript comment token(s). // C-c on this line should use the javascript comment token(s).
foo(); foo();
css`
html {
background-color: red;
}
`;
</script> </script>