summaryrefslogtreecommitdiff
path: root/test/lisp/files-tests.el
diff options
context:
space:
mode:
authorMauro Aranda <maurooaranda@gmail.com>2020-09-20 01:04:39 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2020-09-20 01:04:39 +0200
commit1278a9a907e59b22d8e20a806055c7cb92959017 (patch)
tree38f476a3a267e5af87fd8f03fb6e416d07842f13 /test/lisp/files-tests.el
parent4d184fb07f543d96c0a3a40480a0d8b86c472931 (diff)
downloademacs-1278a9a907e59b22d8e20a806055c7cb92959017.tar.gz
emacs-1278a9a907e59b22d8e20a806055c7cb92959017.tar.bz2
emacs-1278a9a907e59b22d8e20a806055c7cb92959017.zip
New command: revert-buffer-with-fine-grain
* doc/emacs/files.texi (Reverting): Document the new command and the new variable. * etc/NEWS: Mention the new command and the new variable. * lisp/files.el (revert-buffer-with-fine-grain): New command. Revert a buffer trying to be non-destructive, by using replace-buffer-contents. (revert-buffer-insert-file-contents-delicately): New function, alternative to revert-buffer-insert-file-contents-function--default-function. (revert-buffer-with-fine-grain-max-seconds): New variable. Passed as argument MAX-SECS of replace-buffer-contents. * test/lisp/files-tests.el (files-tests-lao files-tests-tzu): Helper variables, taken from diffutils manual, to test reverting a buffer. (files-tests-revert-buffer) (files-tests-revert-buffer-with-fine-grain): New tests (bug#18).
Diffstat (limited to 'test/lisp/files-tests.el')
-rw-r--r--test/lisp/files-tests.el54
1 files changed, 54 insertions, 0 deletions
diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el
index b73eac28174..34777013c35 100644
--- a/test/lisp/files-tests.el
+++ b/test/lisp/files-tests.el
@@ -1377,5 +1377,59 @@ See <https://debbugs.gnu.org/36401>."
(normal-mode)
(should (eq major-mode 'mhtml-mode))))
+(defvar files-tests-lao "The Way that can be told of is not the eternal Way;
+The name that can be named is not the eternal name.
+The Nameless is the origin of Heaven and Earth;
+The Named is the mother of all things.
+Therefore let there always be non-being,
+ so we may see their subtlety,
+And let there always be being,
+ so we may see their outcome.
+The two are the same,
+But after they are produced,
+ they have different names.
+")
+
+(defvar files-tests-tzu "The Nameless is the origin of Heaven and Earth;
+The named is the mother of all things.
+
+Therefore let there always be non-being,
+ so we may see their subtlety,
+And let there always be being,
+ so we may see their outcome.
+The two are the same,
+But after they are produced,
+ they have different names.
+They both may be called deep and profound.
+Deeper and more profound,
+The door of all subtleties!
+")
+
+(ert-deftest files-tests-revert-buffer ()
+ "Test that revert-buffer is succesful."
+ (files-tests--with-temp-file temp-file-name
+ (with-temp-buffer
+ (insert files-tests-lao)
+ (write-file temp-file-name)
+ (erase-buffer)
+ (insert files-tests-tzu)
+ (revert-buffer t t t)
+ (should (compare-strings files-tests-lao nil nil
+ (buffer-substring (point-min) (point-max))
+ nil nil)))))
+
+(ert-deftest files-tests-revert-buffer-with-fine-grain ()
+ "Test that revert-buffer-with-fine-grain is successful."
+ (files-tests--with-temp-file temp-file-name
+ (with-temp-buffer
+ (insert files-tests-lao)
+ (write-file temp-file-name)
+ (erase-buffer)
+ (insert files-tests-tzu)
+ (should (revert-buffer-with-fine-grain t t))
+ (should (compare-strings files-tests-lao nil nil
+ (buffer-substring (point-min) (point-max))
+ nil nil)))))
+
(provide 'files-tests)
;;; files-tests.el ends here