Skip to content

Commit

Permalink
Add unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
yamgent committed Oct 5, 2023
1 parent badcc7a commit 33725b8
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions src/components/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -958,3 +958,75 @@ impl Component for DiffComponent {
self.focused = focus;
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::ui::style::Theme;
use std::io::Write;
use std::rc::Rc;
use tempfile::NamedTempFile;

#[test]
fn test_line_break() {
let diff_line = DiffLine {
content: "".into(),
line_type: DiffLineType::Add,
position: Default::default(),
};

{
let default_theme = Rc::new(Theme::default());

assert_eq!(
DiffComponent::get_line_to_add(
4,
&diff_line,
false,
false,
false,
&default_theme,
0
)
.spans
.last()
.unwrap(),
&Span::styled(
Cow::from(\n"),
default_theme
.diff_line(diff_line.line_type, false)
)
);
}

{
let mut file = NamedTempFile::new().unwrap();

writeln!(
file,
r#"
(
line_break: Some("+")
)
"#
)
.unwrap();

let theme =
Rc::new(Theme::init(&file.path().to_path_buf()));

assert_eq!(
DiffComponent::get_line_to_add(
4, &diff_line, false, false, false, &theme, 0
)
.spans
.last()
.unwrap(),
&Span::styled(
Cow::from("+\n"),
theme.diff_line(diff_line.line_type, false)
)
);
}
}
}

0 comments on commit 33725b8

Please sign in to comment.