summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2022-01-17 13:00:56 -0500
committerDan Davison <dandavison7@gmail.com>2022-01-17 13:11:42 -0500
commit1f80503a56eab8b287f9eaf5263dd7256574ccaf (patch)
tree18b53586a2591f98776e70e4a69fa9deab61cc4d
parent102936b083f9c63ee94f3e5ad87a63ed5b3edd29 (diff)
Improve tests of hunk header / hyperlinks behaviour
-rw-r--r--src/handlers/hunk_header.rs24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/handlers/hunk_header.rs b/src/handlers/hunk_header.rs
index 2900008f..bb6ad8dd 100644
--- a/src/handlers/hunk_header.rs
+++ b/src/handlers/hunk_header.rs
@@ -316,6 +316,7 @@ fn write_to_output_buffer(
pub mod tests {
use super::*;
use crate::ansi::strip_ansi_codes;
+ use crate::git_config::GitConfigEntry;
use crate::tests::integration_test_utils;
#[test]
@@ -389,6 +390,8 @@ pub mod tests {
#[test]
fn test_paint_file_path_with_line_number_default() {
+ // hunk-header-style (by default) includes 'line-number' but not 'file'.
+ // This test confirms that `paint_file_path_with_line_number` returns a painted line number.
let cfg = integration_test_utils::make_config_from_args(&[]);
let result = paint_file_path_with_line_number(Some(3), "some-file", &cfg);
@@ -398,15 +401,28 @@ pub mod tests {
#[test]
fn test_paint_file_path_with_line_number_hyperlinks() {
- let cfg = integration_test_utils::make_config_from_args(&["--features", "hyperlinks"]);
+ // hunk-header-style (by default) includes 'line-number' but not 'file'.
+ // Normally, `paint_file_path_with_line_number` would return a painted line number.
+ // But in this test hyperlinks are activated, and the test ensures that delta.__workdir__ is
+ // present in git_config_entries.
+ // This test confirms that, under those circumstances, `paint_file_path_with_line_number`
+ // returns a hyperlinked file path with line number.
+
+ let mut cfg = integration_test_utils::make_config_from_args(&["--features", "hyperlinks"]);
+ cfg.git_config_entries.insert(
+ "delta.__workdir__".to_string(),
+ GitConfigEntry::Path("/some/workdir".into()),
+ );
let result = paint_file_path_with_line_number(Some(3), "some-file", &cfg);
- assert_eq!(result, "some-file");
+ assert_eq!(result, "\u{1b}]8;;file:///some/workdir/some-file\u{1b}\\\u{1b}[34m3\u{1b}[0m\u{1b}]8;;\u{1b}\\");
}
#[test]
fn test_paint_file_path_with_line_number_empty() {
+ // hunk-header-style includes neither 'file' nor 'line-number'.
+ // This causes `paint_file_path_with_line_number` to return empty string.
let cfg = integration_test_utils::make_config_from_args(&[
"--hunk-header-style",
"syntax bold",
@@ -421,6 +437,10 @@ pub mod tests {
#[test]
fn test_paint_file_path_with_line_number_empty_hyperlinks() {
+ // hunk-header-style includes neither 'file' nor 'line-number'.
+ // This causes `paint_file_path_with_line_number` to return empty string.
+ // This test confirms that this remains true even when we are requesting hyperlinks.
+
let cfg = integration_test_utils::make_config_from_args(&[
"--hunk-header-style",
"syntax bold",