]> git.eshelyaron.com Git - emacs.git/commitdiff
* test/automated/ruby-mode-tests.el (ruby-should-indent):
authorDmitry Gutov <dgutov@yandex.ru>
Fri, 10 Aug 2012 20:25:43 +0000 (16:25 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Fri, 10 Aug 2012 20:25:43 +0000 (16:25 -0400)
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
test/ChangeLog
test/automated/ruby-mode-tests.el

index 86f3019cb0880f9c48ecd243f126edd02a07a96c..d5bed2c8dfc9302d37deaece45601804f10b11c8 100644 (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>
index fbe1b8de9aef88316b92fafd3fd2146cb898ed64..f91b6e44b221ab5e1631ba42ff829662bb099897 100644 (file)
 (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