From 675c08cee899444f33113b806d6709b569c44790 Mon Sep 17 00:00:00 2001 From: Peter Oliver Date: Tue, 27 Apr 2021 16:24:58 +0100 Subject: [PATCH] Test ruby-mode-set-encoding with a few different encodings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follows on from Dmitry Gutov’s patch in https://debbugs.gnu.org/cgi/bugreport.cgi?bug=48043#8. --- test/lisp/progmodes/ruby-mode-tests.el | 30 ++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/lisp/progmodes/ruby-mode-tests.el b/test/lisp/progmodes/ruby-mode-tests.el index 42a011c8bc..fec7d86a95 100644 --- a/test/lisp/progmodes/ruby-mode-tests.el +++ b/test/lisp/progmodes/ruby-mode-tests.el @@ -32,6 +32,12 @@ ruby-with-temp-buffer (ruby-mode) ,@body)) +(defmacro ruby-with-temp-file (contents &rest body) + `(ruby-with-temp-buffer ,contents + (set-visited-file-name "ruby-mode-tests") + ,@body + (delete-file buffer-file-name))) + (defun ruby-should-indent (content column) "Assert indentation COLUMN on the last line of CONTENT." (ruby-with-temp-buffer content @@ -844,6 +850,30 @@ ruby--insert-coding-comment-custom-style (ruby--insert-coding-comment "utf-8") (should (string= "# encoding: utf-8\n\n" (buffer-string)))))) +(ert-deftest ruby--set-encoding-when-ascii () + (ruby-with-temp-file "ascii" + (let ((ruby-encoding-magic-comment-style 'ruby) + (ruby-insert-encoding-magic-comment t)) + (setq save-buffer-coding-system 'us-ascii) + (ruby-mode-set-encoding) + (should (string= "ascii" (buffer-string)))))) + +(ert-deftest ruby--set-encoding-when-utf8 () + (ruby-with-temp-file "💎" + (let ((ruby-encoding-magic-comment-style 'ruby) + (ruby-insert-encoding-magic-comment t)) + (setq save-buffer-coding-system 'utf-8) + (ruby-mode-set-encoding) + (should (string= "💎" (buffer-string)))))) + +(ert-deftest ruby--set-encoding-when-latin-15 () + (ruby-with-temp-file "Ⓡ" + (let ((ruby-encoding-magic-comment-style 'ruby) + (ruby-insert-encoding-magic-comment t)) + (setq save-buffer-coding-system 'iso-8859-15) + (ruby-mode-set-encoding) + (should (string= "# coding: iso-8859-15\nⓇ" (buffer-string)))))) + (ert-deftest ruby--indent/converted-from-manual-test () :tags '(:expensive-test) ;; Converted from manual test. -- 2.26.3