summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2021-12-11 20:28:56 -0500
committerDan Davison <dandavison7@gmail.com>2021-12-12 00:20:52 -0500
commit081e0a7c66cc5d3804b14cdd4f4de6acd6a26483 (patch)
treea0870c7cdd2b64c31258ed618ca634f0eedd7e33
parent8dfd22ba8ac76edb1b1783ce434ba98baf868a89 (diff)
Refactor: factor out a helper function in DeltaTest
-rw-r--r--src/tests/integration_test_utils.rs24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/tests/integration_test_utils.rs b/src/tests/integration_test_utils.rs
index 44dd3bee..2072c404 100644
--- a/src/tests/integration_test_utils.rs
+++ b/src/tests/integration_test_utils.rs
@@ -93,7 +93,7 @@ pub fn get_line_of_code_from_delta(
// line1"#;` // line 2 etc.
// ignore the first newline and compare the following `lines()` to those produced
// by `have`, `skip`-ping the first few. The leading spaces of the first line
-// are strippedfrom every following line (and verified) , unless the first line
+// are stripped from every following line (and verified), unless the first line
// marks the indentation level with `#indent_mark`.
pub fn lines_match(expected: &str, have: &str, skip: Option<usize>) {
let mut exp = expected.lines().peekable();
@@ -163,11 +163,7 @@ pub struct DeltaTestOutput {
impl DeltaTestOutput {
pub fn inspect(self) -> Self {
- if self.explain_ansi_ {
- eprintln!("{}", ansi::explain_ansi(&self.output, true));
- } else {
- eprintln!("{}", &self.output);
- }
+ eprintln!("{}", self.format_output());
self
}
@@ -177,20 +173,22 @@ impl DeltaTestOutput {
}
pub fn expect_skip(self, skip: usize, expected: &str) -> String {
- let processed = if self.explain_ansi_ {
- ansi::explain_ansi(&self.output, false)
- } else {
- ansi::strip_ansi_codes(&self.output)
- };
-
+ let processed = self.format_output();
lines_match(expected, &processed, Some(skip));
-
processed
}
pub fn expect(self, expected: &str) -> String {
self.expect_skip(crate::config::HEADER_LEN, expected)
}
+
+ fn format_output(&self) -> String {
+ if self.explain_ansi_ {
+ ansi::explain_ansi(&self.output, false)
+ } else {
+ ansi::strip_ansi_codes(&self.output)
+ }
+ }
}
pub fn run_delta(input: &str, config: &config::Config) -> String {