| 1 |
use super::*; |
| 2 |
|
| 3 |
use helix_core::diagnostic::Severity; |
| 4 |
|
| 5 |
#[tokio::test(flavor = "multi_thread")] |
| 6 |
async fn history_completion() -> anyhow::Result<()> { |
| 7 |
test_key_sequence( |
| 8 |
&mut AppBuilder::new().build()?, |
| 9 |
Some(":asdf<ret>:theme d<C-n><tab>"), |
| 10 |
Some(&|app| { |
| 11 |
assert!(!app.editor.is_err()); |
| 12 |
}), |
| 13 |
false, |
| 14 |
) |
| 15 |
.await?; |
| 16 |
|
| 17 |
Ok(()) |
| 18 |
} |
| 19 |
|
| 20 |
#[tokio::test(flavor = "multi_thread")] |
| 21 |
async fn prompt_reset_anchor() -> anyhow::Result<()> { |
| 22 |
test_key_sequence( |
| 23 |
&mut AppBuilder::new().build()?, |
| 24 |
Some(":string wider than the terminal window causing the anchor location to be non zero which would panic when the line is deleted<C-u>"), |
| 25 |
Some(&|app| { |
| 26 |
assert!(!app.editor.is_err()); |
| 27 |
}), |
| 28 |
false, |
| 29 |
) |
| 30 |
.await?; |
| 31 |
|
| 32 |
Ok(()) |
| 33 |
} |
| 34 |
|
| 35 |
async fn test_statusline( |
| 36 |
line: &str, |
| 37 |
expected_status: &str, |
| 38 |
expected_severity: Severity, |
| 39 |
) -> anyhow::Result<()> { |
| 40 |
test_key_sequence( |
| 41 |
&mut AppBuilder::new().build()?, |
| 42 |
Some(&format!("{line}<ret>")), |
| 43 |
Some(&|app| { |
| 44 |
let (status, &severity) = app.editor.get_status().unwrap(); |
| 45 |
assert_eq!( |
| 46 |
severity, expected_severity, |
| 47 |
"'{line}' printed {severity:?}: {status}" |
| 48 |
); |
| 49 |
assert_eq!(status.as_ref(), expected_status); |
| 50 |
}), |
| 51 |
false, |
| 52 |
) |
| 53 |
.await |
| 54 |
} |
| 55 |
|
| 56 |
#[tokio::test(flavor = "multi_thread")] |
| 57 |
async fn variable_expansion() -> anyhow::Result<()> { |
| 58 |
test_statusline(r#":echo %{cursor_line}"#, "1", Severity::Info).await?; |
| 59 |
|
| 60 |
test_statusline( |
| 61 |
r#":echo "line%{cursor_line}line""#, |
| 62 |
"line1line", |
| 63 |
Severity::Info, |
| 64 |
) |
| 65 |
.await?; |
| 66 |
|
| 67 |
test_statusline( |
| 68 |
r#":echo "%%{cursor_line}""#, |
| 69 |
"%{cursor_line}", |
| 70 |
Severity::Info, |
| 71 |
) |
| 72 |
.await?; |
| 73 |
|
| 74 |
Ok(()) |
| 75 |
} |
| 76 |
|
| 77 |
#[tokio::test(flavor = "multi_thread")] |
| 78 |
async fn unicode_expansion() -> anyhow::Result<()> { |
| 79 |
test_statusline(r#":echo %u{20}"#, " ", Severity::Info).await?; |
| 80 |
test_statusline(r#":echo %u{0020}"#, " ", Severity::Info).await?; |
| 81 |
test_statusline(r#":echo %u{25CF}"#, "●", Severity::Info).await?; |
| 82 |
|
| 83 |
test_statusline( |
| 84 |
r#":echo %u{deadbeef}"#, |
| 85 |
"'echo': could not interpret 'deadbeef' as a Unicode character code", |
| 86 |
Severity::Error, |
| 87 |
) |
| 88 |
.await?; |
| 89 |
|
| 90 |
Ok(()) |
| 91 |
} |
| 92 |
|
| 93 |
#[cfg(unix)] |
| 94 |
#[tokio::test(flavor = "multi_thread")] |
| 95 |
async fn shell_expansion() -> anyhow::Result<()> { |
| 96 |
test_statusline( |
| 97 |
r#":echo %sh{echo "hello world"}"#, |
| 98 |
"hello world", |
| 99 |
Severity::Info, |
| 100 |
) |
| 101 |
.await?; |
| 102 |
|
| 103 |
|
| 104 |
test_statusline(":echo %sh{echo '%{cursor_line}'}", "1", Severity::Info).await?; |
| 105 |
|
| 106 |
Ok(()) |
| 107 |
} |
| 108 |
|
| 109 |
#[tokio::test(flavor = "multi_thread")] |
| 110 |
async fn register_expansion() -> anyhow::Result<()> { |
| 111 |
test_statusline( |
| 112 |
r#":set-register a hello world<ret>:echo %reg{a}"#, |
| 113 |
"hello world", |
| 114 |
Severity::Info, |
| 115 |
) |
| 116 |
.await?; |
| 117 |
test_statusline(r#":echo %reg{a}"#, "", Severity::Info).await?; |
| 118 |
test_statusline( |
| 119 |
r#":echo %reg{abc}"#, |
| 120 |
"'echo': Invalid register `abc`: should only be a single character", |
| 121 |
Severity::Error, |
| 122 |
) |
| 123 |
.await?; |
| 124 |
|
| 125 |
|
| 126 |
test_statusline( |
| 127 |
r#":set-register a b<ret>:set-register b hello<ret>:echo %reg{%reg{a}}"#, |
| 128 |
"'echo': Invalid register `%reg{a}`: should only be a single character", |
| 129 |
Severity::Error, |
| 130 |
) |
| 131 |
.await?; |
| 132 |
test_statusline( |
| 133 |
r#":set-register a hello<ret>:set-register b %%reg{a}<ret>:echo %reg{b}"#, |
| 134 |
"%reg{a}", |
| 135 |
Severity::Info, |
| 136 |
) |
| 137 |
.await?; |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
test_statusline( |
| 142 |
r#":set-register a hello<ret>:set-register b %reg{a}<ret>:echo %reg{b}"#, |
| 143 |
"hello", |
| 144 |
Severity::Info, |
| 145 |
) |
| 146 |
.await?; |
| 147 |
|
| 148 |
Ok(()) |
| 149 |
} |
| 150 |
|
| 151 |
#[tokio::test(flavor = "multi_thread")] |
| 152 |
async fn percent_escaping() -> anyhow::Result<()> { |
| 153 |
test_statusline( |
| 154 |
r#":sh echo hello 10%"#, |
| 155 |
"'run-shell-command': '%' was not properly escaped. Please use '%%'", |
| 156 |
Severity::Error, |
| 157 |
) |
| 158 |
.await?; |
| 159 |
Ok(()) |
| 160 |
} |