* lisp/progmodes/ruby-mode.el (ruby-add-log-current-method): Print the
[bpt/emacs.git] / test / automated / ruby-mode-tests.el
index 741692a..0e41b2b 100644 (file)
 
 The whitespace before and including \"|\" on each line is removed."
   (with-temp-buffer
-    (cl-flet ((fix-indent (s) (replace-regexp-in-string "^[ \t]*|" "" s)))
-      (insert (fix-indent content))
-      (ruby-mode)
-      (indent-region (point-min) (point-max))
-      (should (string= (fix-indent expected) (buffer-string))))))
+    (insert (ruby-test-string content))
+    (ruby-mode)
+    (indent-region (point-min) (point-max))
+    (should (string= (ruby-test-string expected) (buffer-string)))))
+
+(defun ruby-test-string (s &rest args)
+  (apply 'format (replace-regexp-in-string "^[ \t]*|" "" s) args))
 
 (defun ruby-assert-state (content &rest values-plist)
   "Assert syntax state values at the end of CONTENT.
@@ -261,6 +263,26 @@ VALUES-PLIST is a list with alternating index and value elements."
   (ruby-assert-face "# #{comment}\n \"#{interpolation}\"" 16
                     'font-lock-variable-name-face))
 
+(ert-deftest ruby-add-log-current-method-examples ()
+  (let ((pairs '(("foo" . "#foo")
+                 ("C.foo" . ".foo")
+                 ("self.foo" . ".foo"))))
+    (loop for (name . value) in pairs
+          do (with-temp-buffer
+               (insert (ruby-test-string
+                        "module M
+                        |  class C
+                        |    def %s
+                        |    end
+                        |  end
+                        |end"
+                        name))
+               (ruby-mode)
+               (search-backward "def")
+               (forward-line)
+               (should (string= (ruby-add-log-current-method)
+                                (format "M::C%s" value)))))))
+
 (provide 'ruby-mode-tests)
 
 ;;; ruby-mode-tests.el ends here