(ruby-mode)
,@body))
+(defmacro ruby-with-temp-file (contents &rest body)
+ `(ruby-with-temp-buffer ,contents
+ (set-visited-file-name "ruby-mode-tests")
+ ,@body
+ (set-buffer-modified-p nil)
+ (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
(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.