use super::*; #[tokio::test(flavor = "multi_thread")] async fn test_variable_expansion() -> anyhow::Result<()> { { let mut app = AppBuilder::new().build()?; test_key_sequence( &mut app, Some(":echo %{filename}"), 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(":echo %{basename}"), 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(":echo %{dirname}"), 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(":echo %{filename}"), 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(":echo %{basename}"), 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(":echo %{dirname}"), 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%:echo %{selection}"), 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("ihelixhelixhelix:echo %{linenumber}"), Some(&|app| { assert_eq!(app.editor.get_status().unwrap().0, "4"); }), false, ) .await?; } Ok(()) }