diff options
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) |