aboutsummaryrefslogtreecommitdiff
path: root/helix-vcs/src/diff/worker/test.rs
diff options
context:
space:
mode:
authorPascal Kuthe2022-12-01 08:35:23 +0000
committerGitHub2022-12-01 08:35:23 +0000
commit5a3ff742218aac32c3af08993f0edb623631fc72 (patch)
tree55c09d58aef9284daf63224e1d3afaac6da26ee8 /helix-vcs/src/diff/worker/test.rs
parent67415e096ea70173d30550803559eb2347ed04d6 (diff)
Show (git) diff signs in gutter (#3890)
* Show (git) diff signs in gutter (#3890) Avoid string allocation when git diffing Incrementally diff using changesets refactor diffs to be provider indepndent and improve git implementation remove dependency on zlib-ng switch to asynchronus diffing with similar Update helix-vcs/Cargo.toml fix toml formatting Co-authored-by: Ivan Tham <pickfire@riseup.net> fix typo in documentation use ropey reexpors from helix-core fix crash when creating new file remove useless use if io::Cursor fix spelling mistakes implement suggested improvement to repository loading improve git test isolation remove lefover comments Co-authored-by: univerz <univerz@fu-solution.com> fixed spelling mistake minor cosmetic changes fix: set self.differ to None if decoding the diff_base fails fixup formatting Co-authored-by: Ivan Tham <pickfire@riseup.net> reload diff_base when file is reloaded from disk switch to imara-diff Fixup formatting Co-authored-by: Blaž Hrastnik <blaz@mxxn.io> Redraw buffer whenever a diff is updated. Only store hunks instead of changes for individual lines to easily allow jumping between them Update to latest gitoxide version Change default diff gutter position Only update gutter after timeout * update diff gutter synchronously, with a timeout * Apply suggestions from code review Co-authored-by: Blaž Hrastnik <blaz@mxxn.io> Co-authored-by: Michael Davis <mcarsondavis@gmail.com> * address review comments and ensure lock is always aquired * remove configuration for redraw timeout Co-authored-by: Blaž Hrastnik <blaz@mxxn.io> Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
Diffstat (limited to 'helix-vcs/src/diff/worker/test.rs')
-rw-r--r--helix-vcs/src/diff/worker/test.rs149
1 files changed, 149 insertions, 0 deletions
diff --git a/helix-vcs/src/diff/worker/test.rs b/helix-vcs/src/diff/worker/test.rs
new file mode 100644
index 00000000..14442426
--- /dev/null
+++ b/helix-vcs/src/diff/worker/test.rs
@@ -0,0 +1,149 @@
+use helix_core::Rope;
+use tokio::task::JoinHandle;
+
+use crate::diff::{DiffHandle, Hunk};
+
+impl DiffHandle {
+ fn new_test(diff_base: &str, doc: &str) -> (DiffHandle, JoinHandle<()>) {
+ DiffHandle::new_with_handle(
+ Rope::from_str(diff_base),
+ Rope::from_str(doc),
+ Default::default(),
+ )
+ }
+ async fn into_diff(self, handle: JoinHandle<()>) -> Vec<Hunk> {
+ let hunks = self.hunks;
+ // dropping the channel terminates the task
+ drop(self.channel);
+ handle.await.unwrap();
+ let hunks = hunks.lock();
+ Vec::clone(&*hunks)
+ }
+}
+
+#[tokio::test]
+async fn append_line() {
+ let (differ, handle) = DiffHandle::new_test("foo\n", "foo\nbar\n");
+ let line_diffs = differ.into_diff(handle).await;
+ assert_eq!(
+ &line_diffs,
+ &[Hunk {
+ before: 1..1,
+ after: 1..2
+ }]
+ )
+}
+
+#[tokio::test]
+async fn prepend_line() {
+ let (differ, handle) = DiffHandle::new_test("foo\n", "bar\nfoo\n");
+ let line_diffs = differ.into_diff(handle).await;
+ assert_eq!(
+ &line_diffs,
+ &[Hunk {
+ before: 0..0,
+ after: 0..1
+ }]
+ )
+}
+
+#[tokio::test]
+async fn modify() {
+ let (differ, handle) = DiffHandle::new_test("foo\nbar\n", "foo bar\nbar\n");
+ let line_diffs = differ.into_diff(handle).await;
+ assert_eq!(
+ &line_diffs,
+ &[Hunk {
+ before: 0..1,
+ after: 0..1
+ }]
+ )
+}
+
+#[tokio::test]
+async fn delete_line() {
+ let (differ, handle) = DiffHandle::new_test("foo\nfoo bar\nbar\n", "foo\nbar\n");
+ let line_diffs = differ.into_diff(handle).await;
+ assert_eq!(
+ &line_diffs,
+ &[Hunk {
+ before: 1..2,
+ after: 1..1
+ }]
+ )
+}
+
+#[tokio::test]
+async fn delete_line_and_modify() {
+ let (differ, handle) = DiffHandle::new_test("foo\nbar\ntest\nfoo", "foo\ntest\nfoo bar");
+ let line_diffs = differ.into_diff(handle).await;
+ assert_eq!(
+ &line_diffs,
+ &[
+ Hunk {
+ before: 1..2,
+ after: 1..1
+ },
+ Hunk {
+ before: 3..4,
+ after: 2..3
+ },
+ ]
+ )
+}
+
+#[tokio::test]
+async fn add_use() {
+ let (differ, handle) = DiffHandle::new_test(
+ "use ropey::Rope;\nuse tokio::task::JoinHandle;\n",
+ "use ropey::Rope;\nuse ropey::RopeSlice;\nuse tokio::task::JoinHandle;\n",
+ );
+ let line_diffs = differ.into_diff(handle).await;
+ assert_eq!(
+ &line_diffs,
+ &[Hunk {
+ before: 1..1,
+ after: 1..2
+ },]
+ )
+}
+
+#[tokio::test]
+async fn update_document() {
+ let (differ, handle) = DiffHandle::new_test("foo\nbar\ntest\nfoo", "foo\nbar\ntest\nfoo");
+ differ.update_document(Rope::from_str("foo\ntest\nfoo bar"), false);
+ let line_diffs = differ.into_diff(handle).await;
+ assert_eq!(
+ &line_diffs,
+ &[
+ Hunk {
+ before: 1..2,
+ after: 1..1
+ },
+ Hunk {
+ before: 3..4,
+ after: 2..3
+ },
+ ]
+ )
+}
+
+#[tokio::test]
+async fn update_base() {
+ let (differ, handle) = DiffHandle::new_test("foo\ntest\nfoo bar", "foo\ntest\nfoo bar");
+ differ.update_diff_base(Rope::from_str("foo\nbar\ntest\nfoo"));
+ let line_diffs = differ.into_diff(handle).await;
+ assert_eq!(
+ &line_diffs,
+ &[
+ Hunk {
+ before: 1..2,
+ after: 1..1
+ },
+ Hunk {
+ before: 3..4,
+ after: 2..3
+ },
+ ]
+ )
+}