Skip to content

Commit

Permalink
Factor out line ending handling in integration tests (helix-editor#9921)
Browse files Browse the repository at this point in the history
Prior to this change, every integration test which wanted its line
endings to be handled transparently across platforms, i.e. test with
the same input that has its platform's line feed characters, converting
the line endings was up to each individual test by calling the
`platform_line` helper function. This significantly increases the amount
of boilerplate one has to copy between all the tests.

However, there are some test cases that need to exert strict control
over the exact input text without being manipulated behind the scenes by
the test framework.

So, with this change, the line feed conversions are factored into
the `TestCase` struct. By default, line endings of the input text
are converted to the platform's native line feed ending, but one can
explicitly specify in their test case when the input text should be left
alone and tested as is.
  • Loading branch information
dead10ck authored and Desdaemon committed Apr 3, 2024
1 parent e871a45 commit 8280d8f
Show file tree
Hide file tree
Showing 11 changed files with 564 additions and 478 deletions.
6 changes: 3 additions & 3 deletions helix-term/tests/test/auto_indent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ async fn auto_indent_c() -> anyhow::Result<()> {
AppBuilder::new().with_file("foo.c", None),
// switches to append mode?
(
helpers::platform_line("void foo() {#[|}]#"),
"void foo() {#[|}]#",
"i<ret><esc>",
helpers::platform_line(indoc! {"\
indoc! {"\
void foo() {
#[|\n]#\
}
"}),
"},
),
)
.await?;
Expand Down
28 changes: 28 additions & 0 deletions helix-term/tests/test/auto_pairs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ async fn insert_basic() -> anyhow::Result<()> {
format!("#[{}|]#", LINE_END),
format!("i{}", pair.0),
format!("{}#[|{}]#{}", pair.0, pair.1, LINE_END),
LineFeedHandling::AsIs,
))
.await?;
}
Expand Down Expand Up @@ -46,6 +47,7 @@ async fn insert_configured_multi_byte_chars() -> anyhow::Result<()> {
format!("#[{}|]#", LINE_END),
format!("i{}", open),
format!("{}#[|{}]#{}", open, close, LINE_END),
LineFeedHandling::AsIs,
),
)
.await?;
Expand All @@ -56,6 +58,7 @@ async fn insert_configured_multi_byte_chars() -> anyhow::Result<()> {
format!("{}#[{}|]#{}", open, close, LINE_END),
format!("i{}", close),
format!("{}{}#[|{}]#", open, close, LINE_END),
LineFeedHandling::AsIs,
),
)
.await?;
Expand All @@ -71,6 +74,7 @@ async fn insert_after_word() -> anyhow::Result<()> {
format!("foo#[{}|]#", LINE_END),
format!("i{}", pair.0),
format!("foo{}#[|{}]#{}", pair.0, pair.1, LINE_END),
LineFeedHandling::AsIs,
))
.await?;
}
Expand All @@ -80,6 +84,7 @@ async fn insert_after_word() -> anyhow::Result<()> {
format!("foo#[{}|]#", LINE_END),
format!("i{}", pair.0),
format!("foo{}#[|{}]#", pair.0, LINE_END),
LineFeedHandling::AsIs,
))
.await?;
}
Expand All @@ -94,6 +99,7 @@ async fn insert_before_word() -> anyhow::Result<()> {
format!("#[f|]#oo{}", LINE_END),
format!("i{}", pair.0),
format!("{}#[|f]#oo{}", pair.0, LINE_END),
LineFeedHandling::AsIs,
))
.await?;
}
Expand All @@ -108,6 +114,7 @@ async fn insert_before_word_selection() -> anyhow::Result<()> {
format!("#[foo|]#{}", LINE_END),
format!("i{}", pair.0),
format!("{}#[|foo]#{}", pair.0, LINE_END),
LineFeedHandling::AsIs,
))
.await?;
}
Expand All @@ -122,6 +129,7 @@ async fn insert_before_word_selection_trailing_word() -> anyhow::Result<()> {
format!("foo#[ wor|]#{}", LINE_END),
format!("i{}", pair.0),
format!("foo{}#[|{} wor]#{}", pair.0, pair.1, LINE_END),
LineFeedHandling::AsIs,
))
.await?;
}
Expand All @@ -136,6 +144,7 @@ async fn insert_closer_selection_trailing_word() -> anyhow::Result<()> {
format!("foo{}#[|{} wor]#{}", pair.0, pair.1, LINE_END),
format!("i{}", pair.1),
format!("foo{}{}#[| wor]#{}", pair.0, pair.1, LINE_END),
LineFeedHandling::AsIs,
))
.await?;
}
Expand All @@ -155,6 +164,7 @@ async fn insert_before_eol() -> anyhow::Result<()> {
open = pair.0,
close = pair.1
),
LineFeedHandling::AsIs,
))
.await?;
}
Expand All @@ -177,6 +187,7 @@ async fn insert_auto_pairs_disabled() -> anyhow::Result<()> {
format!("#[{}|]#", LINE_END),
format!("i{}", pair.0),
format!("{}#[|{}]#", pair.0, LINE_END),
LineFeedHandling::AsIs,
),
)
.await?;
Expand All @@ -197,6 +208,7 @@ async fn insert_multi_range() -> anyhow::Result<()> {
close = pair.1,
eol = LINE_END
),
LineFeedHandling::AsIs,
))
.await?;
}
Expand All @@ -211,6 +223,7 @@ async fn insert_before_multi_code_point_graphemes() -> anyhow::Result<()> {
format!("hello #[👨‍👩‍👧‍👦|]# goodbye{}", LINE_END),
format!("i{}", pair.1),
format!("hello {}#[|👨‍👩‍👧‍👦]# goodbye{}", pair.1, LINE_END),
LineFeedHandling::AsIs,
))
.await?;
}
Expand All @@ -226,6 +239,7 @@ async fn insert_at_end_of_document() -> anyhow::Result<()> {
in_keys: format!("i{}", pair.0),
out_text: format!("{}{}{}", LINE_END, pair.0, pair.1),
out_selection: Selection::single(LINE_END.len() + 1, LINE_END.len() + 2),
line_feed_handling: LineFeedHandling::AsIs,
})
.await?;

