aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Gutov2012-08-10 16:25:43 -0400
committerStefan Monnier2012-08-10 16:25:43 -0400
commit9d2ed8a27e459dd09cf3f770bae5127f21debc34 (patch)
tree08dac730e918cd067274e2a485904b0340f847c0
parent9cd80478d6b6e8fd0eaac516e2f7bb6a5e0041bf (diff)
downloademacs-9d2ed8a27e459dd09cf3f770bae5127f21debc34.tar.gz
emacs-9d2ed8a27e459dd09cf3f770bae5127f21debc34.zip
* 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
-rw-r--r--test/ChangeLog12
-rw-r--r--test/automated/ruby-mode-tests.el136
2 files changed, 145 insertions, 3 deletions
diff --git a/test/ChangeLog b/test/ChangeLog
index 86f3019cb08..d5bed2c8dfc 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,11 @@
12012-08-10 Dmitry Gutov <dgutov@yandex.ru>
2
3 * automated/ruby-mode-tests.el (ruby-should-indent):
4 Add docstring, check (current-indentation) instead of (current-column).
5 (ruby-should-indent-buffer): New function.
6 Add tests for `ruby-deep-indent-paren' behavior.
7 Port all tests from test/misc/test_ruby_mode.rb in Ruby repo.
8
12012-08-09 Dmitry Gutov <dgutov@yandex.ru> 92012-08-09 Dmitry Gutov <dgutov@yandex.ru>
2 10
3 * automated/ruby-mode-tests.el (ruby-should-indent) 11 * automated/ruby-mode-tests.el (ruby-should-indent)
@@ -6,8 +14,8 @@
6 14
72012-07-29 David Engster <deng@randomsample.de> 152012-07-29 David Engster <deng@randomsample.de>
8 16
9 * automated/xml-parse-tests.el (xml-parse-tests--qnames): New 17 * automated/xml-parse-tests.el (xml-parse-tests--qnames):
10 variable to hold test data for name expansion. 18 New variable to hold test data for name expansion.
11 (xml-parse-tests): Test the two different types of name expansion. 19 (xml-parse-tests): Test the two different types of name expansion.
12 20
132012-07-29 Juri Linkov <juri@jurta.org> 212012-07-29 Juri Linkov <juri@jurta.org>
diff --git a/test/automated/ruby-mode-tests.el b/test/automated/ruby-mode-tests.el
index fbe1b8de9ae..f91b6e44b22 100644
--- a/test/automated/ruby-mode-tests.el
+++ b/test/automated/ruby-mode-tests.el
@@ -24,11 +24,24 @@
24(require 'ruby-mode) 24(require 'ruby-mode)
25 25
26(defun ruby-should-indent (content column) 26(defun ruby-should-indent (content column)
27 "Assert indentation COLUMN on the last line of CONTENT."
27 (with-temp-buffer 28 (with-temp-buffer
28 (insert content) 29 (insert content)
29 (ruby-mode) 30 (ruby-mode)
30 (ruby-indent-line) 31 (ruby-indent-line)
31 (should (= (current-column) column)))) 32 (should (= (current-indentation) column))))
33
34(defun ruby-should-indent-buffer (expected content)
35 "Assert that CONTENT turns into EXPECTED after the buffer is re-indented.
36
37The whitespace before and including \"|\" on each line is removed."
38 (with-temp-buffer
39 (cl-flet ((fix-indent (s) (replace-regexp-in-string "^[ \t]*|" "" s)))
40 (insert (fix-indent content))
41 (ruby-mode)
42 (indent-region (point-min) (point-max))
43 (should (string= (fix-indent expected) (buffer-substring-no-properties
44 (point-min) (point-max)))))))
32 45
33(defun ruby-assert-state (content &rest values-plist) 46(defun ruby-assert-state (content &rest values-plist)
34 "Assert syntax state values at the end of CONTENT. 47 "Assert syntax state values at the end of CONTENT.
@@ -57,6 +70,127 @@ VALUES-PLIST is a list with alternating index and value elements."
57 (ruby-assert-state "foo <<asd\n" 3 ?\n) 70 (ruby-assert-state "foo <<asd\n" 3 ?\n)
58 (ruby-assert-state "class <<asd\n" 3 nil)) 71 (ruby-assert-state "class <<asd\n" 3 nil))
59 72
73(ert-deftest ruby-deep-indent ()
74 (let ((ruby-deep-arglist nil)
75 (ruby-deep-indent-paren '(?\( ?\{ ?\[ ?\] t)))
76 (ruby-should-indent "foo = [1,\n2" 7)
77 (ruby-should-indent "foo = {a: b,\nc: d" 7)
78 (ruby-should-indent "foo(a,\nb" 4)))
79
80(ert-deftest ruby-deep-indent-disabled ()
81 (let ((ruby-deep-arglist nil)
82 (ruby-deep-indent-paren nil))
83 (ruby-should-indent "foo = [\n1" ruby-indent-level)
84 (ruby-should-indent "foo = {\na: b" ruby-indent-level)
85 (ruby-should-indent "foo(\na" ruby-indent-level)))
86
87(ert-deftest ruby-indent-simple ()
88 (ruby-should-indent-buffer
89 "if foo
90 | bar
91 |end
92 |zot
93 |"
94 "if foo
95 |bar
96 | end
97 | zot
98 |"))
99
100(ert-deftest ruby-indent-keyword-label ()
101 (ruby-should-indent-buffer
102 "bar(class: XXX) do
103 | foo
104 |end
105 |bar
106 |"
107 "bar(class: XXX) do
108 | foo
109 | end
110 | bar
111 |"))
112
113(ert-deftest ruby-indent-method-with-question-mark ()
114 (ruby-should-indent-buffer
115 "if x.is_a?(XXX)
116 | foo
117 |end
118 |"
119 "if x.is_a?(XXX)
120 | foo
121 | end
122 |"))
123
124(ert-deftest ruby-indent-expr-in-regexp ()
125 (ruby-should-indent-buffer
126 "if /#{foo}/ =~ s
127 | x = 1
128 |end
129 |"
130 "if /#{foo}/ =~ s
131 | x = 1
132 | end
133 |"))
134
135(ert-deftest ruby-indent-singleton-class ()
136 :expected-result :failed ; Doesn't work yet, when no space before "<<".
137 (ruby-should-indent-buffer
138 "class<<bar
139 | foo
140 |end
141 |"
142 "class<<bar
143 |foo
144 | end
145 |"))
146
147(ert-deftest ruby-indent-array-literal ()
148 (let ((ruby-deep-indent-paren nil))
149 (ruby-should-indent-buffer
150 "foo = [
151 | bar
152 |]
153 |"
154 "foo = [
155 | bar
156 | ]
157 |"))
158 (ruby-should-indent-buffer
159 "foo do
160 | [bar]
161 |end
162 |"
163 "foo do
164 |[bar]
165 | end
166 |"))
167
168(ert-deftest ruby-indent-begin-end ()
169 (ruby-should-indent-buffer
170 "begin
171 | a[b]
172 |end
173 |"
174 "begin
175 | a[b]
176 | end
177 |"))
178
179(ert-deftest ruby-indent-array-after-paren-and-space ()
180 (ruby-should-indent-buffer
181 "class A
182 | def foo
183 | foo( [])
184 | end
185 |end
186 |"
187 "class A
188 | def foo
189 |foo( [])
190 |end
191 | end
192 |"))
193
60(provide 'ruby-mode-tests) 194(provide 'ruby-mode-tests)
61 195
62;;; ruby-mode-tests.el ends here 196;;; ruby-mode-tests.el ends here