aboutsummaryrefslogtreecommitdiffstats
path: root/test/automated/ruby-mode-tests.el
diff options
context:
space:
mode:
Diffstat (limited to 'test/automated/ruby-mode-tests.el')
-rw-r--r--test/automated/ruby-mode-tests.el93
1 files changed, 85 insertions, 8 deletions
diff --git a/test/automated/ruby-mode-tests.el b/test/automated/ruby-mode-tests.el
index 0e41b2ba1e2..ad48413b030 100644
--- a/test/automated/ruby-mode-tests.el
+++ b/test/automated/ruby-mode-tests.el
@@ -80,7 +80,7 @@ VALUES-PLIST is a list with alternating index and value elements."
80 80
81(ert-deftest ruby-heredoc-font-lock () 81(ert-deftest ruby-heredoc-font-lock ()
82 (let ((s "foo <<eos.gsub('^ *', '')")) 82 (let ((s "foo <<eos.gsub('^ *', '')"))
83 (ruby-assert-face s 9 'font-lock-string-face) 83 (ruby-assert-face s 9 font-lock-string-face)
84 (ruby-assert-face s 10 nil))) 84 (ruby-assert-face s 10 nil)))
85 85
86(ert-deftest ruby-singleton-class-no-heredoc-font-lock () 86(ert-deftest ruby-singleton-class-no-heredoc-font-lock ()
@@ -154,7 +154,6 @@ VALUES-PLIST is a list with alternating index and value elements."
154 |")) 154 |"))
155 155
156(ert-deftest ruby-indent-singleton-class () 156(ert-deftest ruby-indent-singleton-class ()
157 :expected-result :failed ; Doesn't work yet, when no space before "<<".
158 (ruby-should-indent-buffer 157 (ruby-should-indent-buffer
159 "class<<bar 158 "class<<bar
160 | foo 159 | foo
@@ -165,6 +164,20 @@ VALUES-PLIST is a list with alternating index and value elements."
165 | end 164 | end
166 |")) 165 |"))
167 166
167(ert-deftest ruby-indent-inside-heredoc-after-operator ()
168 (ruby-should-indent-buffer
169 "b=<<eos
170 | 42"
171 "b=<<eos
172 | 42"))
173
174(ert-deftest ruby-indent-inside-heredoc-after-space ()
175 (ruby-should-indent-buffer
176 "foo <<eos.gsub(' ', '*')
177 | 42"
178 "foo <<eos.gsub(' ', '*')
179 | 42"))
180
168(ert-deftest ruby-indent-array-literal () 181(ert-deftest ruby-indent-array-literal ()
169 (let ((ruby-deep-indent-paren nil)) 182 (let ((ruby-deep-indent-paren nil))
170 (ruby-should-indent-buffer 183 (ruby-should-indent-buffer
@@ -249,19 +262,35 @@ VALUES-PLIST is a list with alternating index and value elements."
249 (should (string= "foo do |b|\n b + 1\nend" (buffer-string))))) 262 (should (string= "foo do |b|\n b + 1\nend" (buffer-string)))))
250 263
251(ert-deftest ruby-recognize-symbols-starting-with-at-character () 264(ert-deftest ruby-recognize-symbols-starting-with-at-character ()
252 (ruby-assert-face ":@abc" 3 'font-lock-constant-face)) 265 (ruby-assert-face ":@abc" 3 font-lock-constant-face))
253 266
254(ert-deftest ruby-hash-character-not-interpolation () 267(ert-deftest ruby-hash-character-not-interpolation ()
255 (ruby-assert-face "\"This is #{interpolation}\"" 15 268 (ruby-assert-face "\"This is #{interpolation}\"" 15
256 'font-lock-variable-name-face) 269 font-lock-variable-name-face)
257 (ruby-assert-face "\"This is \\#{no interpolation} despite the #\"" 270 (ruby-assert-face "\"This is \\#{no interpolation} despite the #\""
258 15 'font-lock-string-face) 271 15 font-lock-string-face)
259 (ruby-assert-face "\n#@comment, not ruby code" 5 'font-lock-comment-face) 272 (ruby-assert-face "\n#@comment, not ruby code" 5 font-lock-comment-face)
260 (ruby-assert-state "\n#@comment, not ruby code" 4 t) 273 (ruby-assert-state "\n#@comment, not ruby code" 4 t)
261 (ruby-assert-face "# A comment cannot have #{an interpolation} in it" 274 (ruby-assert-face "# A comment cannot have #{an interpolation} in it"
262 30 'font-lock-comment-face) 275 30 font-lock-comment-face)
263 (ruby-assert-face "# #{comment}\n \"#{interpolation}\"" 16 276 (ruby-assert-face "# #{comment}\n \"#{interpolation}\"" 16
264 'font-lock-variable-name-face)) 277 font-lock-variable-name-face))
278
279(ert-deftest ruby-interpolation-suppresses-syntax-inside ()
280 (let ((s "\"<ul><li>#{@files.join(\"</li><li>\")}</li></ul>\""))
281 (ruby-assert-state s 8 nil)
282 (ruby-assert-face s 9 font-lock-string-face)
283 (ruby-assert-face s 10 font-lock-variable-name-face)
284 (ruby-assert-face s 41 font-lock-string-face)))
285
286(ert-deftest ruby-interpolation-inside-percent-literal-with-paren ()
287 :expected-result :failed
288 (let ((s "%(^#{\")\"}^)"))
289 (ruby-assert-face s 3 font-lock-string-face)
290 (ruby-assert-face s 4 font-lock-variable-name-face)
291 (ruby-assert-face s 10 font-lock-string-face)
292 ;; It's confused by the closing paren in the middle.
293 (ruby-assert-state s 8 nil)))
265 294
266(ert-deftest ruby-add-log-current-method-examples () 295(ert-deftest ruby-add-log-current-method-examples ()
267 (let ((pairs '(("foo" . "#foo") 296 (let ((pairs '(("foo" . "#foo")
@@ -283,6 +312,54 @@ VALUES-PLIST is a list with alternating index and value elements."
283 (should (string= (ruby-add-log-current-method) 312 (should (string= (ruby-add-log-current-method)
284 (format "M::C%s" value))))))) 313 (format "M::C%s" value)))))))
285 314
315(defvar ruby-block-test-example
316 (ruby-test-string
317 "class C
318 | def foo
319 | 1
320 | end
321 |
322 | def bar
323 | 2
324 | end
325 |
326 | def baz
327 | some do
328 | end
329 | end
330 |end"))
331
332(defmacro ruby-deftest-move-to-block (name &rest body)
333 `(ert-deftest ,(intern (format "ruby-move-to-block-%s" name)) ()
334 (with-temp-buffer
335 (insert ruby-block-test-example)
336 (ruby-mode)
337 ,@body)))
338
339(put 'ruby-deftest-move-to-block 'lisp-indent-function 'defun)
340
341(ruby-deftest-move-to-block works-on-do
342 (goto-line 11)
343 (ruby-end-of-block)
344 (should (= 12 (line-number-at-pos)))
345 (ruby-beginning-of-block)
346 (should (= 11 (line-number-at-pos))))
347
348(ruby-deftest-move-to-block zero-is-noop
349 (goto-line 5)
350 (ruby-move-to-block 0)
351 (should (= 5 (line-number-at-pos))))
352
353(ruby-deftest-move-to-block ok-with-three
354 (goto-line 2)
355 (ruby-move-to-block 3)
356 (should (= 13 (line-number-at-pos))))
357
358(ruby-deftest-move-to-block ok-with-minus-two
359 (goto-line 10)
360 (ruby-move-to-block -2)
361 (should (= 2 (line-number-at-pos))))
362
286(provide 'ruby-mode-tests) 363(provide 'ruby-mode-tests)
287 364
288;;; ruby-mode-tests.el ends here 365;;; ruby-mode-tests.el ends here