diff options
author | Tim Oram <dev@mitmaro.ca> | 2020-12-21 12:14:33 -0330 |
---|---|---|
committer | Tim Oram <dev@mitmaro.ca> | 2020-12-22 11:48:24 -0330 |
commit | 1a4335ae551b95a27da71b5c92ba35829bc64db2 (patch) | |
tree | 8f0186d8705ab8181f52062b1aefd1ad64cd1c35 | |
parent | 6c21a46d8d5c4846459ea2891f6e56bdf20616d6 (diff) |
Fix context parsing in show_commit::delta
Context was incorrectly splitting on @ instead of @@, resulting in the
context being double rendered.
-rw-r--r-- | src/show_commit/delta.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/show_commit/delta.rs b/src/show_commit/delta.rs index 63870f7..f5713b5 100644 --- a/src/show_commit/delta.rs +++ b/src/show_commit/delta.rs @@ -13,7 +13,7 @@ pub struct Delta { impl Delta { pub(super) fn new(header: &str, old_start: u32, new_start: u32, old_lines: u32, new_lines: u32) -> Self { - let context = header.splitn(3, '@').nth(2).unwrap_or("").trim(); + let context = header.splitn(3, "@@").nth(2).unwrap_or("").trim(); Self { old_start, old_lines, @@ -60,7 +60,7 @@ mod tests { #[test] fn new_with_correctly_formatted_context() { - let delta = Delta::new("@ src/show_commit/delta.rs:56 @ impl Delta {", 10, 12, 3, 4); + let delta = Delta::new("@@ src/show_commit/delta.rs:56 @@ impl Delta {", 10, 12, 3, 4); assert_eq!(delta.context(), "impl Delta {"); assert_eq!(delta.old_start(), 10); assert_eq!(delta.new_start(), 12); @@ -70,8 +70,8 @@ mod tests { #[test] fn new_with_at_symbol_in_context() { - let delta = Delta::new("@ path:1 @ Context@", 10, 12, 3, 4); - assert_eq!(delta.context(), "Context@"); + let delta = Delta::new("@@ path:1 @@ Context@@", 10, 12, 3, 4); + assert_eq!(delta.context(), "Context@@"); assert_eq!(delta.old_start(), 10); assert_eq!(delta.new_start(), 12); assert_eq!(delta.old_lines(), 3); @@ -80,7 +80,7 @@ mod tests { #[test] fn new_with_incorrectly_formatted_context() { - let delta = Delta::new("@invalid", 10, 12, 3, 4); + let delta = Delta::new("@@invalid", 10, 12, 3, 4); assert_eq!(delta.context(), ""); assert_eq!(delta.old_start(), 10); assert_eq!(delta.new_start(), 12); @@ -90,7 +90,7 @@ mod tests { #[test] fn add_line() { - let mut delta = Delta::new("@ src/show_commit/delta.rs:56 @ impl Delta {", 10, 12, 3, 4); + let mut delta = Delta::new("@@ src/show_commit/delta.rs:56 @@ impl Delta {", 10, 12, 3, 4); delta.add_line(DiffLine::new( Origin::Addition, "this is a line", |