aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Oliver2021-04-28 05:18:40 +0300
committerDmitry Gutov2021-04-28 05:18:40 +0300
commita9fc30e6c2ea67d7a2faa5c218af5bcae9f31246 (patch)
tree67f622e461eda56e01a1a466ce7fcf51f878aa2a
parent6a078097c98902b3d90ec614a8f96d027203c812 (diff)
downloademacs-a9fc30e6c2ea67d7a2faa5c218af5bcae9f31246.tar.gz
emacs-a9fc30e6c2ea67d7a2faa5c218af5bcae9f31246.zip
Add tests
* test/lisp/progmodes/ruby-mode-tests.el (ruby-with-temp-file): New helper. (ruby--set-encoding-when-ascii, ruby--set-encoding-when-utf8) (ruby--set-encoding-when-latin-15): Tests for the previous commit (bug#48043).
-rw-r--r--test/lisp/progmodes/ruby-mode-tests.el31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/lisp/progmodes/ruby-mode-tests.el b/test/lisp/progmodes/ruby-mode-tests.el
index 42a011c8bcd..e2ea0d91370 100644
--- a/test/lisp/progmodes/ruby-mode-tests.el
+++ b/test/lisp/progmodes/ruby-mode-tests.el
@@ -32,6 +32,13 @@
32 (ruby-mode) 32 (ruby-mode)
33 ,@body)) 33 ,@body))
34 34
35(defmacro ruby-with-temp-file (contents &rest body)
36 `(ruby-with-temp-buffer ,contents
37 (set-visited-file-name "ruby-mode-tests")
38 ,@body
39 (set-buffer-modified-p nil)
40 (delete-file buffer-file-name)))
41
35(defun ruby-should-indent (content column) 42(defun ruby-should-indent (content column)
36 "Assert indentation COLUMN on the last line of CONTENT." 43 "Assert indentation COLUMN on the last line of CONTENT."
37 (ruby-with-temp-buffer content 44 (ruby-with-temp-buffer content
@@ -844,6 +851,30 @@ VALUES-PLIST is a list with alternating index and value elements."
844 (ruby--insert-coding-comment "utf-8") 851 (ruby--insert-coding-comment "utf-8")
845 (should (string= "# encoding: utf-8\n\n" (buffer-string)))))) 852 (should (string= "# encoding: utf-8\n\n" (buffer-string))))))
846 853
854(ert-deftest ruby--set-encoding-when-ascii ()
855 (ruby-with-temp-file "ascii"
856 (let ((ruby-encoding-magic-comment-style 'ruby)
857 (ruby-insert-encoding-magic-comment t))
858 (setq save-buffer-coding-system 'us-ascii)
859 (ruby-mode-set-encoding)
860 (should (string= "ascii" (buffer-string))))))
861
862(ert-deftest ruby--set-encoding-when-utf8 ()
863 (ruby-with-temp-file "šŸ’Ž"
864 (let ((ruby-encoding-magic-comment-style 'ruby)
865 (ruby-insert-encoding-magic-comment t))
866 (setq save-buffer-coding-system 'utf-8)
867 (ruby-mode-set-encoding)
868 (should (string= "šŸ’Ž" (buffer-string))))))
869
870(ert-deftest ruby--set-encoding-when-latin-15 ()
871 (ruby-with-temp-file "Ⓡ"
872 (let ((ruby-encoding-magic-comment-style 'ruby)
873 (ruby-insert-encoding-magic-comment t))
874 (setq save-buffer-coding-system 'iso-8859-15)
875 (ruby-mode-set-encoding)
876 (should (string= "# coding: iso-8859-15\nⓇ" (buffer-string))))))
877
847(ert-deftest ruby--indent/converted-from-manual-test () 878(ert-deftest ruby--indent/converted-from-manual-test ()
848 :tags '(:expensive-test) 879 :tags '(:expensive-test)
849 ;; Converted from manual test. 880 ;; Converted from manual test.