You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
helix/helix-term/tests/test/commands/variable_expansion.rs

184 lines
5.2 KiB
Rust

5 months ago
use super::*;
4 months ago
use std::borrow::Cow;
5 months ago
#[tokio::test(flavor = "multi_thread")]
async fn test_variable_expansion() -> anyhow::Result<()> {
{
let mut app = AppBuilder::new().build()?;
test_key_sequence(
&mut app,
Some("<esc>:echo %{filename}<ret>"),
Some(&|app| {
assert_eq!(
app.editor.get_status().unwrap().0,
helix_view::document::SCRATCH_BUFFER_NAME
);
}),
false,
)
.await?;
let mut app = AppBuilder::new().build()?;
5 months ago
test_key_sequence(
&mut app,
Some("<esc>:echo %{basename}<ret>"),
Some(&|app| {
assert_eq!(
app.editor.get_status().unwrap().0,
helix_view::document::SCRATCH_BUFFER_NAME
);
}),
false,
)
.await?;
let mut app = AppBuilder::new().build()?;
test_key_sequence(
&mut app,
Some("<esc>:echo %{dirname}<ret>"),
Some(&|app| {
assert_eq!(
app.editor.get_status().unwrap().0,
helix_view::document::SCRATCH_BUFFER_NAME
);
}),
false,
)
.await?;
}
{
let file = tempfile::NamedTempFile::new()?;
let mut app = AppBuilder::new().with_file(file.path(), None).build()?;
test_key_sequence(
&mut app,
Some("<esc>:echo %{filename}<ret>"),
Some(&|app| {
assert_eq!(
app.editor.get_status().unwrap().0,
helix_stdx::path::canonicalize(file.path())
.to_str()
.unwrap()
);
}),
false,
)
.await?;
let mut app = AppBuilder::new().with_file(file.path(), None).build()?;
test_key_sequence(
&mut app,
Some("<esc>:echo %{basename}<ret>"),
Some(&|app| {
assert_eq!(
app.editor.get_status().unwrap().0,
file.path().file_name().unwrap().to_str().unwrap()
);
}),
false,
)
.await?;
let mut app = AppBuilder::new().with_file(file.path(), None).build()?;
test_key_sequence(
&mut app,
Some("<esc>:echo %{dirname}<ret>"),
Some(&|app| {
assert_eq!(
app.editor.get_status().unwrap().0,
helix_stdx::path::canonicalize(file.path().parent().unwrap())
.to_str()
.unwrap()
);
}),
false,
)
.await?;
}
{
let file = tempfile::NamedTempFile::new()?;
let mut app = AppBuilder::new().with_file(file.path(), None).build()?;
test_key_sequence(
&mut app,
Some("ihelix<esc>%:echo %{selection}<ret>"),
Some(&|app| {
assert_eq!(app.editor.get_status().unwrap().0, "helix");
}),
false,
)
.await?;
}
{
let file = tempfile::NamedTempFile::new()?;
let mut app = AppBuilder::new().with_file(file.path(), None).build()?;
test_key_sequence(
&mut app,
Some("ihelix<ret>helix<ret>helix<ret><esc>:echo %{linenumber}<ret>"),
Some(&|app| {
assert_eq!(app.editor.get_status().unwrap().0, "4");
}),
false,
)
.await?;
4 months ago
let mut app = AppBuilder::new().build()?;
test_key_sequence(
&mut app,
Some("<esc>:echo %sh{echo %{filename}}<ret>"),
Some(&|app| {
assert_eq!(
app.editor.get_status().unwrap().0,
helix_view::document::SCRATCH_BUFFER_NAME
);
}),
false,
)
.await?;
let mut app = AppBuilder::new().build()?;
test_key_sequence(
&mut app,
Some("<esc>:echo %sh{echo %{filename} %{linenumber}}<ret>"),
Some(&|app| {
assert_eq!(
app.editor.get_status().unwrap().0,
&Cow::from(format!(
"{} {}",
helix_view::document::SCRATCH_BUFFER_NAME,
1
))
);
}),
false,
)
.await?;
let mut app = AppBuilder::new().build()?;
test_key_sequence(
&mut app,
Some("<esc>:echo %sh{echo %{filename} %sh{echo %{filename}}}<ret>"),
Some(&|app| {
assert_eq!(
app.editor.get_status().unwrap().0,
&Cow::from(format!(
"{} {}",
helix_view::document::SCRATCH_BUFFER_NAME,
helix_view::document::SCRATCH_BUFFER_NAME
))
);
}),
false,
)
.await?;
5 months ago
}
Ok(())
}