* test/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.

Fixes: debbugs:12169
This commit is contained in:
Dmitry Gutov 2012-08-10 16:25:43 -04:00 committed by Stefan Monnier
parent 9cd80478d6
commit 9d2ed8a27e
2 changed files with 145 additions and 3 deletions

View file

@ -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)
@ -6,8 +14,8 @@
2012-07-29 David Engster <deng@randomsample.de>
* automated/xml-parse-tests.el (xml-parse-tests--qnames): New
variable to hold test data for name expansion.
* automated/xml-parse-tests.el (xml-parse-tests--qnames):
New variable to hold test data for name expansion.
(xml-parse-tests): Test the two different types of name expansion.
2012-07-29 Juri Linkov <juri@jurta.org>

View file

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