emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r109559: * test/automated/ruby-mode-t


From: Stefan Monnier
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r109559: * test/automated/ruby-mode-tests.el (ruby-should-indent):
Date: Fri, 10 Aug 2012 16:25:43 -0400
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 109559
fixes bug: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=12169
author: Dmitry Gutov <address@hidden>
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Fri 2012-08-10 16:25:43 -0400
message:
  * 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.
modified:
  test/ChangeLog
  test/automated/ruby-mode-tests.el
=== modified file 'test/ChangeLog'
--- a/test/ChangeLog    2012-08-10 20:19:09 +0000
+++ b/test/ChangeLog    2012-08-10 20:25:43 +0000
@@ -1,3 +1,11 @@
+2012-08-10  Dmitry Gutov  <address@hidden>
+
+       * 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  <address@hidden>
 
        * automated/ruby-mode-tests.el (ruby-should-indent)
@@ -6,8 +14,8 @@
 
 2012-07-29  David Engster  <address@hidden>
 
-       * 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  <address@hidden>

=== modified file 'test/automated/ruby-mode-tests.el'
--- a/test/automated/ruby-mode-tests.el 2012-08-10 20:19:09 +0000
+++ b/test/automated/ruby-mode-tests.el 2012-08-10 20:25:43 +0000
@@ -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 @@
   (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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]