]> code.delx.au - gnu-emacs/commitdiff
Fix quote escaping in ruby-toggle-string-quotes
authorSriram Thaiyar <sriram.thaiyar@gmail.com>
Wed, 22 Jun 2016 16:21:26 +0000 (09:21 -0700)
committerDmitry Gutov <dgutov@yandex.ru>
Mon, 27 Jun 2016 04:31:39 +0000 (07:31 +0300)
* 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

lisp/progmodes/ruby-mode.el
test/lisp/progmodes/ruby-mode-tests.el

index d75edbc84ef20989ba8560b5fcfdbe0b44e7837d..aa7c08c542f79dbcbf6e84ec72053fd6883213bf 100644 (file)
@@ -1799,7 +1799,7 @@ If the result is do-end block, it will always be multiline."
            (content
             (buffer-substring-no-properties (1+ min) (1- max))))
       (setq content
-            (if (equal string-quote "\"")
+            (if (equal string-quote "'")
                 (replace-regexp-in-string "\\\\\"" "\"" (replace-regexp-in-string "\\([^\\\\]\\)'" "\\1\\\\'" content))
               (replace-regexp-in-string "\\\\'" "'" (replace-regexp-in-string "\\([^\\\\]\\)\"" "\\1\\\\\"" content))))
       (let ((orig-point (point)))
index 52126a3bdf142365eee3f57dfc39c4535079722a..5dd34f8ee415374d12b37e4c28bf1e6d9c9adf82 100644 (file)
@@ -716,6 +716,17 @@ VALUES-PLIST is a list with alternating index and value elements."
     (ruby-backward-sexp)
     (should (= 2 (line-number-at-pos)))))
 
+(ert-deftest ruby-toggle-string-quotes-quotes-correctly ()
+  (let ((pairs
+         '(("puts 'foo\"\\''" . "puts \"foo\\\"'\"")
+           ("puts \"foo'\\\"\"" . "puts 'foo\\'\"'"))))
+    (dolist (pair pairs)
+      (ruby-with-temp-buffer (car pair)
+        (beginning-of-line)
+        (search-forward "foo")
+        (ruby-toggle-string-quotes)
+        (should (string= (buffer-string) (cdr pair)))))))
+
 (ert-deftest ruby--insert-coding-comment-ruby-style ()
   (with-temp-buffer
     (let ((ruby-encoding-magic-comment-style 'ruby))