* 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
(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)))
(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))