summaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2020-05-20 17:40:03 -0400
committerDan Davison <dandavison7@gmail.com>2020-05-22 22:23:28 -0400
commit291d2fb7fa8cfc2a0886af895972326d00fb4dbe (patch)
treea24d3fd37156c6df862beb851a750f053945514e /src/tests
parentf08effc46de52655c8431498c6bc214c0eda30e5 (diff)
Use ansi_term style data structures instead of syntect
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/ansi_test_utils.rs30
-rw-r--r--src/tests/test_hunk_highlighting.rs52
2 files changed, 35 insertions, 47 deletions
diff --git a/src/tests/ansi_test_utils.rs b/src/tests/ansi_test_utils.rs
index 5167999c..ccfbab6f 100644
--- a/src/tests/ansi_test_utils.rs
+++ b/src/tests/ansi_test_utils.rs
@@ -3,7 +3,6 @@ pub mod ansi_test_utils {
use ansi_parser::{self, AnsiParser};
use console::strip_ansi_codes;
use itertools::Itertools;
- use syntect::highlighting::StyleModifier;
use crate::config::{ColorLayer::*, Config};
use crate::delta::State;
@@ -49,13 +48,10 @@ pub mod ansi_test_utils {
}
fn string_has_background_color(string: &str, state: &State, config: &Config) -> bool {
- let painted = paint::paint_text_background(
- "",
- config
- .get_color(state, Background)
- .unwrap_or_else(|| panic!("state {:?} does not have a background color", state)),
- true,
- );
+ let painted = config
+ .get_color(state, Background)
+ .unwrap_or_else(|| panic!("state {:?} does not have a background color", state))
+ .paint("");
let ansi_sequence = painted
.trim_end_matches(paint::ANSI_SGR_RESET)
.trim_end_matches("m");
@@ -102,18 +98,10 @@ pub mod ansi_test_utils {
pub fn get_color_variants(string: &str, config: &Config) -> (String, String) {
let string_without_any_color = strip_ansi_codes(string).to_string();
- let string_with_plus_color_only = paint_text(
- &string_without_any_color,
- config.plus_style_modifier,
- config,
- );
- (string_without_any_color, string_with_plus_color_only)
- }
-
- fn paint_text(input: &str, style_modifier: StyleModifier, config: &Config) -> String {
- let mut output = String::new();
- let style = config.no_style.apply(style_modifier);
- paint::paint_text(&input, style, &mut output, config.true_color);
- output
+ let string_with_plus_color_only = config.plus_style.paint(&string_without_any_color);
+ (
+ string_without_any_color.to_string(),
+ string_with_plus_color_only.to_string(),
+ )
}
}
diff --git a/src/tests/test_hunk_highlighting.rs b/src/tests/test_hunk_highlighting.rs
index 8c2bbe35..fdc5cfc5 100644
--- a/src/tests/test_hunk_highlighting.rs
+++ b/src/tests/test_hunk_highlighting.rs
@@ -2,6 +2,8 @@
mod tests {
use itertools::Itertools;
+ use ansi_term::Style;
+
use crate::cli;
use crate::config::ColorLayer::*;
use crate::delta::State;
@@ -52,32 +54,30 @@ mod tests {
);
let lines = output.trim().split("\n").skip(4);
- let minus =
- paint::paint_text_background("", config.minus_style_modifier.background.unwrap(), true)
- .trim_end_matches(paint::ANSI_SGR_RESET)
- .trim_end_matches("m")
- .to_string();
- let minus_emph = paint::paint_text_background(
- "",
- config.minus_emph_style_modifier.background.unwrap(),
- true,
- )
- .trim_end_matches(paint::ANSI_SGR_RESET)
- .trim_end_matches("m")
- .to_string();
- let plus =
- paint::paint_text_background("", config.plus_style_modifier.background.unwrap(), true)
- .trim_end_matches(paint::ANSI_SGR_RESET)
- .trim_end_matches("m")
- .to_string();
- let plus_emph = paint::paint_text_background(
- "",
- config.plus_emph_style_modifier.background.unwrap(),
- true,
- )
- .trim_end_matches(paint::ANSI_SGR_RESET)
- .trim_end_matches("m")
- .to_string();
+ let minus = Style::new()
+ .on(config.minus_style.background.unwrap())
+ .paint("")
+ .trim_end_matches(paint::ANSI_SGR_RESET)
+ .trim_end_matches("m")
+ .to_string();
+ let minus_emph = Style::new()
+ .on(config.minus_emph_style.background.unwrap())
+ .paint("")
+ .trim_end_matches(paint::ANSI_SGR_RESET)
+ .trim_end_matches("m")
+ .to_string();
+ let plus = Style::new()
+ .on(config.plus_style.background.unwrap())
+ .paint("")
+ .trim_end_matches(paint::ANSI_SGR_RESET)
+ .trim_end_matches("m")
+ .to_string();
+ let plus_emph = Style::new()
+ .on(config.plus_emph_style.background.unwrap())
+ .paint("")
+ .trim_end_matches(paint::ANSI_SGR_RESET)
+ .trim_end_matches("m")
+ .to_string();
let expectation = vec![
// line 1: unchanged