on master help sign in
rename test helpers
commit7c0bca186cdacf070355c1a4ab82121d6a4d2e27 authorSkyler Hawthorne <skyler@dead10ck.com> dateSun 22 May 2022, 13:29 (4 years ago) parent526c9be
5 files changed+45−90
helix-term/tests/integration.rs+1−7 helix-term/tests/test/auto_indent.rs+1−1 helix-term/tests/test/auto_pairs.rs+2−7 helix-term/tests/test/helpers.rs+9−4 helix-term/tests/test/movement.rs+32−71
helix-term/tests/integration.rs+1−7
@@ -13,13 +13,7 @@ mod test {
1313
1414 #[tokio::test]
1515 async fn hello_world() -> anyhow::Result<()> {
16− test_key_sequence_text_result(
17− Args::default(),
18− Config::default(),
19− ("#[\n|]#", "ihello world<esc>", "hello world#[|\n]#"),
20− )
21− .await?;
22−
16+ test(("#[\n|]#", "ihello world<esc>", "hello world#[|\n]#")).await?;
2317 Ok(())
2418 }
2519
helix-term/tests/test/auto_indent.rs+1−1
@@ -2,7 +2,7 @@ use super::*;
22
33#[tokio::test]
44async fn auto_indent_c() -> anyhow::Result<()> {
5− test_key_sequence_text_result(
5+ test_with_config(
66 Args {
77 files: vec![(PathBuf::from("foo.c"), Position::default())],
88 ..Default::default()
helix-term/tests/test/auto_pairs.rs+2−7
@@ -2,14 +2,9 @@ use super::*;
22
33#[tokio::test]
44async fn auto_pairs_basic() -> anyhow::Result<()> {
5− test_key_sequence_text_result(
6− Args::default(),
7− Config::default(),
8− ("#[\n|]#", "i(<esc>", "(#[|)]#\n"),
9− )
10− .await?;
5+ test(("#[\n|]#", "i(<esc>", "(#[|)]#\n")).await?;
116
12− test_key_sequence_text_result(
7+ test_with_config(
138 Args::default(),
149 Config {
1510 editor: helix_view::editor::Config {
helix-term/tests/test/helpers.rs+9−4
@@ -41,6 +41,7 @@ pub async fn test_key_sequence(
4141 test_key_sequences(app, vec![(in_keys, test_fn)]).await
4242}
4343
44+#[allow(clippy::type_complexity)]
4445pub async fn test_key_sequences(
4546 app: &mut Application,
4647 inputs: Vec<(Option<&str>, Option<&dyn Fn(&Application)>)>,
@@ -51,7 +52,7 @@ pub async fn test_key_sequences(
5152
5253 for (in_keys, test_fn) in inputs {
5354 if let Some(in_keys) = in_keys {
54− for key_event in parse_macro(&in_keys)?.into_iter() {
55+ for key_event in parse_macro(in_keys)?.into_iter() {
5556 tx.send(Ok(Event::Key(KeyEvent::from(key_event))))?;
5657 }
5758 }
@@ -92,7 +93,7 @@ pub async fn test_key_sequence_with_input_text<T: Into<TestCase>>(
9293
9394 // replace the initial text with the input text
9495 doc.apply(
95− &Transaction::change_by_selection(&doc.text(), &sel, |_| {
96+ &Transaction::change_by_selection(doc.text(), &sel, |_| {
9697 (0, doc.text().len_chars(), Some((&test_case.in_text).into()))
9798 })
9899 .with_selection(test_case.in_selection.clone()),
@@ -105,7 +106,7 @@ pub async fn test_key_sequence_with_input_text<T: Into<TestCase>>(
105106/// Use this for very simple test cases where there is one input
106107/// document, selection, and sequence of key presses, and you just
107108/// want to verify the resulting document and selection.
108−pub async fn test_key_sequence_text_result<T: Into<TestCase>>(
109+pub async fn test_with_config<T: Into<TestCase>>(
109110 args: Args,
110111 config: Config,
111112 test_case: T,
@@ -126,6 +127,10 @@ pub async fn test_key_sequence_text_result<T: Into<TestCase>>(
126127 .await
127128}
128129
130+pub async fn test<T: Into<TestCase>>(test_case: T) -> anyhow::Result<()> {
131+ test_with_config(Args::default(), Config::default(), test_case).await
132+}
133+
129134pub fn temp_file_with_contents<S: AsRef<str>>(
130135 content: S,
131136) -> anyhow::Result<tempfile::NamedTempFile> {
@@ -148,7 +153,7 @@ pub fn platform_line(input: &str) -> String {
148153
149154 // we can assume that the source files in this code base will always
150155 // be LF, so indoc strings will always insert LF
151− let mut output = input.replace("\n", line_end);
156+ let mut output = input.replace('\n', line_end);
152157
153158 if !output.ends_with(line_end) {
154159 output.push_str(line_end);
helix-term/tests/test/movement.rs+32−71
@@ -4,39 +4,18 @@ use super::*;
44
55#[tokio::test]
66async fn insert_mode_cursor_position() -> anyhow::Result<()> {
7− test_key_sequence_text_result(
8− Args::default(),
9− Config::default(),
10− TestCase {
11− in_text: String::new(),
12− in_selection: Selection::single(0, 0),
13− in_keys: "i".into(),
14− out_text: String::new(),
15− out_selection: Selection::single(0, 0),
16− },
17− )
18− .await?;
19−
20− test_key_sequence_text_result(
21− Args::default(),
22− Config::default(),
23− ("#[\n|]#", "i", "#[|\n]#"),
24− )
25− .await?;
26−
27− test_key_sequence_text_result(
28− Args::default(),
29− Config::default(),
30− ("#[\n|]#", "i<esc>", "#[|\n]#"),
31− )
7+ test(TestCase {
8+ in_text: String::new(),
9+ in_selection: Selection::single(0, 0),
10+ in_keys: "i".into(),
11+ out_text: String::new(),
12+ out_selection: Selection::single(0, 0),
13+ })
3214 .await?;
3315
34− test_key_sequence_text_result(
35− Args::default(),
36− Config::default(),
37− ("#[\n|]#", "i<esc>i", "#[|\n]#"),
38− )
39− .await?;
16+ test(("#[\n|]#", "i", "#[|\n]#")).await?;
17+ test(("#[\n|]#", "i<esc>", "#[|\n]#")).await?;
18+ test(("#[\n|]#", "i<esc>i", "#[|\n]#")).await?;
4019
4120 Ok(())
4221}
@@ -44,62 +23,44 @@ async fn insert_mode_cursor_position() -> anyhow::Result<()> {
4423/// Range direction is preserved when escaping insert mode to normal
4524#[tokio::test]
4625async fn insert_to_normal_mode_cursor_position() -> anyhow::Result<()> {
47− test_key_sequence_text_result(
48− Args::default(),
49− Config::default(),
50− ("#[f|]#oo\n", "vll<A-;><esc>", "#[|foo]#\n"),
51− )
52− .await?;
53−
54− test_key_sequence_text_result(
55− Args::default(),
56− Config::default(),
57− (
58− indoc! {"\
26+ test(("#[f|]#oo\n", "vll<A-;><esc>", "#[|foo]#\n")).await?;
27+ test((
28+ indoc! {"\
5929 #[f|]#oo
6030 #(b|)#ar"
61− },
62− "vll<A-;><esc>",
63− indoc! {"\
31+ },
32+ "vll<A-;><esc>",
33+ indoc! {"\
6434 #[|foo]#
6535 #(|bar)#"
66− },
67− ),
68− )
36+ },
37+ ))
6938 .await?;
7039
71− test_key_sequence_text_result(
72− Args::default(),
73− Config::default(),
74− (
75− indoc! {"\
40+ test((
41+ indoc! {"\
7642 #[f|]#oo
7743 #(b|)#ar"
78− },
79− "a",
80− indoc! {"\
44+ },
45+ "a",
46+ indoc! {"\
8147 #[fo|]#o
8248 #(ba|)#r"
83− },
84− ),
85− )
49+ },
50+ ))
8651 .await?;
8752
88− test_key_sequence_text_result(
89− Args::default(),
90− Config::default(),
91− (
92− indoc! {"\
53+ test((
54+ indoc! {"\
9355 #[f|]#oo
9456 #(b|)#ar"
95− },
96− "a<esc>",
97− indoc! {"\
57+ },
58+ "a<esc>",
59+ indoc! {"\
9860 #[f|]#oo
9961 #(b|)#ar"
100− },
101− ),
102− )
62+ },
63+ ))
10364 .await?;
10465
10566 Ok(())