aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSriram Thaiyar2016-06-22 09:21:26 -0700
committerDmitry Gutov2016-06-27 07:31:39 +0300
commit7f02dedfcae6ba0e3a646c1367c908af9b3dbe1d (patch)
tree1d2880f718e78d7170655a9eae65bdff08eea36c
parentdd98ee8992c3246861e44447ffcd02886a52878e (diff)
downloademacs-7f02dedfcae6ba0e3a646c1367c908af9b3dbe1d.tar.gz
emacs-7f02dedfcae6ba0e3a646c1367c908af9b3dbe1d.zip
Fix quote escaping in ruby-toggle-string-quotes
* lisp/progmodes/ruby-mode.el (ruby-toggle-string-quotes): Change logic to quote based on the current quote of the string. * test/lisp/progmodes/ruby-mode-tests.el (ruby-toggle-string-quotes-quotes-correctly): Add test. Copyright-paperwork-exempt: yes
-rw-r--r--lisp/progmodes/ruby-mode.el2
-rw-r--r--test/lisp/progmodes/ruby-mode-tests.el11
2 files changed, 12 insertions, 1 deletions
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index d75edbc84ef..aa7c08c542f 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -1799,7 +1799,7 @@ If the result is do-end block, it will always be multiline."
1799 (content 1799 (content
1800 (buffer-substring-no-properties (1+ min) (1- max)))) 1800 (buffer-substring-no-properties (1+ min) (1- max))))
1801 (setq content 1801 (setq content
1802 (if (equal string-quote "\"") 1802 (if (equal string-quote "'")
1803 (replace-regexp-in-string "\\\\\"" "\"" (replace-regexp-in-string "\\([^\\\\]\\)'" "\\1\\\\'" content)) 1803 (replace-regexp-in-string "\\\\\"" "\"" (replace-regexp-in-string "\\([^\\\\]\\)'" "\\1\\\\'" content))
1804 (replace-regexp-in-string "\\\\'" "'" (replace-regexp-in-string "\\([^\\\\]\\)\"" "\\1\\\\\"" content)))) 1804 (replace-regexp-in-string "\\\\'" "'" (replace-regexp-in-string "\\([^\\\\]\\)\"" "\\1\\\\\"" content))))
1805 (let ((orig-point (point))) 1805 (let ((orig-point (point)))
diff --git a/test/lisp/progmodes/ruby-mode-tests.el b/test/lisp/progmodes/ruby-mode-tests.el
index 52126a3bdf1..5dd34f8ee41 100644
--- a/test/lisp/progmodes/ruby-mode-tests.el
+++ b/test/lisp/progmodes/ruby-mode-tests.el
@@ -716,6 +716,17 @@ VALUES-PLIST is a list with alternating index and value elements."
716 (ruby-backward-sexp) 716 (ruby-backward-sexp)
717 (should (= 2 (line-number-at-pos))))) 717 (should (= 2 (line-number-at-pos)))))
718 718
719(ert-deftest ruby-toggle-string-quotes-quotes-correctly ()
720 (let ((pairs
721 '(("puts 'foo\"\\''" . "puts \"foo\\\"'\"")
722 ("puts \"foo'\\\"\"" . "puts 'foo\\'\"'"))))
723 (dolist (pair pairs)
724 (ruby-with-temp-buffer (car pair)
725 (beginning-of-line)
726 (search-forward "foo")
727 (ruby-toggle-string-quotes)
728 (should (string= (buffer-string) (cdr pair)))))))
729
719(ert-deftest ruby--insert-coding-comment-ruby-style () 730(ert-deftest ruby--insert-coding-comment-ruby-style ()
720 (with-temp-buffer 731 (with-temp-buffer
721 (let ((ruby-encoding-magic-comment-style 'ruby)) 732 (let ((ruby-encoding-magic-comment-style 'ruby))