]> code.delx.au - gnu-emacs/blobdiff - test/lisp/progmodes/ruby-mode-tests.el
Fix quote escaping in ruby-toggle-string-quotes
[gnu-emacs] / test / lisp / progmodes / ruby-mode-tests.el
index da8d77c5157beb1cd28aac45a81ee809c4a45a05..5dd34f8ee415374d12b37e4c28bf1e6d9c9adf82 100644 (file)
@@ -91,6 +91,15 @@ VALUES-PLIST is a list with alternating index and value elements."
 (ert-deftest ruby-no-heredoc-inside-quotes ()
   (ruby-assert-state "\"<<\", \"\",\nfoo" 3 nil))
 
+(ert-deftest ruby-no-heredoc-left-shift ()
+  ;; We can't really detect the left shift operator (like in similar
+  ;; cases, it depends on the type of foo), so we just require for <<
+  ;; to be preceded by a character from a known set.
+  (ruby-assert-state "foo(a<<b)" 3 nil))
+
+(ert-deftest ruby-no-heredoc-class-self ()
+  (ruby-assert-state "class <<self\nend" 3 nil))
+
 (ert-deftest ruby-exit!-font-lock ()
   (ruby-assert-face "exit!" 5 font-lock-builtin-face))
 
@@ -137,6 +146,9 @@ VALUES-PLIST is a list with alternating index and value elements."
 (ert-deftest ruby-slash-char-literal-is-not-mistaken-for-regexp ()
   (ruby-assert-state "?/" 3 nil))
 
+(ert-deftest ruby-regexp-is-not-mistaken-for-slash-symbol ()
+  (ruby-assert-state "x = /foo:/" 3 nil))
+
 (ert-deftest ruby-indent-simple ()
   (ruby-should-indent-buffer
    "if foo
@@ -440,6 +452,14 @@ VALUES-PLIST is a list with alternating index and value elements."
     ;; It's confused by the closing paren in the middle.
     (ruby-assert-state s 8 nil)))
 
+(ert-deftest ruby-interpolation-inside-another-interpolation ()
+  :expected-result :failed
+  (let ((s "\"#{[a, b, c].map { |v| \"#{v}\" }.join}\""))
+    (ruby-assert-face s 1 font-lock-string-face)
+    (ruby-assert-face s 2 font-lock-variable-name-face)
+    (ruby-assert-face s 38 font-lock-string-face)
+    (ruby-assert-state s 8 nil)))
+
 (ert-deftest ruby-interpolation-inside-double-quoted-percent-literals ()
   (ruby-assert-face "%Q{foo #@bar}" 8 font-lock-variable-name-face)
   (ruby-assert-face "%W{foo #@bar}" 8 font-lock-variable-name-face)
@@ -461,6 +481,14 @@ VALUES-PLIST is a list with alternating index and value elements."
   (ruby-assert-face "%S{foo}" 4 nil)
   (ruby-assert-face "%R{foo}" 4 nil))
 
+(ert-deftest ruby-no-nested-percent-literals ()
+  (ruby-with-temp-buffer "a = %w[b %()]"
+    (syntax-propertize (point))
+    (should (null (nth 8 (syntax-ppss))))
+    (should (eq t (nth 3 (syntax-ppss (1- (point-max))))))
+    (search-backward "[")
+    (should (eq t (nth 3 (syntax-ppss))))))
+
 (ert-deftest ruby-add-log-current-method-examples ()
   (let ((pairs '(("foo" . "#foo")
                  ("C.foo" . ".foo")
@@ -688,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))