mirror of https://github.com/helix-editor/helix
test: write more tests for toggle comment, and add tests for toggle block comment
parent
7c24110061
commit
621dec74be
|
@ -653,22 +653,23 @@ async fn test_join_selections_space() -> anyhow::Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Comment and uncomment
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn test_injected_comments() -> anyhow::Result<()> {
|
||||
async fn test_injected_comment_tokens_simple() -> anyhow::Result<()> {
|
||||
// Uncomment inner injection
|
||||
test((
|
||||
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">
|
||||
// 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();
|
||||
</script>
|
||||
"#},
|
||||
":lang html<ret><C-c>",
|
||||
":lang html<ret> c",
|
||||
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">
|
||||
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();
|
||||
</script>
|
||||
"#},
|
||||
|
@ -678,37 +679,83 @@ async fn test_injected_comments() -> anyhow::Result<()> {
|
|||
// Comment inner injection
|
||||
test((
|
||||
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">
|
||||
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();
|
||||
</script>
|
||||
"#},
|
||||
":lang html<ret><C-c>",
|
||||
":lang html<ret> c",
|
||||
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">
|
||||
// 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();
|
||||
</script>
|
||||
"#},
|
||||
))
|
||||
.await?;
|
||||
|
||||
// Comments two different injection layers with different comments
|
||||
// Block comment inner injection
|
||||
test((
|
||||
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">
|
||||
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>
|
||||
"#},
|
||||
":lang html<ret><C-c>",
|
||||
":lang html<ret> C",
|
||||
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">
|
||||
// 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();
|
||||
</script>
|
||||
"#},
|
||||
|
@ -718,17 +765,17 @@ async fn test_injected_comments() -> anyhow::Result<()> {
|
|||
// Uncomments two different injection layers with different comments
|
||||
test((
|
||||
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">
|
||||
// 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();
|
||||
</script>
|
||||
"#},
|
||||
":lang html<ret><C-c>",
|
||||
":lang html<ret> c",
|
||||
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">
|
||||
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();
|
||||
</script>
|
||||
"#},
|
||||
|
@ -738,17 +785,17 @@ async fn test_injected_comments() -> anyhow::Result<()> {
|
|||
// Works with multiple selections
|
||||
test((
|
||||
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">
|
||||
// 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();
|
||||
</script>
|
||||
"#},
|
||||
":lang html<ret><C-c>",
|
||||
":lang html<ret> c",
|
||||
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">
|
||||
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();
|
||||
</script>
|
||||
"#},
|
||||
|
@ -758,9 +805,9 @@ async fn test_injected_comments() -> anyhow::Result<()> {
|
|||
// Works with nested injection layers: html, js then css
|
||||
test((
|
||||
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">
|
||||
// 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();
|
||||
css`
|
||||
h#[tml {
|
||||
|
@ -769,11 +816,11 @@ async fn test_injected_comments() -> anyhow::Result<()> {
|
|||
`
|
||||
</script>
|
||||
"#},
|
||||
":lang html<ret><C-c>",
|
||||
":lang html<ret> c",
|
||||
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">
|
||||
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();
|
||||
css`
|
||||
/* h#[tml { */
|
||||
|
@ -785,9 +832,71 @@ async fn test_injected_comments() -> anyhow::Result<()> {
|
|||
))
|
||||
.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(())
|
||||
}
|
||||
|
||||
/// 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")]
|
||||
async fn test_join_selections_comment() -> anyhow::Result<()> {
|
||||
test((
|
||||
|
|
7
lol.html
7
lol.html
|
@ -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">
|
||||
// C-c on this line should use the javascript comment token(s).
|
||||
foo();
|
||||
css`
|
||||
html {
|
||||
background-color: red;
|
||||
}
|
||||
`;
|
||||
</script>
|
||||
|
|
Loading…
Reference in New Issue