From: Dmitry Gutov <dgutov@yandex.ru>
To: 12169@debbugs.gnu.org
Subject: bug#12169: Acknowledgement ([PATCH] Merge changes from upstream ruby-mode)
Date: Fri, 10 Aug 2012 18:52:30 +0400 [thread overview]
Message-ID: <5025202E.70507@yandex.ru> (raw)
In-Reply-To: <handler.12169.B.13445594689259.ack@debbugs.gnu.org>
[-- Attachment #1: Type: text/plain, Size: 693 bytes --]
Here's part 2, in which I'm skipping the next 3 commits:
https://github.com/ruby/ruby/commit/85df40e9ab4559cd4ddde3f106ab56c76a808cc8
https://github.com/ruby/ruby/commit/6b0dc7fd81b25bc66681548b8b82f38258f7e08c
https://github.com/ruby/ruby/commit/862048e28d26112af1e67205cfd1c16564590bce
Because as far as I can tell, they hijack the `ruby-deep-indent-paren'
behavior. IOW, with these applied, the indentation works as though the
above variable is always nil (with a small improvement in the nested
case, to be fair), so they don't make sense.
Instead, I added two tests, for `ruby-deep-indent-paren' enabled and
disabled, and also ported all examples from test/misc/test_ruby_mode.rb.
[-- Attachment #2: ruby-upstream-2.diff --]
[-- Type: text/plain, Size: 4249 bytes --]
diff --git a/test/ChangeLog b/test/ChangeLog
index 86f3019..c59c3cb 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,11 @@
+2012-08-10 Dmitry Gutov <dgutov@yandex.ru>
+
+ * automated/ruby-mode-tests.el (ruby-should-indent): Add
+ docstring, check (current-indentation) instead of (current-column).
+ (ruby-should-indent-buffer): New function.
+ Add tests for `ruby-deep-indent-paren' behavior.
+ Port all tests from test/misc/test_ruby_mode.rb in Ruby repo.
+
2012-08-09 Dmitry Gutov <dgutov@yandex.ru>
* automated/ruby-mode-tests.el (ruby-should-indent)
diff --git a/test/automated/ruby-mode-tests.el b/test/automated/ruby-mode-tests.el
index fbe1b8d..f91b6e4 100644
--- a/test/automated/ruby-mode-tests.el
+++ b/test/automated/ruby-mode-tests.el
@@ -24,11 +24,24 @@
(require 'ruby-mode)
(defun ruby-should-indent (content column)
+ "Assert indentation COLUMN on the last line of CONTENT."
(with-temp-buffer
(insert content)
(ruby-mode)
(ruby-indent-line)
- (should (= (current-column) column))))
+ (should (= (current-indentation) column))))
+
+(defun ruby-should-indent-buffer (expected content)
+ "Assert that CONTENT turns into EXPECTED after the buffer is re-indented.
+
+The whitespace before and including \"|\" on each line is removed."
+ (with-temp-buffer
+ (cl-flet ((fix-indent (s) (replace-regexp-in-string "^[ \t]*|" "" s)))
+ (insert (fix-indent content))
+ (ruby-mode)
+ (indent-region (point-min) (point-max))
+ (should (string= (fix-indent expected) (buffer-substring-no-properties
+ (point-min) (point-max)))))))
(defun ruby-assert-state (content &rest values-plist)
"Assert syntax state values at the end of CONTENT.
@@ -57,6 +70,127 @@ VALUES-PLIST is a list with alternating index and value elements."
(ruby-assert-state "foo <<asd\n" 3 ?\n)
(ruby-assert-state "class <<asd\n" 3 nil))
+(ert-deftest ruby-deep-indent ()
+ (let ((ruby-deep-arglist nil)
+ (ruby-deep-indent-paren '(?\( ?\{ ?\[ ?\] t)))
+ (ruby-should-indent "foo = [1,\n2" 7)
+ (ruby-should-indent "foo = {a: b,\nc: d" 7)
+ (ruby-should-indent "foo(a,\nb" 4)))
+
+(ert-deftest ruby-deep-indent-disabled ()
+ (let ((ruby-deep-arglist nil)
+ (ruby-deep-indent-paren nil))
+ (ruby-should-indent "foo = [\n1" ruby-indent-level)
+ (ruby-should-indent "foo = {\na: b" ruby-indent-level)
+ (ruby-should-indent "foo(\na" ruby-indent-level)))
+
+(ert-deftest ruby-indent-simple ()
+ (ruby-should-indent-buffer
+ "if foo
+ | bar
+ |end
+ |zot
+ |"
+ "if foo
+ |bar
+ | end
+ | zot
+ |"))
+
+(ert-deftest ruby-indent-keyword-label ()
+ (ruby-should-indent-buffer
+ "bar(class: XXX) do
+ | foo
+ |end
+ |bar
+ |"
+ "bar(class: XXX) do
+ | foo
+ | end
+ | bar
+ |"))
+
+(ert-deftest ruby-indent-method-with-question-mark ()
+ (ruby-should-indent-buffer
+ "if x.is_a?(XXX)
+ | foo
+ |end
+ |"
+ "if x.is_a?(XXX)
+ | foo
+ | end
+ |"))
+
+(ert-deftest ruby-indent-expr-in-regexp ()
+ (ruby-should-indent-buffer
+ "if /#{foo}/ =~ s
+ | x = 1
+ |end
+ |"
+ "if /#{foo}/ =~ s
+ | x = 1
+ | end
+ |"))
+
+(ert-deftest ruby-indent-singleton-class ()
+ :expected-result :failed ; Doesn't work yet, when no space before "<<".
+ (ruby-should-indent-buffer
+ "class<<bar
+ | foo
+ |end
+ |"
+ "class<<bar
+ |foo
+ | end
+ |"))
+
+(ert-deftest ruby-indent-array-literal ()
+ (let ((ruby-deep-indent-paren nil))
+ (ruby-should-indent-buffer
+ "foo = [
+ | bar
+ |]
+ |"
+ "foo = [
+ | bar
+ | ]
+ |"))
+ (ruby-should-indent-buffer
+ "foo do
+ | [bar]
+ |end
+ |"
+ "foo do
+ |[bar]
+ | end
+ |"))
+
+(ert-deftest ruby-indent-begin-end ()
+ (ruby-should-indent-buffer
+ "begin
+ | a[b]
+ |end
+ |"
+ "begin
+ | a[b]
+ | end
+ |"))
+
+(ert-deftest ruby-indent-array-after-paren-and-space ()
+ (ruby-should-indent-buffer
+ "class A
+ | def foo
+ | foo( [])
+ | end
+ |end
+ |"
+ "class A
+ | def foo
+ |foo( [])
+ |end
+ | end
+ |"))
+
(provide 'ruby-mode-tests)
;;; ruby-mode-tests.el ends here
next prev parent reply other threads:[~2012-08-10 14:52 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-10 0:36 bug#12169: [PATCH] Merge changes from upstream ruby-mode Dmitry Gutov
[not found] ` <handler.12169.B.13445594689259.ack@debbugs.gnu.org>
2012-08-10 14:52 ` Dmitry Gutov [this message]
2012-08-10 15:54 ` Glenn Morris
2012-08-10 20:28 ` Stefan Monnier
2012-08-10 22:15 ` Dmitry Gutov
2012-08-10 23:06 ` Dmitry Gutov
2012-08-12 22:09 ` Stefan Monnier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5025202E.70507@yandex.ru \
--to=dgutov@yandex.ru \
--cc=12169@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.