summaryrefslogtreecommitdiffstats
path: root/src/tests/test_example_diffs.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/test_example_diffs.rs')
-rw-r--r--src/tests/test_example_diffs.rs170
1 files changed, 125 insertions, 45 deletions
diff --git a/src/tests/test_example_diffs.rs b/src/tests/test_example_diffs.rs
index 94b18f11..402a88a5 100644
--- a/src/tests/test_example_diffs.rs
+++ b/src/tests/test_example_diffs.rs
@@ -74,7 +74,7 @@ mod tests {
let config = integration_test_utils::make_config_from_args(&[]);
let output = integration_test_utils::get_line_of_code_from_delta(
&ADDED_FILE_INPUT,
- 12,
+ 14,
"class X:",
&config,
);
@@ -88,7 +88,7 @@ mod tests {
let config = integration_test_utils::make_config_from_args(&[]);
let input = ADDED_FILE_INPUT.replace("a.py", "a");
let output =
- integration_test_utils::get_line_of_code_from_delta(&input, 12, "class X:", &config);
+ integration_test_utils::get_line_of_code_from_delta(&input, 14, "class X:", &config);
ansi_test_utils::assert_has_color_other_than_plus_color(&output, &config);
}
@@ -104,7 +104,7 @@ mod tests {
]);
let input = ADDED_FILE_INPUT.replace("a.py", "a");
let output =
- integration_test_utils::get_line_of_code_from_delta(&input, 12, "class X:", &config);
+ integration_test_utils::get_line_of_code_from_delta(&input, 14, "class X:", &config);
ansi_test_utils::assert_has_plus_color_only(&output, &config);
}
@@ -117,14 +117,10 @@ mod tests {
// Header
assert_eq!(lines.nth(1).unwrap(), "comparing: one.rs ⟶ src/two.rs");
- // Line
- assert_eq!(lines.nth(2).unwrap(), "5");
// Change
- assert_eq!(lines.nth(2).unwrap(), "println!(\"Hello ruster\");");
- // Next chunk
- assert_eq!(lines.nth(2).unwrap(), "43");
+ assert_eq!(lines.nth(7).unwrap(), "println!(\"Hello ruster\");");
// Unchanged in second chunk
- assert_eq!(lines.nth(2).unwrap(), "Unchanged");
+ assert_eq!(lines.nth(7).unwrap(), "Unchanged");
}
#[test]
@@ -139,10 +135,8 @@ mod tests {
lines.nth(1).unwrap(),
"comparing: a/different ⟶ b/different"
);
- // Line number
- assert_eq!(lines.nth(2).unwrap(), "1");
// Change
- assert_eq!(lines.nth(2).unwrap(), "This is different from b");
+ assert_eq!(lines.nth(7).unwrap(), "This is different from b");
// File uniqueness
assert_eq!(lines.nth(2).unwrap(), "Only in a/: just_a");
// FileMeta divider
@@ -196,7 +190,7 @@ mod tests {
let output = integration_test_utils::run_delta(DIFF_WITH_MERGE_CONFLICT, &config);
// TODO: The + in the first column is being removed.
assert!(strip_ansi_codes(&output).contains("+>>>>>>> Stashed changes"));
- assert_eq!(output.lines().count(), 46);
+ assert_eq!(output.lines().count(), 45);
}
#[test]
@@ -1014,7 +1008,7 @@ src/align.rs
"--file-style",
"yellow",
"--hunk-header-style",
- "file red",
+ "file line-number red",
"--hunk-header-decoration-style",
"box",
]);
@@ -1023,16 +1017,16 @@ src/align.rs
ansi_test_utils::assert_line_has_style(
&output,
11,
- "src/align.rs: impl<'a> Alignment<'a> {",
+ "src/align.rs:71: impl<'a> Alignment<'a> {",
"yellow",
&config,
);
let output = strip_ansi_codes(&output);
assert!(output.contains(
"
-───────────────────────────────────────┐
-src/align.rs: impl<'a> Alignment<'a> { │
-───────────────────────────────────────┘
+──────────────────────────────────────────┐
+src/align.rs:71: impl<'a> Alignment<'a> { │
+──────────────────────────────────────────┘
"
));
}
@@ -1043,19 +1037,19 @@ src/align.rs: impl<'a> Alignment<'a> { │
"--file-style",
"yellow",
"--hunk-header-style",
- "file red",
+ "file line-number red",
"--hunk-header-decoration-style",
"box",
]);
let output = integration_test_utils::run_delta(GIT_DIFF_SINGLE_HUNK_NO_FRAG, &config);
- ansi_test_utils::assert_line_has_style(&output, 5, "src/delta.rs", "yellow", &config);
+ ansi_test_utils::assert_line_has_style(&output, 5, "src/delta.rs:1 ", "yellow", &config);
let output = strip_ansi_codes(&output);
assert!(output.contains(
"
-─────────────┐
-src/delta.rs │
-─────────────┘
+───────────────┐
+src/delta.rs:1 │
+───────────────┘
"
));
}
@@ -1084,7 +1078,7 @@ src/delta.rs │
fn test_hunk_header_style_colored_input_color_is_stripped_under_normal() {
let config = integration_test_utils::make_config_from_args(&[
"--hunk-header-style",
- "normal",
+ "line-number normal",
"--hunk-header-decoration-style",
"omit",
]);
@@ -1094,7 +1088,7 @@ src/delta.rs │
);
// An additional newline is inserted under anything other than `style=raw,
// decoration-style=omit`, to better separate the hunks. Hence 9 + 1.
- ansi_test_utils::assert_line_has_no_color(&output, 9 + 1, "impl<'a> Alignment<'a> {");
+ ansi_test_utils::assert_line_has_no_color(&output, 9 + 1, "71: impl<'a> Alignment<'a> {");
}
#[test]
@@ -1178,6 +1172,36 @@ impl<'a> Alignment<'a> {
}
#[test]
+ fn test_hunk_header_style_box_line_number() {
+ _do_test_hunk_header_style_box(&[
+ "--hunk-header-style",
+ "line-number",
+ "--hunk-header-decoration-style",
+ "white box",
+ ]);
+ }
+
+ #[test]
+ fn test_hunk_header_style_box_file_line_number() {
+ _do_test_hunk_header_style_box_file_line_number(&[
+ "--hunk-header-style",
+ "file line-number",
+ "--hunk-header-decoration-style",
+ "white box",
+ ]);
+ }
+
+ #[test]
+ fn test_hunk_header_style_box_file() {
+ _do_test_hunk_header_style_box_file(&[
+ "--hunk-header-style",
+ "file",
+ "--hunk-header-decoration-style",
+ "white box",
+ ]);
+ }
+
+ #[test]
fn test_hunk_header_style_box_deprecated_options() {
_do_test_hunk_header_style_box(&["--hunk-color", "white", "--hunk-style", "box"]);
}
@@ -1188,23 +1212,77 @@ impl<'a> Alignment<'a> {
ansi_test_utils::assert_line_has_style(
&output,
10,
- "─────────────────────────┐",
+ "─────────────────────────────┐",
+ "white",
+ &config,
+ );
+ ansi_test_utils::assert_line_has_style(
+ &output,
+ 12,
+ "─────────────────────────────┘",
+ "white",
+ &config,
+ );
+ let output = strip_ansi_codes(&output);
+ assert!(output.contains(
+ "
+─────────────────────────────┐
+71: impl<'a> Alignment<'a> { │
+─────────────────────────────┘
+"
+ ));
+ }
+
+ fn _do_test_hunk_header_style_box_file(args: &[&str]) {
+ let config = integration_test_utils::make_config_from_args(args);
+ let output = integration_test_utils::run_delta(GIT_DIFF_SINGLE_HUNK, &config);
+ ansi_test_utils::assert_line_has_style(
+ &output,
+ 10,
+ "───────────────────────────────────────┐",
+ "white",
+ &config,
+ );
+ ansi_test_utils::assert_line_has_style(
+ &output,
+ 12,
+ "───────────────────────────────────────┘",
+ "white",
+ &config,
+ );
+ let output = strip_ansi_codes(&output);
+ assert!(output.contains(
+ "
+───────────────────────────────────────┐
+src/align.rs: impl<'a> Alignment<'a> { │
+───────────────────────────────────────┘
+"
+ ));
+ }
+
+ fn _do_test_hunk_header_style_box_file_line_number(args: &[&str]) {
+ let config = integration_test_utils::make_config_from_args(args);
+ let output = integration_test_utils::run_delta(GIT_DIFF_SINGLE_HUNK, &config);
+ ansi_test_utils::assert_line_has_style(
+ &output,
+ 10,
+ "──────────────────────────────────────────┐",
"white",
&config,
);
ansi_test_utils::assert_line_has_style(
&output,
12,
- "─────────────────────────┘",
+ "──────────────────────────────────────────┘",
"white",
&config,
);
let output = strip_ansi_codes(&output);
assert!(output.contains(
"
-─────────────────────────┐
-impl<'a> Alignment<'a> { │
-─────────────────────────┘
+──────────────────────────────────────────┐
+src/align.rs:71: impl<'a> Alignment<'a> { │
+──────────────────────────────────────────┘
"
));
}
@@ -1263,8 +1341,8 @@ impl<'a> Alignment<'a> { │
let output = strip_ansi_codes(&output);
assert!(output.contains(
"
-impl<'a> Alignment<'a> {
-────────────────────────"
+71: impl<'a> Alignment<'a> {
+────────────────────────────"
));
}
@@ -1274,27 +1352,28 @@ impl<'a> Alignment<'a> {
// otherwise it will confuse assert_line_is_syntax_highlighted.
let config = integration_test_utils::make_config_from_args(&[
"--hunk-header-style",
- "syntax",
+ "line-number syntax",
"--hunk-header-decoration-style",
"box",
]);
let output = integration_test_utils::run_delta(GIT_DIFF_SINGLE_HUNK, &config);
- ansi_test_utils::assert_line_has_no_color(&output, 10, "─────────────────────────┐");
- ansi_test_utils::assert_line_is_syntax_highlighted(
+ ansi_test_utils::assert_line_has_no_color(&output, 10, "─────────────────────────────┐");
+ ansi_test_utils::assert_line_has_syntax_highlighted_substring(
&output,
11,
+ 4,
"impl<'a> Alignment<'a> { ",
"rs",
State::HunkHeader,
&config,
);
- ansi_test_utils::assert_line_has_no_color(&output, 12, "─────────────────────────┘");
+ ansi_test_utils::assert_line_has_no_color(&output, 12, "─────────────────────────────┘");
let output = strip_ansi_codes(&output);
assert!(output.contains(
"
-─────────────────────────┐
-impl<'a> Alignment<'a> { │
-─────────────────────────┘
+─────────────────────────────┐
+71: impl<'a> Alignment<'a> { │
+─────────────────────────────┘
"
));
}
@@ -1370,7 +1449,7 @@ impl<'a> Alignment<'a> { │
empty_line_marker_style,
]);
let output = integration_test_utils::run_delta(example_diff, &config);
- let line = output.lines().nth(6).unwrap();
+ let line = output.lines().nth(8).unwrap();
if base_style_has_background_color {
let style = style::Style::from_str(base_style, None, None, true, false);
assert_eq!(
@@ -1400,11 +1479,11 @@ impl<'a> Alignment<'a> { │
whitespace_error_style,
]);
let output = integration_test_utils::run_delta(DIFF_WITH_WHITESPACE_ERROR, &config);
- ansi_test_utils::assert_line_has_style(&output, 6, " ", whitespace_error_style, &config);
+ ansi_test_utils::assert_line_has_style(&output, 8, " ", whitespace_error_style, &config);
let output = integration_test_utils::run_delta(DIFF_WITH_REMOVED_WHITESPACE_ERROR, &config);
ansi_test_utils::assert_line_does_not_have_style(
&output,
- 6,
+ 8,
" ",
whitespace_error_style,
&config,
@@ -1421,7 +1500,7 @@ impl<'a> Alignment<'a> { │
plus_style,
]);
let output = integration_test_utils::run_delta(DIFF_WITH_ADDED_EMPTY_LINE, &config);
- ansi_test_utils::assert_line_has_style(&output, 6, "", plus_style, &config)
+ ansi_test_utils::assert_line_has_style(&output, 8, "", plus_style, &config)
}
#[test]
@@ -1434,16 +1513,17 @@ impl<'a> Alignment<'a> { │
plus_style,
]);
let output = integration_test_utils::run_delta(DIFF_WITH_SINGLE_CHARACTER_LINE, &config);
- ansi_test_utils::assert_line_has_style(&output, 12, "+}", plus_style, &config)
+ ansi_test_utils::assert_line_has_style(&output, 14, "+}", plus_style, &config)
}
#[test]
fn test_color_only() {
let config = integration_test_utils::make_config_from_args(&["--color-only"]);
let output = integration_test_utils::run_delta(GIT_DIFF_SINGLE_HUNK, &config);
- ansi_test_utils::assert_line_is_syntax_highlighted(
+ ansi_test_utils::assert_line_has_syntax_highlighted_substring(
&output,
12,
+ 1,
" for (i, x_i) in self.x.iter().enumerate() {",
"rs",
State::HunkZero,