aboutsummaryrefslogtreecommitdiff
path: root/helix-term/tests
diff options
context:
space:
mode:
authorSkyler Hawthorne2022-05-22 17:29:52 +0000
committerSkyler Hawthorne2022-06-19 03:57:47 +0000
commit7c0bca186cdacf070355c1a4ab82121d6a4d2e27 (patch)
tree4b0d1e2a09d676d297ecde75e72a93d27e40fe54 /helix-term/tests
parent526c9be8cadf99519e8f6a9911b3784ab7f2e142 (diff)
rename test helpers
Diffstat (limited to 'helix-term/tests')
-rw-r--r--helix-term/tests/integration.rs8
-rw-r--r--helix-term/tests/test/auto_indent.rs2
-rw-r--r--helix-term/tests/test/auto_pairs.rs9
-rw-r--r--helix-term/tests/test/helpers.rs13
-rw-r--r--helix-term/tests/test/movement.rs103
5 files changed, 45 insertions, 90 deletions
diff --git a/helix-term/tests/integration.rs b/helix-term/tests/integration.rs
index 376bc88b..11bc4e4c 100644
--- a/helix-term/tests/integration.rs
+++ b/helix-term/tests/integration.rs
@@ -13,13 +13,7 @@ mod test {
#[tokio::test]
async fn hello_world() -> anyhow::Result<()> {
- test_key_sequence_text_result(
- Args::default(),
- Config::default(),
- ("#[\n|]#", "ihello world<esc>", "hello world#[|\n]#"),
- )
- .await?;
-
+ test(("#[\n|]#", "ihello world<esc>", "hello world#[|\n]#")).await?;
Ok(())
}
diff --git a/helix-term/tests/test/auto_indent.rs b/helix-term/tests/test/auto_indent.rs
index 8933cb6a..2f638893 100644
--- a/helix-term/tests/test/auto_indent.rs
+++ b/helix-term/tests/test/auto_indent.rs
@@ -2,7 +2,7 @@ use super::*;
#[tokio::test]
async fn auto_indent_c() -> anyhow::Result<()> {
- test_key_sequence_text_result(
+ test_with_config(
Args {
files: vec![(PathBuf::from("foo.c"), Position::default())],
..Default::default()
diff --git a/helix-term/tests/test/auto_pairs.rs b/helix-term/tests/test/auto_pairs.rs
index 52fee55e..ec47a5b4 100644
--- a/helix-term/tests/test/auto_pairs.rs
+++ b/helix-term/tests/test/auto_pairs.rs
@@ -2,14 +2,9 @@ use super::*;
#[tokio::test]
async fn auto_pairs_basic() -> anyhow::Result<()> {
- test_key_sequence_text_result(
- Args::default(),
- Config::default(),
- ("#[\n|]#", "i(<esc>", "(#[|)]#\n"),
- )
- .await?;
+ test(("#[\n|]#", "i(<esc>", "(#[|)]#\n")).await?;
- test_key_sequence_text_result(
+ test_with_config(
Args::default(),
Config {
editor: helix_view::editor::Config {
diff --git a/helix-term/tests/test/helpers.rs b/helix-term/tests/test/helpers.rs
index 3fe1934f..2bebe31b 100644
--- a/helix-term/tests/test/helpers.rs
+++ b/helix-term/tests/test/helpers.rs
@@ -41,6 +41,7 @@ pub async fn test_key_sequence(
test_key_sequences(app, vec![(in_keys, test_fn)]).await
}
+#[allow(clippy::type_complexity)]
pub async fn test_key_sequences(
app: &mut Application,
inputs: Vec<(Option<&str>, Option<&dyn Fn(&Application)>)>,
@@ -51,7 +52,7 @@ pub async fn test_key_sequences(
for (in_keys, test_fn) in inputs {
if let Some(in_keys) = in_keys {
- for key_event in parse_macro(&in_keys)?.into_iter() {
+ for key_event in parse_macro(in_keys)?.into_iter() {
tx.send(Ok(Event::Key(KeyEvent::from(key_event))))?;
}
}
@@ -92,7 +93,7 @@ pub async fn test_key_sequence_with_input_text<T: Into<TestCase>>(
// replace the initial text with the input text
doc.apply(
- &Transaction::change_by_selection(&doc.text(), &sel, |_| {
+ &Transaction::change_by_selection(doc.text(), &sel, |_| {
(0, doc.text().len_chars(), Some((&test_case.in_text).into()))
})
.with_selection(test_case.in_selection.clone()),
@@ -105,7 +106,7 @@ pub async fn test_key_sequence_with_input_text<T: Into<TestCase>>(
/// Use this for very simple test cases where there is one input
/// document, selection, and sequence of key presses, and you just
/// want to verify the resulting document and selection.
-pub async fn test_key_sequence_text_result<T: Into<TestCase>>(
+pub async fn test_with_config<T: Into<TestCase>>(
args: Args,
config: Config,
test_case: T,
@@ -126,6 +127,10 @@ pub async fn test_key_sequence_text_result<T: Into<TestCase>>(
.await
}
+pub async fn test<T: Into<TestCase>>(test_case: T) -> anyhow::Result<()> {
+ test_with_config(Args::default(), Config::default(), test_case).await
+}
+
pub fn temp_file_with_contents<S: AsRef<str>>(
content: S,
) -> anyhow::Result<tempfile::NamedTempFile> {
@@ -148,7 +153,7 @@ pub fn platform_line(input: &str) -> String {
// we can assume that the source files in this code base will always
// be LF, so indoc strings will always insert LF
- let mut output = input.replace("\n", line_end);
+ let mut output = input.replace('\n', line_end);
if !output.ends_with(line_end) {
output.push_str(line_end);
diff --git a/helix-term/tests/test/movement.rs b/helix-term/tests/test/movement.rs
index e0bfc3bf..5fb2ce25 100644
--- a/helix-term/tests/test/movement.rs
+++ b/helix-term/tests/test/movement.rs
@@ -4,39 +4,18 @@ use super::*;
#[tokio::test]
async fn insert_mode_cursor_position() -> anyhow::Result<()> {
- test_key_sequence_text_result(
- Args::default(),
- Config::default(),
- TestCase {
- in_text: String::new(),
- in_selection: Selection::single(0, 0),
- in_keys: "i".into(),
- out_text: String::new(),
- out_selection: Selection::single(0, 0),
- },
- )
- .await?;
-
- test_key_sequence_text_result(
- Args::default(),
- Config::default(),
- ("#[\n|]#", "i", "#[|\n]#"),
- )
- .await?;
-
- test_key_sequence_text_result(
- Args::default(),
- Config::default(),
- ("#[\n|]#", "i<esc>", "#[|\n]#"),
- )
+ test(TestCase {
+ in_text: String::new(),
+ in_selection: Selection::single(0, 0),
+ in_keys: "i".into(),
+ out_text: String::new(),
+ out_selection: Selection::single(0, 0),
+ })
.await?;
- test_key_sequence_text_result(
- Args::default(),
- Config::default(),
- ("#[\n|]#", "i<esc>i", "#[|\n]#"),
- )
- .await?;
+ test(("#[\n|]#", "i", "#[|\n]#")).await?;
+ test(("#[\n|]#", "i<esc>", "#[|\n]#")).await?;
+ test(("#[\n|]#", "i<esc>i", "#[|\n]#")).await?;
Ok(())
}
@@ -44,62 +23,44 @@ async fn insert_mode_cursor_position() -> anyhow::Result<()> {
/// Range direction is preserved when escaping insert mode to normal
#[tokio::test]
async fn insert_to_normal_mode_cursor_position() -> anyhow::Result<()> {
- test_key_sequence_text_result(
- Args::default(),
- Config::default(),
- ("#[f|]#oo\n", "vll<A-;><esc>", "#[|foo]#\n"),
- )
- .await?;
-
- test_key_sequence_text_result(
- Args::default(),
- Config::default(),
- (
- indoc! {"\
+ test(("#[f|]#oo\n", "vll<A-;><esc>", "#[|foo]#\n")).await?;
+ test((
+ indoc! {"\
#[f|]#oo
#(b|)#ar"
- },
- "vll<A-;><esc>",
- indoc! {"\
+ },
+ "vll<A-;><esc>",
+ indoc! {"\
#[|foo]#
#(|bar)#"
- },
- ),
- )
+ },
+ ))
.await?;
- test_key_sequence_text_result(
- Args::default(),
- Config::default(),
- (
- indoc! {"\
+ test((
+ indoc! {"\
#[f|]#oo
#(b|)#ar"
- },
- "a",
- indoc! {"\
+ },
+ "a",
+ indoc! {"\
#[fo|]#o
#(ba|)#r"
- },
- ),
- )
+ },
+ ))
.await?;
- test_key_sequence_text_result(
- Args::default(),
- Config::default(),
- (
- indoc! {"\
+ test((
+ indoc! {"\
#[f|]#oo
#(b|)#ar"
- },
- "a<esc>",
- indoc! {"\
+ },
+ "a<esc>",
+ indoc! {"\
#[f|]#oo
#(b|)#ar"
- },
- ),
- )
+ },
+ ))
.await?;
Ok(())