Commit 3729a3f8 authored by Nobuyoshi Nakada's avatar Nobuyoshi Nakada Committed by Dmitry Gutov
Browse files

Support Ruby block arguments ending with , or *

* lisp/progmodes/ruby-mode.el (ruby-smie--forward-token):
Recognize punctuation before "closing-|" as a separate token.
(ruby-smie--backward-token): Same (bug#33487).

* test/lisp/progmodes/ruby-mode-tests.el
(ruby-forward-sexp-jumps-do-end-block-with-no-args)
(ruby-backward-sexp-jumps-do-end-block-with-no-args)
(ruby-forward-sexp-jumps-do-end-block-with-empty-args)
(ruby-backward-sexp-jumps-do-end-block-with-empty-args)
(ruby-forward-sexp-jumps-do-end-block-with-args)
(ruby-backward-sexp-jumps-do-end-block-with-args)
(ruby-forward-sexp-jumps-do-end-block-with-any-args)
(ruby-forward-sexp-jumps-do-end-block-with-expanded-one-arg)
(ruby-forward-sexp-jumps-do-end-block-with-one-and-any-args)
(ruby-backward-sexp-jumps-do-end-block-with-one-and-any-args):
New tests.
parent 0054961a
Pipeline #257 failed with stage
in 4 minutes and 50 seconds
......@@ -517,6 +517,9 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
((ruby-smie--opening-pipe-p) "opening-|")
((ruby-smie--closing-pipe-p) "closing-|")
(t tok)))
((string-match "\\`[^|]+|\\'" tok)
(forward-char -1)
(substring tok 0 -1))
((and (equal tok "") (looking-at "\\\\\n"))
(goto-char (match-end 0)) (ruby-smie--forward-token))
((equal tok "do")
......@@ -559,6 +562,7 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
((ruby-smie--opening-pipe-p) "opening-|")
((ruby-smie--closing-pipe-p) "closing-|")
(t tok)))
((string-match-p "\\`[^|]+|\\'" tok) "closing-|")
((string-match-p "\\`|[*&]\\'" tok)
(forward-char 1)
(substring tok 1))
......
......@@ -718,6 +718,96 @@ VALUES-PLIST is a list with alternating index and value elements."
(ruby-backward-sexp)
(should (= 2 (line-number-at-pos)))))
(ert-deftest ruby-forward-sexp-jumps-do-end-block-with-no-args ()
(ruby-with-temp-buffer
(ruby-test-string
"proc do
|end")
(search-backward "do\n")
(ruby-forward-sexp)
(should (eobp))))
(ert-deftest ruby-backward-sexp-jumps-do-end-block-with-no-args ()
(ruby-with-temp-buffer
(ruby-test-string
"proc do
|end")
(goto-char (point-max))
(ruby-backward-sexp)
(should (looking-at "do$"))))
(ert-deftest ruby-forward-sexp-jumps-do-end-block-with-empty-args ()
(ruby-with-temp-buffer
(ruby-test-string
"proc do ||
|end")
(search-backward "do ")
(ruby-forward-sexp)
(should (eobp))))
(ert-deftest ruby-backward-sexp-jumps-do-end-block-with-empty-args ()
(ruby-with-temp-buffer
(ruby-test-string
"proc do ||
|end")
(goto-char (point-max))
(ruby-backward-sexp)
(should (looking-at "do "))))
(ert-deftest ruby-forward-sexp-jumps-do-end-block-with-args ()
(ruby-with-temp-buffer
(ruby-test-string
"proc do |a,b|
|end")
(search-backward "do ")
(ruby-forward-sexp)
(should (eobp))))
(ert-deftest ruby-backward-sexp-jumps-do-end-block-with-args ()
(ruby-with-temp-buffer
(ruby-test-string
"proc do |a,b|
|end")
(goto-char (point-max))
(ruby-backward-sexp)
(should (looking-at "do "))))
(ert-deftest ruby-forward-sexp-jumps-do-end-block-with-any-args ()
(ruby-with-temp-buffer
(ruby-test-string
"proc do |*|
|end")
(search-backward "do ")
(ruby-forward-sexp)
(should (eobp))))
(ert-deftest ruby-forward-sexp-jumps-do-end-block-with-expanded-one-arg ()
(ruby-with-temp-buffer
(ruby-test-string
"proc do |a,|
|end")
(search-backward "do ")
(ruby-forward-sexp)
(should (eobp))))
(ert-deftest ruby-forward-sexp-jumps-do-end-block-with-one-and-any-args ()
(ruby-with-temp-buffer
(ruby-test-string
"proc do |a,*|
|end")
(search-backward "do ")
(ruby-forward-sexp)
(should (eobp))))
(ert-deftest ruby-backward-sexp-jumps-do-end-block-with-one-and-any-args ()
(ruby-with-temp-buffer
(ruby-test-string
"proc do |a,*|
|end")
(goto-char (point-max))
(ruby-backward-sexp)
(should (looking-at "do "))))
(ert-deftest ruby-toggle-string-quotes-quotes-correctly ()
(let ((pairs
'(("puts '\"foo\"\\''" . "puts \"\\\"foo\\\"'\"")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment