]> code.delx.au - gnu-emacs/blob - test/automated/ruby-mode-tests.el
; Auto-commit of loaddefs files.
[gnu-emacs] / test / automated / ruby-mode-tests.el
1 ;;; ruby-mode-tests.el --- Test suite for ruby-mode
2
3 ;; Copyright (C) 2012-2016 Free Software Foundation, Inc.
4
5 ;; This file is part of GNU Emacs.
6
7 ;; GNU Emacs is free software: you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
11
12 ;; GNU Emacs is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
16
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
19
20 ;;; Commentary:
21
22 ;;; Code:
23
24 (require 'ert)
25 (require 'ruby-mode)
26
27 (defmacro ruby-with-temp-buffer (contents &rest body)
28 (declare (indent 1) (debug t))
29 `(with-temp-buffer
30 (insert ,contents)
31 (ruby-mode)
32 ,@body))
33
34 (defun ruby-should-indent (content column)
35 "Assert indentation COLUMN on the last line of CONTENT."
36 (ruby-with-temp-buffer content
37 (indent-according-to-mode)
38 (should (= (current-indentation) column))))
39
40 (defun ruby-should-indent-buffer (expected content)
41 "Assert that CONTENT turns into EXPECTED after the buffer is re-indented.
42
43 The whitespace before and including \"|\" on each line is removed."
44 (ruby-with-temp-buffer (ruby-test-string content)
45 (indent-region (point-min) (point-max))
46 (should (string= (ruby-test-string expected) (buffer-string)))))
47
48 (defun ruby-test-string (s &rest args)
49 (apply 'format (replace-regexp-in-string "^[ \t]*|" "" s) args))
50
51 (defun ruby-assert-state (content index value &optional point)
52 "Assert syntax state values at the end of CONTENT.
53
54 VALUES-PLIST is a list with alternating index and value elements."
55 (ruby-with-temp-buffer content
56 (when point (goto-char point))
57 (syntax-propertize (point))
58 (should (eq (nth index
59 (parse-partial-sexp (point-min) (point)))
60 value))))
61
62 (defun ruby-assert-face (content pos face)
63 (ruby-with-temp-buffer content
64 (font-lock-ensure nil nil)
65 (should (eq face (get-text-property pos 'face)))))
66
67 (ert-deftest ruby-indent-after-symbol-made-from-string-interpolation ()
68 "It can indent the line after symbol made using string interpolation."
69 (ruby-should-indent "def foo(suffix)\n :\"bar#{suffix}\"\n"
70 ruby-indent-level))
71
72 (ert-deftest ruby-indent-after-js-style-symbol-with-block-beg-name ()
73 "JS-style hash symbol can have keyword name."
74 (ruby-should-indent "link_to \"home\", home_path, class: \"foo\"\n" 0))
75
76 (ert-deftest ruby-discern-singleton-class-from-heredoc ()
77 (ruby-assert-state "foo <<asd\n" 3 ?\n)
78 (ruby-assert-state "class <<asd\n" 3 nil))
79
80 (ert-deftest ruby-heredoc-font-lock ()
81 (let ((s "foo <<eos.gsub('^ *', '')"))
82 (ruby-assert-face s 9 font-lock-string-face)
83 (ruby-assert-face s 10 nil)))
84
85 (ert-deftest ruby-singleton-class-no-heredoc-font-lock ()
86 (ruby-assert-face "class<<a" 8 nil))
87
88 (ert-deftest ruby-heredoc-highlights-interpolations ()
89 (ruby-assert-face "s = <<EOS\n #{foo}\nEOS" 15 font-lock-variable-name-face))
90
91 (ert-deftest ruby-no-heredoc-inside-quotes ()
92 (ruby-assert-state "\"<<\", \"\",\nfoo" 3 nil))
93
94 (ert-deftest ruby-no-heredoc-left-shift ()
95 ;; We can't really detect the left shift operator (like in similar
96 ;; cases, it depends on the type of foo), so we just require for <<
97 ;; to be preceded by a character from a known set.
98 (ruby-assert-state "foo(a<<b)" 3 nil))
99
100 (ert-deftest ruby-no-heredoc-class-self ()
101 (ruby-assert-state "class <<self\nend" 3 nil))
102
103 (ert-deftest ruby-exit!-font-lock ()
104 (ruby-assert-face "exit!" 5 font-lock-builtin-face))
105
106 (ert-deftest ruby-deep-indent ()
107 (let ((ruby-deep-arglist nil)
108 (ruby-deep-indent-paren '(?\( ?\{ ?\[ ?\] t)))
109 (ruby-should-indent "foo = [1,\n2" 7)
110 (ruby-should-indent "foo = {a: b,\nc: d" 7)
111 (ruby-should-indent "foo(a,\nb" 4)))
112
113 (ert-deftest ruby-deep-indent-disabled ()
114 (let ((ruby-deep-arglist nil)
115 (ruby-deep-indent-paren nil))
116 (ruby-should-indent "foo = [\n1" ruby-indent-level)
117 (ruby-should-indent "foo = {\na: b" ruby-indent-level)
118 (ruby-should-indent "foo(\na" ruby-indent-level)))
119
120 (ert-deftest ruby-indent-after-keyword-in-a-string ()
121 (ruby-should-indent "a = \"abc\nif\"\n " 0)
122 (ruby-should-indent "a = %w[abc\n def]\n " 0)
123 (ruby-should-indent "a = \"abc\n def\"\n " 0))
124
125 (ert-deftest ruby-regexp-doesnt-start-in-string ()
126 (ruby-assert-state "'(/', /\d+/" 3 nil))
127
128 (ert-deftest ruby-regexp-starts-after-string ()
129 (ruby-assert-state "'(/', /\d+/" 3 ?/ 8))
130
131 (ert-deftest ruby-regexp-interpolation-is-highlighted ()
132 (ruby-assert-face "/#{foobs}/" 4 font-lock-variable-name-face))
133
134 (ert-deftest ruby-regexp-skips-over-interpolation ()
135 (ruby-assert-state "/#{foobs.join('/')}/" 3 nil))
136
137 (ert-deftest ruby-regexp-continues-till-end-when-unclosed ()
138 (ruby-assert-state "/bars" 3 ?/))
139
140 (ert-deftest ruby-regexp-can-be-multiline ()
141 (ruby-assert-state "/bars\ntees # toots \nfoos/" 3 nil))
142
143 (ert-deftest ruby-slash-symbol-is-not-mistaken-for-regexp ()
144 (ruby-assert-state ":/" 3 nil))
145
146 (ert-deftest ruby-slash-char-literal-is-not-mistaken-for-regexp ()
147 (ruby-assert-state "?/" 3 nil))
148
149 (ert-deftest ruby-indent-simple ()
150 (ruby-should-indent-buffer
151 "if foo
152 | bar
153 |end
154 |zot
155 |"
156 "if foo
157 |bar
158 | end
159 | zot
160 |"))
161
162 (ert-deftest ruby-indent-keyword-label ()
163 (ruby-should-indent-buffer
164 "bar(class: XXX) do
165 | foo
166 |end
167 |bar
168 |"
169 "bar(class: XXX) do
170 | foo
171 | end
172 | bar
173 |"))
174
175 (ert-deftest ruby-indent-method-with-question-mark ()
176 (ruby-should-indent-buffer
177 "if x.is_a?(XXX)
178 | foo
179 |end
180 |"
181 "if x.is_a?(XXX)
182 | foo
183 | end
184 |"))
185
186 (ert-deftest ruby-indent-expr-in-regexp ()
187 (ruby-should-indent-buffer
188 "if /#{foo}/ =~ s
189 | x = 1
190 |end
191 |"
192 "if /#{foo}/ =~ s
193 | x = 1
194 | end
195 |"))
196
197 (ert-deftest ruby-indent-singleton-class ()
198 (ruby-should-indent-buffer
199 "class<<bar
200 | foo
201 |end
202 |"
203 "class<<bar
204 |foo
205 | end
206 |"))
207
208 (ert-deftest ruby-indent-inside-heredoc-after-operator ()
209 (ruby-should-indent-buffer
210 "b=<<eos
211 | 42"
212 "b=<<eos
213 | 42"))
214
215 (ert-deftest ruby-indent-inside-heredoc-after-space ()
216 (ruby-should-indent-buffer
217 "foo <<eos.gsub(' ', '*')
218 | 42"
219 "foo <<eos.gsub(' ', '*')
220 | 42"))
221
222 (ert-deftest ruby-indent-array-literal ()
223 (let ((ruby-deep-indent-paren nil))
224 (ruby-should-indent-buffer
225 "foo = [
226 | bar
227 |]
228 |"
229 "foo = [
230 | bar
231 | ]
232 |"))
233 (ruby-should-indent-buffer
234 "foo do
235 | [bar]
236 |end
237 |"
238 "foo do
239 |[bar]
240 | end
241 |"))
242
243 (ert-deftest ruby-indent-begin-end ()
244 (ruby-should-indent-buffer
245 "begin
246 | a[b]
247 |end
248 |"
249 "begin
250 | a[b]
251 | end
252 |"))
253
254 (ert-deftest ruby-indent-array-after-paren-and-space ()
255 (ruby-should-indent-buffer
256 "class A
257 | def foo
258 | foo( [])
259 | end
260 |end
261 |"
262 "class A
263 | def foo
264 |foo( [])
265 |end
266 | end
267 |"))
268
269 (ert-deftest ruby-indent-after-block-in-continued-expression ()
270 (ruby-should-indent-buffer
271 "var =
272 | begin
273 | val
274 | end
275 |statement"
276 "var =
277 |begin
278 |val
279 |end
280 |statement"))
281
282 (ert-deftest ruby-indent-spread-args-in-parens ()
283 (let ((ruby-deep-indent-paren '(?\()))
284 (ruby-should-indent-buffer
285 "foo(1,
286 | 2,
287 | 3)
288 |"
289 "foo(1,
290 | 2,
291 | 3)
292 |")))
293
294 (ert-deftest ruby-align-to-stmt-keywords-t ()
295 (let ((ruby-align-to-stmt-keywords t))
296 (ruby-should-indent-buffer
297 "foo = if bar?
298 | 1
299 |else
300 | 2
301 |end
302 |
303 |foo || begin
304 | bar
305 |end
306 |
307 |foo ||
308 | begin
309 | bar
310 | end
311 |"
312 "foo = if bar?
313 | 1
314 |else
315 | 2
316 | end
317 |
318 | foo || begin
319 | bar
320 |end
321 |
322 | foo ||
323 | begin
324 |bar
325 | end
326 |")
327 ))
328
329 (ert-deftest ruby-align-to-stmt-keywords-case ()
330 (let ((ruby-align-to-stmt-keywords '(case)))
331 (ruby-should-indent-buffer
332 "b = case a
333 |when 13
334 | 6
335 |else
336 | 42
337 |end"
338 "b = case a
339 | when 13
340 | 6
341 | else
342 | 42
343 | end")))
344
345 (ert-deftest ruby-align-chained-calls ()
346 (let ((ruby-align-chained-calls t))
347 (ruby-should-indent-buffer
348 "one.two.three
349 | .four
350 |
351 |my_array.select { |str| str.size > 5 }
352 | .map { |str| str.downcase }"
353 "one.two.three
354 | .four
355 |
356 |my_array.select { |str| str.size > 5 }
357 | .map { |str| str.downcase }")))
358
359 (ert-deftest ruby-move-to-block-stops-at-indentation ()
360 (ruby-with-temp-buffer "def f\nend"
361 (beginning-of-line)
362 (ruby-move-to-block -1)
363 (should (looking-at "^def"))))
364
365 (ert-deftest ruby-toggle-block-to-do-end ()
366 (ruby-with-temp-buffer "foo {|b|\n}"
367 (beginning-of-line)
368 (ruby-toggle-block)
369 (should (string= "foo do |b|\nend" (buffer-string)))))
370
371 (ert-deftest ruby-toggle-block-to-brace ()
372 (let ((pairs '((17 . "foo { |b| b + 2 }")
373 (16 . "foo { |b|\n b + 2\n}"))))
374 (dolist (pair pairs)
375 (with-temp-buffer
376 (let ((fill-column (car pair)))
377 (insert "foo do |b|\n b + 2\nend")
378 (ruby-mode)
379 (beginning-of-line)
380 (ruby-toggle-block)
381 (should (string= (cdr pair) (buffer-string))))))))
382
383 (ert-deftest ruby-toggle-block-to-multiline ()
384 (ruby-with-temp-buffer "foo {|b| b + 1}"
385 (beginning-of-line)
386 (ruby-toggle-block)
387 (should (string= "foo do |b|\n b + 1\nend" (buffer-string)))))
388
389 (ert-deftest ruby-toggle-block-with-interpolation ()
390 (ruby-with-temp-buffer "foo do\n \"#{bar}\"\nend"
391 (beginning-of-line)
392 (ruby-toggle-block)
393 (should (string= "foo { \"#{bar}\" }" (buffer-string)))))
394
395 (ert-deftest ruby-recognize-symbols-starting-with-at-character ()
396 (ruby-assert-face ":@abc" 3 font-lock-constant-face))
397
398 (ert-deftest ruby-hash-character-not-interpolation ()
399 (ruby-assert-face "\"This is #{interpolation}\"" 15
400 font-lock-variable-name-face)
401 (ruby-assert-face "\"This is \\#{no interpolation} despite the #\""
402 15 font-lock-string-face)
403 (ruby-assert-face "\n#@comment, not ruby code" 5 font-lock-comment-face)
404 (ruby-assert-state "\n#@comment, not ruby code" 4 t)
405 (ruby-assert-face "# A comment cannot have #{an interpolation} in it"
406 30 font-lock-comment-face)
407 (ruby-assert-face "# #{comment}\n \"#{interpolation}\"" 16
408 font-lock-variable-name-face))
409
410 (ert-deftest ruby-interpolation-suppresses-quotes-inside ()
411 (let ((s "\"<ul><li>#{@files.join(\"</li><li>\")}</li></ul>\""))
412 (ruby-assert-state s 8 nil)
413 (ruby-assert-face s 9 font-lock-string-face)
414 (ruby-assert-face s 10 font-lock-variable-name-face)
415 (ruby-assert-face s 41 font-lock-string-face)))
416
417 (ert-deftest ruby-interpolation-suppresses-one-double-quote ()
418 (let ((s "\"foo#{'\"'}\""))
419 (ruby-assert-state s 8 nil)
420 (ruby-assert-face s 8 font-lock-variable-name-face)
421 (ruby-assert-face s 11 font-lock-string-face)))
422
423 (ert-deftest ruby-interpolation-suppresses-one-backtick ()
424 (let ((s "`as#{'`'}das`"))
425 (ruby-assert-state s 8 nil)))
426
427 (ert-deftest ruby-interpolation-keeps-non-quote-syntax ()
428 (let ((s "\"foo#{baz.tee}bar\""))
429 (ruby-with-temp-buffer s
430 (goto-char (point-min))
431 (ruby-mode)
432 (syntax-propertize (point-max))
433 (search-forward "tee")
434 (should (string= (thing-at-point 'symbol) "tee")))))
435
436 (ert-deftest ruby-interpolation-inside-percent-literal ()
437 (let ((s "%( #{boo} )"))
438 (ruby-assert-face s 1 font-lock-string-face)
439 (ruby-assert-face s 4 font-lock-variable-name-face)
440 (ruby-assert-face s 10 font-lock-string-face)
441 (ruby-assert-state s 8 nil)))
442
443 (ert-deftest ruby-interpolation-inside-percent-literal-with-paren ()
444 :expected-result :failed
445 (let ((s "%(^#{\")\"}^)"))
446 (ruby-assert-face s 3 font-lock-string-face)
447 (ruby-assert-face s 4 font-lock-variable-name-face)
448 (ruby-assert-face s 10 font-lock-string-face)
449 ;; It's confused by the closing paren in the middle.
450 (ruby-assert-state s 8 nil)))
451
452 (ert-deftest ruby-interpolation-inside-another-interpolation ()
453 :expected-result :failed
454 (let ((s "\"#{[a, b, c].map { |v| \"#{v}\" }.join}\""))
455 (ruby-assert-face s 1 font-lock-string-face)
456 (ruby-assert-face s 2 font-lock-variable-name-face)
457 (ruby-assert-face s 38 font-lock-string-face)
458 (ruby-assert-state s 8 nil)))
459
460 (ert-deftest ruby-interpolation-inside-double-quoted-percent-literals ()
461 (ruby-assert-face "%Q{foo #@bar}" 8 font-lock-variable-name-face)
462 (ruby-assert-face "%W{foo #@bar}" 8 font-lock-variable-name-face)
463 (ruby-assert-face "%r{foo #@bar}" 8 font-lock-variable-name-face)
464 (ruby-assert-face "%x{foo #@bar}" 8 font-lock-variable-name-face))
465
466 (ert-deftest ruby-no-interpolation-in-single-quoted-literals ()
467 (ruby-assert-face "'foo #@bar'" 7 font-lock-string-face)
468 (ruby-assert-face "%q{foo #@bar}" 8 font-lock-string-face)
469 (ruby-assert-face "%w{foo #@bar}" 8 font-lock-string-face)
470 (ruby-assert-face "%s{foo #@bar}" 8 font-lock-string-face))
471
472 (ert-deftest ruby-interpolation-after-dollar-sign ()
473 (ruby-assert-face "\"$#{balance}\"" 2 'font-lock-string-face)
474 (ruby-assert-face "\"$#{balance}\"" 3 'font-lock-variable-name-face))
475
476 (ert-deftest ruby-no-unknown-percent-literals ()
477 ;; No folding of case.
478 (ruby-assert-face "%S{foo}" 4 nil)
479 (ruby-assert-face "%R{foo}" 4 nil))
480
481 (ert-deftest ruby-no-nested-percent-literals ()
482 (ruby-with-temp-buffer "a = %w[b %()]"
483 (syntax-propertize (point))
484 (should (null (nth 8 (syntax-ppss))))
485 (should (eq t (nth 3 (syntax-ppss (1- (point-max))))))
486 (search-backward "[")
487 (should (eq t (nth 3 (syntax-ppss))))))
488
489 (ert-deftest ruby-add-log-current-method-examples ()
490 (let ((pairs '(("foo" . "#foo")
491 ("C.foo" . ".foo")
492 ("self.foo" . ".foo"))))
493 (dolist (pair pairs)
494 (let ((name (car pair))
495 (value (cdr pair)))
496 (ruby-with-temp-buffer (ruby-test-string
497 "module M
498 | class C
499 | def %s
500 | _
501 | end
502 | end
503 |end"
504 name)
505 (search-backward "_")
506 (forward-line)
507 (should (string= (ruby-add-log-current-method)
508 (format "M::C%s" value))))))))
509
510 (ert-deftest ruby-add-log-current-method-outside-of-method ()
511 (ruby-with-temp-buffer (ruby-test-string
512 "module M
513 | class C
514 | def foo
515 | end
516 | _
517 | end
518 |end")
519 (search-backward "_")
520 (should (string= (ruby-add-log-current-method)"M::C"))))
521
522 (ert-deftest ruby-add-log-current-method-in-singleton-class ()
523 (ruby-with-temp-buffer (ruby-test-string
524 "class C
525 | class << self
526 | def foo
527 | _
528 | end
529 | end
530 |end")
531 (search-backward "_")
532 (should (string= (ruby-add-log-current-method) "C.foo"))))
533
534 (ert-deftest ruby-add-log-current-method-namespace-shorthand ()
535 (ruby-with-temp-buffer (ruby-test-string
536 "class C::D
537 | def foo
538 | _
539 | end
540 |end")
541 (search-backward "_")
542 (should (string= (ruby-add-log-current-method) "C::D#foo"))))
543
544 (ert-deftest ruby-add-log-current-method-after-inner-class ()
545 (ruby-with-temp-buffer (ruby-test-string
546 "module M
547 | class C
548 | class D
549 | end
550 | def foo
551 | _
552 | end
553 | end
554 |end")
555 (search-backward "_")
556 (should (string= (ruby-add-log-current-method) "M::C#foo"))))
557
558 (defvar ruby-block-test-example
559 (ruby-test-string
560 "class C
561 | def foo
562 | 1
563 | end
564 |
565 | def bar
566 | 2
567 | end
568 |
569 | def baz
570 |some do
571 |3
572 | end
573 | end
574 |end"))
575
576 (defmacro ruby-deftest-move-to-block (name &rest body)
577 (declare (indent defun))
578 `(ert-deftest ,(intern (format "ruby-move-to-block-%s" name)) ()
579 (with-temp-buffer
580 (insert ruby-block-test-example)
581 (ruby-mode)
582 (goto-char (point-min))
583 ,@body)))
584
585 (ruby-deftest-move-to-block works-on-do
586 (forward-line 10)
587 (ruby-end-of-block)
588 (should (= 13 (line-number-at-pos)))
589 (ruby-beginning-of-block)
590 (should (= 11 (line-number-at-pos))))
591
592 (ruby-deftest-move-to-block zero-is-noop
593 (forward-line 4)
594 (ruby-move-to-block 0)
595 (should (= 5 (line-number-at-pos))))
596
597 (ruby-deftest-move-to-block ok-with-three
598 (forward-line 1)
599 (ruby-move-to-block 3)
600 (should (= 14 (line-number-at-pos))))
601
602 (ruby-deftest-move-to-block ok-with-minus-two
603 (forward-line 9)
604 (ruby-move-to-block -2)
605 (should (= 2 (line-number-at-pos))))
606
607 (ert-deftest ruby-move-to-block-skips-percent-literal ()
608 (dolist (s (list (ruby-test-string
609 "foo do
610 | a = %%w(
611 | def yaa
612 | )
613 |end")
614 (ruby-test-string
615 "foo do
616 | a = %%w|
617 | end
618 | |
619 |end")))
620 (ruby-with-temp-buffer s
621 (goto-char (point-min))
622 (ruby-end-of-block)
623 (should (= 5 (line-number-at-pos)))
624 (ruby-beginning-of-block)
625 (should (= 1 (line-number-at-pos))))))
626
627 (ert-deftest ruby-move-to-block-skips-heredoc ()
628 (ruby-with-temp-buffer
629 (ruby-test-string
630 "if something_wrong?
631 | ActiveSupport::Deprecation.warn(<<-eowarn)
632 | boo hoo
633 | end
634 | eowarn
635 |end")
636 (goto-char (point-min))
637 (ruby-end-of-block)
638 (should (= 6 (line-number-at-pos)))
639 (ruby-beginning-of-block)
640 (should (= 1 (line-number-at-pos)))))
641
642 (ert-deftest ruby-move-to-block-does-not-fold-case ()
643 (ruby-with-temp-buffer
644 (ruby-test-string
645 "foo do
646 | Module.to_s
647 |end")
648 (let ((case-fold-search t))
649 (ruby-beginning-of-block))
650 (should (= 1 (line-number-at-pos)))))
651
652 (ert-deftest ruby-move-to-block-moves-from-else-to-if ()
653 (ruby-with-temp-buffer (ruby-test-string
654 "if true
655 | nested_block do
656 | end
657 |else
658 |end")
659 (goto-char (point-min))
660 (forward-line 3)
661 (ruby-beginning-of-block)
662 (should (= 1 (line-number-at-pos)))))
663
664 (ert-deftest ruby-beginning-of-defun-does-not-fold-case ()
665 (ruby-with-temp-buffer
666 (ruby-test-string
667 "class C
668 | def bar
669 | Class.to_s
670 | end
671 |end")
672 (goto-char (point-min))
673 (forward-line 3)
674 (let ((case-fold-search t))
675 (beginning-of-defun))
676 (should (= 2 (line-number-at-pos)))))
677
678 (ert-deftest ruby-end-of-defun-skips-to-next-line-after-the-method ()
679 (ruby-with-temp-buffer
680 (ruby-test-string
681 "class D
682 | def tee
683 | 'ho hum'
684 | end
685 |end")
686 (goto-char (point-min))
687 (forward-line 1)
688 (end-of-defun)
689 (should (= 5 (line-number-at-pos)))))
690
691 (defvar ruby-sexp-test-example
692 (ruby-test-string
693 "class C
694 | def foo
695 | self.end
696 | D.new.class
697 | [1, 2, 3].map do |i|
698 | i + 1
699 | end.sum
700 | end
701 |end"))
702
703 (ert-deftest ruby-forward-sexp-skips-method-calls-with-keyword-names ()
704 (ruby-with-temp-buffer ruby-sexp-test-example
705 (goto-line 2)
706 (ruby-forward-sexp)
707 (should (= 8 (line-number-at-pos)))))
708
709 (ert-deftest ruby-backward-sexp-skips-method-calls-with-keyword-names ()
710 (ruby-with-temp-buffer ruby-sexp-test-example
711 (goto-line 8)
712 (end-of-line)
713 (ruby-backward-sexp)
714 (should (= 2 (line-number-at-pos)))))
715
716 (ert-deftest ruby--insert-coding-comment-ruby-style ()
717 (with-temp-buffer
718 (let ((ruby-encoding-magic-comment-style 'ruby))
719 (ruby--insert-coding-comment "utf-8")
720 (should (string= "# coding: utf-8\n" (buffer-string))))))
721
722 (ert-deftest ruby--insert-coding-comment-emacs-style ()
723 (with-temp-buffer
724 (let ((ruby-encoding-magic-comment-style 'emacs))
725 (ruby--insert-coding-comment "utf-8")
726 (should (string= "# -*- coding: utf-8 -*-\n" (buffer-string))))))
727
728 (ert-deftest ruby--insert-coding-comment-custom-style ()
729 (with-temp-buffer
730 (let ((ruby-encoding-magic-comment-style 'custom)
731 (ruby-custom-encoding-magic-comment-template "# encoding: %s\n"))
732 (ruby--insert-coding-comment "utf-8")
733 (should (string= "# encoding: utf-8\n\n" (buffer-string))))))
734
735
736 (provide 'ruby-mode-tests)
737
738 ;;; ruby-mode-tests.el ends here