Expand All @@ -235,6 +249,7 @@ async fn insert_at_end_of_document() -> anyhow::Result<()> {
in_keys: format!("i{}", pair.0),
out_text: format!("foo{}{}{}", LINE_END, pair.0, pair.1),
out_selection: Selection::single(LINE_END.len() + 4, LINE_END.len() + 5),
line_feed_handling: LineFeedHandling::AsIs,
})
.await?;
}
Expand All @@ -259,6 +274,7 @@ async fn insert_close_inside_pair() -> anyhow::Result<()> {
close = pair.1,
eol = LINE_END
),
LineFeedHandling::AsIs,
))
.await?;
}
Expand All @@ -283,6 +299,7 @@ async fn insert_close_inside_pair_multi() -> anyhow::Result<()> {
close = pair.1,
eol = LINE_END
),
LineFeedHandling::AsIs,
))
.await?;
}
Expand All @@ -307,6 +324,7 @@ async fn insert_nested_open_inside_pair() -> anyhow::Result<()> {
close = pair.1,
eol = LINE_END
),
LineFeedHandling::AsIs,
))
.await?;
}
Expand Down Expand Up @@ -338,6 +356,7 @@ async fn insert_nested_open_inside_pair_multi() -> anyhow::Result<()> {
inner_close = inner_pair.1,
eol = LINE_END
),
LineFeedHandling::AsIs,
))
.await?;
}
Expand All @@ -358,6 +377,7 @@ async fn append_basic() -> anyhow::Result<()> {
close = pair.1,
eol = LINE_END
),
LineFeedHandling::AsIs,
))
.await?;
}
Expand All @@ -377,6 +397,7 @@ async fn append_multi_range() -> anyhow::Result<()> {
close = pair.1,
eol = LINE_END
),
LineFeedHandling::AsIs,
))
.await?;
}
Expand All @@ -401,6 +422,7 @@ async fn append_close_inside_pair() -> anyhow::Result<()> {
close = pair.1,
eol = LINE_END
),
LineFeedHandling::AsIs,
))
.await?;
}
Expand All @@ -425,6 +447,7 @@ async fn append_close_inside_pair_multi() -> anyhow::Result<()> {
close = pair.1,
eol = LINE_END
),
LineFeedHandling::AsIs,
))
.await?;
}
Expand All @@ -444,6 +467,7 @@ async fn append_end_of_word() -> anyhow::Result<()> {
close = pair.1,
eol = LINE_END
),
LineFeedHandling::AsIs,
))
.await?;
}
Expand All @@ -458,6 +482,7 @@ async fn append_middle_of_word() -> anyhow::Result<()> {
format!("#[wo|]#rd{}", LINE_END),
format!("a{}", pair.1),
format!("#[wo{}r|]#d{}", pair.1, LINE_END),
LineFeedHandling::AsIs,
))
.await?;
}
Expand All @@ -477,6 +502,7 @@ async fn append_end_of_word_multi() -> anyhow::Result<()> {
close = pair.1,
eol = LINE_END
),
LineFeedHandling::AsIs,
))
.await?;
}
Expand All @@ -501,6 +527,7 @@ async fn append_inside_nested_pair() -> anyhow::Result<()> {
close = pair.1,
eol = LINE_END
),
LineFeedHandling::AsIs,
))
.await?;
}
Expand Down Expand Up @@ -532,6 +559,7 @@ async fn append_inside_nested_pair_multi() -> anyhow::Result<()> {
inner_close = inner_pair.1,
eol = LINE_END
),
LineFeedHandling::AsIs,
))
.await?;
}
Expand Down
Loading

0 comments on commit 8280d8f

Please sign in to comment.