|
|
@ -8,8 +8,8 @@ use std::{
|
|
|
|
use anyhow::bail;
|
|
|
|
use anyhow::bail;
|
|
|
|
use crossterm::event::{Event, KeyEvent};
|
|
|
|
use crossterm::event::{Event, KeyEvent};
|
|
|
|
use helix_core::{diagnostic::Severity, test, Selection, Transaction};
|
|
|
|
use helix_core::{diagnostic::Severity, test, Selection, Transaction};
|
|
|
|
use helix_term::{application::Application, args::Args, config::Config};
|
|
|
|
use helix_term::{application::Application, args::Args, config::Config, keymap::merge_keys};
|
|
|
|
use helix_view::{doc, input::parse_macro, Editor};
|
|
|
|
use helix_view::{doc, editor::LspConfig, input::parse_macro, Editor};
|
|
|
|
use tempfile::NamedTempFile;
|
|
|
|
use tempfile::NamedTempFile;
|
|
|
|
use tokio_stream::wrappers::UnboundedReceiverStream;
|
|
|
|
use tokio_stream::wrappers::UnboundedReceiverStream;
|
|
|
|
|
|
|
|
|
|
|
@ -118,7 +118,7 @@ pub async fn test_key_sequence_with_input_text<T: Into<TestCase>>(
|
|
|
|
let test_case = test_case.into();
|
|
|
|
let test_case = test_case.into();
|
|
|
|
let mut app = match app {
|
|
|
|
let mut app = match app {
|
|
|
|
Some(app) => app,
|
|
|
|
Some(app) => app,
|
|
|
|
None => Application::new(Args::default(), Config::default(), test_syntax_conf(None))?,
|
|
|
|
None => Application::new(Args::default(), test_config(), test_syntax_conf(None))?,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
let (view, doc) = helix_view::current!(app.editor);
|
|
|
|
let (view, doc) = helix_view::current!(app.editor);
|
|
|
@ -143,27 +143,9 @@ pub async fn test_key_sequence_with_input_text<T: Into<TestCase>>(
|
|
|
|
|
|
|
|
|
|
|
|
/// Generates language configs that merge in overrides, like a user language
|
|
|
|
/// Generates language configs that merge in overrides, like a user language
|
|
|
|
/// config. The argument string must be a raw TOML document.
|
|
|
|
/// config. The argument string must be a raw TOML document.
|
|
|
|
///
|
|
|
|
|
|
|
|
/// By default, language server configuration is dropped from the languages.toml
|
|
|
|
|
|
|
|
/// document. If a language-server is necessary for a test, it must be explicitly
|
|
|
|
|
|
|
|
/// added in `overrides`.
|
|
|
|
|
|
|
|
pub fn test_syntax_conf(overrides: Option<String>) -> helix_core::syntax::Configuration {
|
|
|
|
pub fn test_syntax_conf(overrides: Option<String>) -> helix_core::syntax::Configuration {
|
|
|
|
let mut lang = helix_loader::config::default_lang_config();
|
|
|
|
let mut lang = helix_loader::config::default_lang_config();
|
|
|
|
|
|
|
|
|
|
|
|
for lang_config in lang
|
|
|
|
|
|
|
|
.as_table_mut()
|
|
|
|
|
|
|
|
.expect("Expected languages.toml to be a table")
|
|
|
|
|
|
|
|
.get_mut("language")
|
|
|
|
|
|
|
|
.expect("Expected languages.toml to have \"language\" keys")
|
|
|
|
|
|
|
|
.as_array_mut()
|
|
|
|
|
|
|
|
.expect("Expected an array of language configurations")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
lang_config
|
|
|
|
|
|
|
|
.as_table_mut()
|
|
|
|
|
|
|
|
.expect("Expected language config to be a TOML table")
|
|
|
|
|
|
|
|
.remove("language-server");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if let Some(overrides) = overrides {
|
|
|
|
if let Some(overrides) = overrides {
|
|
|
|
let override_toml = toml::from_str(&overrides).unwrap();
|
|
|
|
let override_toml = toml::from_str(&overrides).unwrap();
|
|
|
|
lang = helix_loader::merge_toml_values(lang, override_toml, 3);
|
|
|
|
lang = helix_loader::merge_toml_values(lang, override_toml, 3);
|
|
|
@ -177,11 +159,12 @@ pub fn test_syntax_conf(overrides: Option<String>) -> helix_core::syntax::Config
|
|
|
|
/// want to verify the resulting document and selection.
|
|
|
|
/// want to verify the resulting document and selection.
|
|
|
|
pub async fn test_with_config<T: Into<TestCase>>(
|
|
|
|
pub async fn test_with_config<T: Into<TestCase>>(
|
|
|
|
args: Args,
|
|
|
|
args: Args,
|
|
|
|
config: Config,
|
|
|
|
mut config: Config,
|
|
|
|
syn_conf: helix_core::syntax::Configuration,
|
|
|
|
syn_conf: helix_core::syntax::Configuration,
|
|
|
|
test_case: T,
|
|
|
|
test_case: T,
|
|
|
|
) -> anyhow::Result<()> {
|
|
|
|
) -> anyhow::Result<()> {
|
|
|
|
let test_case = test_case.into();
|
|
|
|
let test_case = test_case.into();
|
|
|
|
|
|
|
|
config = helix_term::keymap::merge_keys(config);
|
|
|
|
let app = Application::new(args, config, syn_conf)?;
|
|
|
|
let app = Application::new(args, config, syn_conf)?;
|
|
|
|
|
|
|
|
|
|
|
|
test_key_sequence_with_input_text(
|
|
|
|
test_key_sequence_with_input_text(
|
|
|
@ -205,7 +188,7 @@ pub async fn test_with_config<T: Into<TestCase>>(
|
|
|
|
pub async fn test<T: Into<TestCase>>(test_case: T) -> anyhow::Result<()> {
|
|
|
|
pub async fn test<T: Into<TestCase>>(test_case: T) -> anyhow::Result<()> {
|
|
|
|
test_with_config(
|
|
|
|
test_with_config(
|
|
|
|
Args::default(),
|
|
|
|
Args::default(),
|
|
|
|
Config::default(),
|
|
|
|
test_config(),
|
|
|
|
test_syntax_conf(None),
|
|
|
|
test_syntax_conf(None),
|
|
|
|
test_case,
|
|
|
|
test_case,
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -226,6 +209,20 @@ pub fn temp_file_with_contents<S: AsRef<str>>(
|
|
|
|
Ok(temp_file)
|
|
|
|
Ok(temp_file)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Generates a config with defaults more suitable for integration tests
|
|
|
|
|
|
|
|
pub fn test_config() -> Config {
|
|
|
|
|
|
|
|
merge_keys(Config {
|
|
|
|
|
|
|
|
editor: helix_view::editor::Config {
|
|
|
|
|
|
|
|
lsp: LspConfig {
|
|
|
|
|
|
|
|
enable: false,
|
|
|
|
|
|
|
|
..Default::default()
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
..Default::default()
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
..Default::default()
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Replaces all LF chars with the system's appropriate line feed
|
|
|
|
/// Replaces all LF chars with the system's appropriate line feed
|
|
|
|
/// character, and if one doesn't exist already, appends the system's
|
|
|
|
/// character, and if one doesn't exist already, appends the system's
|
|
|
|
/// appropriate line ending to the end of a string.
|
|
|
|
/// appropriate line ending to the end of a string.
|
|
|
|