2022-08-17 03:28:41 +02:00
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[tokio::test(flavor = "multi_thread")]
|
|
|
|
async fn test_move_parent_node_end() -> anyhow::Result<()> {
|
|
|
|
let tests = vec![
|
|
|
|
// single cursor stays single cursor, first goes to end of current
|
|
|
|
// node, then parent
|
|
|
|
(
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {r##"
|
2022-08-17 03:28:41 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
"yes"
|
|
|
|
} else {
|
|
|
|
"no#["|]#
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"##},
|
2022-08-17 03:28:41 +02:00
|
|
|
"<A-e>",
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {"\
|
2022-08-17 03:28:41 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
\"yes\"
|
|
|
|
} else {
|
|
|
|
\"no\"#[\n|]#
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"},
|
2022-08-17 03:28:41 +02:00
|
|
|
),
|
|
|
|
(
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {"\
|
2022-08-17 03:28:41 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
\"yes\"
|
|
|
|
} else {
|
|
|
|
\"no\"#[\n|]#
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"},
|
2022-08-17 03:28:41 +02:00
|
|
|
"<A-e>",
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {"\
|
2022-08-17 03:28:41 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
\"yes\"
|
|
|
|
} else {
|
|
|
|
\"no\"
|
|
|
|
}#[\n|]#
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"},
|
2022-08-17 03:28:41 +02:00
|
|
|
),
|
|
|
|
// select mode extends
|
|
|
|
(
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {r##"
|
2022-08-17 03:28:41 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
"yes"
|
|
|
|
} else {
|
|
|
|
#["no"|]#
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"##},
|
2022-08-17 03:28:41 +02:00
|
|
|
"v<A-e><A-e>",
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {"\
|
2022-08-17 03:28:41 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
\"yes\"
|
|
|
|
} else {
|
|
|
|
#[\"no\"
|
|
|
|
}\n|]#
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"},
|
2022-08-17 03:28:41 +02:00
|
|
|
),
|
|
|
|
];
|
|
|
|
|
|
|
|
for test in tests {
|
|
|
|
test_with_config(AppBuilder::new().with_file("foo.rs", None), test).await?;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test(flavor = "multi_thread")]
|
|
|
|
async fn test_move_parent_node_start() -> anyhow::Result<()> {
|
|
|
|
let tests = vec![
|
|
|
|
// single cursor stays single cursor, first goes to end of current
|
|
|
|
// node, then parent
|
|
|
|
(
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {r##"
|
2022-08-17 03:28:41 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
"yes"
|
|
|
|
} else {
|
|
|
|
"no#["|]#
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"##},
|
2022-08-17 03:28:41 +02:00
|
|
|
"<A-b>",
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {"\
|
2022-08-17 03:28:41 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
\"yes\"
|
|
|
|
} else {
|
|
|
|
#[\"|]#no\"
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"},
|
2022-08-17 03:28:41 +02:00
|
|
|
),
|
|
|
|
(
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {"\
|
2022-08-17 03:28:41 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
\"yes\"
|
|
|
|
} else {
|
|
|
|
\"no\"#[\n|]#
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"},
|
2022-08-17 03:28:41 +02:00
|
|
|
"<A-b>",
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {"\
|
2022-08-17 03:28:41 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
\"yes\"
|
|
|
|
} else #[{|]#
|
|
|
|
\"no\"
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"},
|
2022-08-17 03:28:41 +02:00
|
|
|
),
|
|
|
|
(
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {"\
|
2022-08-17 03:28:41 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
\"yes\"
|
|
|
|
} else #[{|]#
|
|
|
|
\"no\"
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"},
|
2022-08-17 03:28:41 +02:00
|
|
|
"<A-b>",
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {"\
|
2022-08-17 03:28:41 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
\"yes\"
|
|
|
|
} #[e|]#lse {
|
|
|
|
\"no\"
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"},
|
2022-08-17 03:28:41 +02:00
|
|
|
),
|
|
|
|
// select mode extends
|
|
|
|
(
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {r##"
|
2022-08-17 03:28:41 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
"yes"
|
|
|
|
} else {
|
|
|
|
#["no"|]#
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"##},
|
2022-08-17 03:28:41 +02:00
|
|
|
"v<A-b><A-b>",
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {"\
|
2022-08-17 03:28:41 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
\"yes\"
|
|
|
|
} else #[|{
|
|
|
|
]#\"no\"
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"},
|
2022-08-17 03:28:41 +02:00
|
|
|
),
|
|
|
|
(
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {r##"
|
2022-08-17 03:28:41 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
"yes"
|
|
|
|
} else {
|
|
|
|
#["no"|]#
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"##},
|
2022-08-17 03:28:41 +02:00
|
|
|
"v<A-b><A-b><A-b>",
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {"\
|
2022-08-17 03:28:41 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
\"yes\"
|
|
|
|
} #[|else {
|
|
|
|
]#\"no\"
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"},
|
2022-08-17 03:28:41 +02:00
|
|
|
),
|
|
|
|
];
|
|
|
|
|
|
|
|
for test in tests {
|
|
|
|
test_with_config(AppBuilder::new().with_file("foo.rs", None), test).await?;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
2022-10-09 00:14:49 +02:00
|
|
|
|
|
|
|
#[tokio::test(flavor = "multi_thread")]
|
|
|
|
async fn test_smart_tab_move_parent_node_end() -> anyhow::Result<()> {
|
|
|
|
let tests = vec![
|
|
|
|
// single cursor stays single cursor, first goes to end of current
|
|
|
|
// node, then parent
|
|
|
|
(
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {r##"
|
2022-10-09 00:14:49 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
"yes"
|
|
|
|
} else {
|
|
|
|
"no#["|]#
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"##},
|
2022-10-09 00:14:49 +02:00
|
|
|
"i<tab>",
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {"\
|
2022-10-09 00:14:49 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
\"yes\"
|
|
|
|
} else {
|
|
|
|
\"no\"#[|\n]#
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"},
|
2022-10-09 00:14:49 +02:00
|
|
|
),
|
|
|
|
(
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {"\
|
2022-10-09 00:14:49 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
\"yes\"
|
|
|
|
} else {
|
|
|
|
\"no\"#[\n|]#
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"},
|
2022-10-09 00:14:49 +02:00
|
|
|
"i<tab>",
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {"\
|
2022-10-09 00:14:49 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
\"yes\"
|
|
|
|
} else {
|
|
|
|
\"no\"
|
|
|
|
}#[|\n]#
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"},
|
2022-10-09 00:14:49 +02:00
|
|
|
),
|
|
|
|
// appending to the end of a line should still look at the current
|
|
|
|
// line, not the next one
|
|
|
|
(
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {"\
|
2022-10-09 00:14:49 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
\"yes\"
|
|
|
|
} else {
|
|
|
|
\"no#[\"|]#
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"},
|
2022-10-09 00:14:49 +02:00
|
|
|
"a<tab>",
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {"\
|
2022-10-09 00:14:49 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
\"yes\"
|
|
|
|
} else {
|
|
|
|
\"no\"
|
|
|
|
}#[\n|]#
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"},
|
2022-10-09 00:14:49 +02:00
|
|
|
),
|
|
|
|
// before cursor is all whitespace, so insert tab
|
|
|
|
(
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {"\
|
2022-10-09 00:14:49 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
\"yes\"
|
|
|
|
} else {
|
|
|
|
#[\"no\"|]#
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"},
|
2022-10-09 00:14:49 +02:00
|
|
|
"i<tab>",
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {"\
|
2022-10-09 00:14:49 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
\"yes\"
|
|
|
|
} else {
|
|
|
|
#[|\"no\"]#
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"},
|
2022-10-09 00:14:49 +02:00
|
|
|
),
|
|
|
|
// if selection spans multiple lines, it should still only look at the
|
|
|
|
// line on which the head is
|
|
|
|
(
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {"\
|
2022-10-09 00:14:49 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
#[\"yes\"
|
|
|
|
} else {
|
|
|
|
\"no\"|]#
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"},
|
2022-10-09 00:14:49 +02:00
|
|
|
"a<tab>",
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {"\
|
2022-10-09 00:14:49 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
\"yes\"
|
|
|
|
} else {
|
|
|
|
\"no\"
|
|
|
|
}#[\n|]#
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"},
|
2022-10-09 00:14:49 +02:00
|
|
|
),
|
|
|
|
(
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {"\
|
2022-10-09 00:14:49 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
#[\"yes\"
|
|
|
|
} else {
|
|
|
|
\"no\"|]#
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"},
|
2022-10-09 00:14:49 +02:00
|
|
|
"i<tab>",
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {"\
|
2022-10-09 00:14:49 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
#[|\"yes\"
|
|
|
|
} else {
|
|
|
|
\"no\"]#
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"},
|
2022-10-09 00:14:49 +02:00
|
|
|
),
|
|
|
|
(
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {"\
|
2022-10-09 00:14:49 +02:00
|
|
|
fn foo() {
|
|
|
|
#[l|]#et result = if true {
|
|
|
|
#(\"yes\"
|
|
|
|
} else {
|
|
|
|
\"no\"|)#
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"},
|
2022-10-09 00:14:49 +02:00
|
|
|
"i<tab>",
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {"\
|
2022-10-09 00:14:49 +02:00
|
|
|
fn foo() {
|
|
|
|
#[|l]#et result = if true {
|
|
|
|
#(|\"yes\"
|
|
|
|
} else {
|
|
|
|
\"no\")#
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"},
|
2022-10-09 00:14:49 +02:00
|
|
|
),
|
|
|
|
(
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {"\
|
2022-10-09 00:14:49 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
\"yes\"#[\n|]#
|
|
|
|
} else {
|
|
|
|
\"no\"#(\n|)#
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"},
|
2022-10-09 00:14:49 +02:00
|
|
|
"i<tab>",
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {"\
|
2022-10-09 00:14:49 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
\"yes\"
|
|
|
|
}#[| ]#else {
|
|
|
|
\"no\"
|
|
|
|
}#(|\n)#
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"},
|
2022-10-09 00:14:49 +02:00
|
|
|
),
|
|
|
|
(
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {"\
|
2022-10-09 00:14:49 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
#[\"yes\"|]#
|
|
|
|
} else {
|
|
|
|
#(\"no\"|)#
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"},
|
2022-10-09 00:14:49 +02:00
|
|
|
"i<tab>",
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {"\
|
2022-10-09 00:14:49 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
#[|\"yes\"]#
|
|
|
|
} else {
|
|
|
|
#(|\"no\")#
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"},
|
2022-10-09 00:14:49 +02:00
|
|
|
),
|
|
|
|
// if any cursors are not preceded by all whitespace, then do the
|
|
|
|
// smart_tab action
|
|
|
|
(
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {"\
|
2022-10-09 00:14:49 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
#[\"yes\"\n|]#
|
|
|
|
} else {
|
|
|
|
\"no#(\"\n|)#
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"},
|
2022-10-09 00:14:49 +02:00
|
|
|
"i<tab>",
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {"\
|
2022-10-09 00:14:49 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
\"yes\"
|
|
|
|
}#[| ]#else {
|
|
|
|
\"no\"
|
|
|
|
}#(|\n)#
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"},
|
2022-10-09 00:14:49 +02:00
|
|
|
),
|
|
|
|
// Ctrl-tab always inserts a tab
|
|
|
|
(
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {"\
|
2022-10-09 00:14:49 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
#[\"yes\"\n|]#
|
|
|
|
} else {
|
|
|
|
\"no#(\"\n|)#
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"},
|
2022-10-09 00:14:49 +02:00
|
|
|
"i<S-tab>",
|
2024-03-31 14:12:17 +02:00
|
|
|
indoc! {"\
|
2022-10-09 00:14:49 +02:00
|
|
|
fn foo() {
|
|
|
|
let result = if true {
|
|
|
|
#[|\"yes\"\n]#
|
|
|
|
} else {
|
|
|
|
\"no #(|\"\n)#
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 14:12:17 +02:00
|
|
|
"},
|
2022-10-09 00:14:49 +02:00
|
|
|
),
|
|
|
|
];
|
|
|
|
|
|
|
|
for test in tests {
|
|
|
|
test_with_config(AppBuilder::new().with_file("foo.rs", None), test).await?;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|