Do not show diffs for files with \r\n contents (#11519)

This commit is contained in:
Kirill Bulatov
2024-05-08 00:37:09 +03:00
committed by GitHub
parent 6a64b732b6
commit 3d9f0087ff
6 changed files with 56 additions and 33 deletions
+29 -4
View File
@@ -2826,6 +2826,31 @@ async fn test_join_lines_with_git_diff_base(
);
}
#[gpui::test]
async fn test_custom_newlines_cause_no_false_positive_diffs(
executor: BackgroundExecutor,
cx: &mut gpui::TestAppContext,
) {
init_test(cx, |_| {});
let mut cx = EditorTestContext::new(cx).await;
cx.set_state("Line 0\r\nLine 1\rˇ\nLine 2\r\nLine 3");
cx.set_diff_base(Some("Line 0\r\nLine 1\r\nLine 2\r\nLine 3"));
executor.run_until_parked();
cx.update_editor(|editor, cx| {
assert_eq!(
editor
.buffer()
.read(cx)
.snapshot(cx)
.git_diff_hunks_in_range(0..u32::MAX)
.collect::<Vec<_>>(),
Vec::new(),
"Should not have any diffs for files with custom newlines"
);
});
}
#[gpui::test]
async fn test_manipulate_lines_with_single_selection(cx: &mut TestAppContext) {
init_test(cx, |_| {});
@@ -9026,7 +9051,7 @@ async fn test_multibuffer_reverts(cx: &mut gpui::TestAppContext) {
.collect::<String>(),
cx,
);
buffer.set_diff_base(Some(sample_text.into()), cx);
buffer.set_diff_base(Some(sample_text), cx);
});
cx.executor().run_until_parked();
}
@@ -10041,17 +10066,17 @@ async fn test_toggle_diff_expand_in_multi_buffer(cx: &mut gpui::TestAppContext)
"vvvv\nwwww\nxxxx\nyyyy\nzzzz\n@@@@\n{{{{\n||||\n}}}}\n~~~~\n\u{7f}\u{7f}\u{7f}\u{7f}";
let buffer_1 = cx.new_model(|cx| {
let mut buffer = Buffer::local(modified_sample_text_1.to_string(), cx);
buffer.set_diff_base(Some(sample_text_1.clone().into()), cx);
buffer.set_diff_base(Some(sample_text_1.clone()), cx);
buffer
});
let buffer_2 = cx.new_model(|cx| {
let mut buffer = Buffer::local(modified_sample_text_2.to_string(), cx);
buffer.set_diff_base(Some(sample_text_2.clone().into()), cx);
buffer.set_diff_base(Some(sample_text_2.clone()), cx);
buffer
});
let buffer_3 = cx.new_model(|cx| {
let mut buffer = Buffer::local(modified_sample_text_3.to_string(), cx);
buffer.set_diff_base(Some(sample_text_3.clone().into()), cx);
buffer.set_diff_base(Some(sample_text_3.clone()), cx);
buffer
});
+2 -4
View File
@@ -145,8 +145,7 @@ mod tests {
1.five
1.six
"
.unindent()
.into(),
.unindent(),
),
cx,
);
@@ -182,8 +181,7 @@ mod tests {
2.four
2.six
"
.unindent()
.into(),
.unindent(),
),
cx,
);
@@ -21,7 +21,6 @@ use std::{
Arc,
},
};
use text::Rope;
use ui::Context;
use util::{
assert_set_eq,
@@ -272,8 +271,7 @@ impl EditorTestContext {
}
pub fn set_diff_base(&mut self, diff_base: Option<&str>) {
let diff_base = diff_base.map(Rope::from);
self.update_buffer(|buffer, cx| buffer.set_diff_base(diff_base, cx));
self.update_buffer(|buffer, cx| buffer.set_diff_base(diff_base.map(ToOwned::to_owned), cx));
}
/// Change the editor's text and selections using a string containing