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.
This commit is contained in:
Nobuyoshi Nakada 2018-12-11 03:12:46 +02:00 committed by Dmitry Gutov
parent 0054961acf
commit 3729a3f88f
2 changed files with 94 additions and 0 deletions

View file

@ -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))

View file

@ -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\\\"'\"")