diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2021-08-19 16:48:59 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2021-08-19 16:48:59 -0700 |
commit | 07fcbb558d797272b9f43547da60beda485873a3 (patch) | |
tree | 77d5da14e9f9d9d8b1d877c70c01296fd3893796 /test/lisp/vc/diff-mode-tests.el | |
parent | c9bdeff3e45a7ac84a74a81bb048046f82dddc91 (diff) | |
parent | fb81c8c3adf8633f2f617c82f6019aef630860c7 (diff) | |
download | emacs-07fcbb558d797272b9f43547da60beda485873a3.tar.gz |
Merge remote-tracking branch 'origin/master' into athena/unstable
Diffstat (limited to 'test/lisp/vc/diff-mode-tests.el')
-rw-r--r-- | test/lisp/vc/diff-mode-tests.el | 154 |
1 files changed, 154 insertions, 0 deletions
diff --git a/test/lisp/vc/diff-mode-tests.el b/test/lisp/vc/diff-mode-tests.el index f4e5c89afb4..fefe50d5173 100644 --- a/test/lisp/vc/diff-mode-tests.el +++ b/test/lisp/vc/diff-mode-tests.el @@ -203,6 +203,148 @@ youthfulness (kill-buffer buf2) (delete-directory temp-dir 'recursive)))))) +(ert-deftest diff-mode-test-hunk-text-no-newline () + "Check output of `diff-hunk-text' with no newline at end of file." + + ;; First check unified change/remove/add cases with newline + (let ((hunk "\ +@@ -1 +1 @@ +-foo ++bar +")) + (should (equal (diff-hunk-text hunk nil nil) "\ +foo +")) + (should (equal (diff-hunk-text hunk t nil) "\ +bar +"))) + + (let ((hunk "\ +@@ -1 +0,0 @@ +-foo +")) + (should (equal (diff-hunk-text hunk nil nil) "\ +foo +")) + (should (equal (diff-hunk-text hunk t nil) "\ +"))) + + (let ((hunk "\ +@@ -0,0 +1 @@ ++bar +")) + (should (equal (diff-hunk-text hunk nil nil) "\ +")) + (should (equal (diff-hunk-text hunk t nil) "\ +bar +"))) + + ;; Check unified change/remove cases with no newline in old file + (let ((hunk "\ +@@ -1 +1 @@ +-foo +\\ No newline at end of file ++bar +")) + (should (equal (diff-hunk-text hunk nil nil) "\ +foo")) + (should (equal (diff-hunk-text hunk t nil) "\ +bar +"))) + + (let ((hunk "\ +@@ -1 +0,0 @@ +-foo +\\ No newline at end of file +")) + (should (equal (diff-hunk-text hunk nil nil) "\ +foo")) + (should (equal (diff-hunk-text hunk t nil) "\ +"))) + + ;; Check unified change/add cases with no newline in new file + (let ((hunk "\ +@@ -1 +1 @@ +-foo ++bar +\\ No newline at end of file +")) + (should (equal (diff-hunk-text hunk nil nil) "\ +foo +")) + (should (equal (diff-hunk-text hunk t nil) "\ +bar"))) + + (let ((hunk "\ +@@ -0,0 +1 @@ ++bar +\\ No newline at end of file +")) + (should (equal (diff-hunk-text hunk nil nil) "\ +")) + (should (equal (diff-hunk-text hunk t nil) "\ +bar"))) + + ;; Check unified change case with no newline in both old/new file + (let ((hunk "\ +@@ -1 +1 @@ +-foo +\\ No newline at end of file ++bar +\\ No newline at end of file +")) + (should (equal (diff-hunk-text hunk nil nil) "\ +foo")) + (should (equal (diff-hunk-text hunk t nil) "\ +bar"))) + + ;; Check context-after unified change case with no newline in both old/new file + (let ((hunk "\ +@@ -1,2 +1,2 @@ +-foo ++bar + baz +\\ No newline at end of file +")) + (should (equal (diff-hunk-text hunk nil nil) "\ +foo +baz")) + (should (equal (diff-hunk-text hunk t nil) "\ +bar +baz"))) + + (let ((hunk "\ +@@ -1,2 +1,2 @@ +-foo +-baz +\\ No newline at end of file ++bar ++baz +")) + (should (equal (diff-hunk-text hunk nil nil) "\ +foo +baz")) + (should (equal (diff-hunk-text hunk t nil) "\ +bar +baz +"))) + + (let ((hunk "\ +@@ -1,2 +1,2 @@ +-foo +-baz ++bar ++baz +\\ No newline at end of file +")) + (should (equal (diff-hunk-text hunk nil nil) "\ +foo +baz +")) + (should (equal (diff-hunk-text hunk t nil) "\ +bar +baz")))) + (ert-deftest diff-mode-test-font-lock () "Check font-locking of diff hunks." ;; See comments in diff-hunk-file-names about nonascii. @@ -326,4 +468,16 @@ youthfulness (114 131 (diff-mode syntax face font-lock-string-face)) (134 140 (diff-mode syntax face font-lock-keyword-face)))))))) +(ert-deftest test-hunk-file-names () + (with-temp-buffer + (insert "diff -c /tmp/ange-ftp13518wvE.el /tmp/ange-ftp1351895K.el\n") + (goto-char (point-min)) + (should (equal (diff-hunk-file-names) + '("/tmp/ange-ftp1351895K.el" "/tmp/ange-ftp13518wvE.el")))) + (with-temp-buffer + (insert "diff -c -L /ftp:slbhao:/home/albinus/src/tramp/lisp/tramp.el -L /ftp:slbhao:/home/albinus/src/emacs/lisp/net/tramp.el /tmp/ange-ftp13518wvE.el /tmp/ange-ftp1351895K.el\n") + (goto-char (point-min)) + (should (equal (diff-hunk-file-names) + '("/tmp/ange-ftp1351895K.el" "/tmp/ange-ftp13518wvE.el"))))) + (provide 'diff-mode-tests) |