Give '$' punctuation syntax in make-mode (Bug#24477)
[emacs.git] / test / lisp / progmodes / ruby-mode-tests.el
blob72d83affaef892e7a0f523b1134b2df0a7b599db
1 ;;; ruby-mode-tests.el --- Test suite for ruby-mode
3 ;; Copyright (C) 2012-2018 Free Software Foundation, Inc.
5 ;; This file is part of GNU Emacs.
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.
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.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
20 ;;; Commentary:
22 ;;; Code:
24 (require 'ert)
25 (require 'ruby-mode)
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))
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))))
40 (defun ruby-should-indent-buffer (expected content)
41 "Assert that CONTENT turns into EXPECTED after the buffer is re-indented.
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)))))
48 (defun ruby-test-string (s &rest args)
49 (apply 'format (replace-regexp-in-string "^[ \t]*|" "" s) args))
51 (defun ruby-assert-state (content index value &optional point)
52 "Assert syntax state values at the end of CONTENT.
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))))
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)))))
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))
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))
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))
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)))
85 (ert-deftest ruby-singleton-class-no-heredoc-font-lock ()
86 (ruby-assert-face "class<<a" 8 nil))
88 (ert-deftest ruby-heredoc-highlights-interpolations ()
89 (ruby-assert-face "s = <<EOS\n #{foo}\nEOS" 15 font-lock-variable-name-face))
91 (ert-deftest ruby-no-heredoc-inside-quotes ()
92 (ruby-assert-state "\"<<\", \"\",\nfoo" 3 nil))
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))
100 (ert-deftest ruby-no-heredoc-class-self ()
101 (ruby-assert-state "class <<self\nend" 3 nil))
103 (ert-deftest ruby-exit!-font-lock ()
104 (ruby-assert-face "exit!" 5 font-lock-builtin-face))
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)))
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)))
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))
125 (ert-deftest ruby-regexp-doesnt-start-in-string ()
126 (ruby-assert-state "'(/', /\d+/" 3 nil))
128 (ert-deftest ruby-regexp-starts-after-string ()
129 (ruby-assert-state "'(/', /\d+/" 3 ?/ 8))
131 (ert-deftest ruby-regexp-interpolation-is-highlighted ()
132 (ruby-assert-face "/#{foobs}/" 4 font-lock-variable-name-face))
134 (ert-deftest ruby-regexp-skips-over-interpolation ()
135 (ruby-assert-state "/#{foobs.join('/')}/" 3 nil))
137 (ert-deftest ruby-regexp-continues-till-end-when-unclosed ()
138 (ruby-assert-state "/bars" 3 ?/))
140 (ert-deftest ruby-regexp-can-be-multiline ()
141 (ruby-assert-state "/bars\ntees # toots \nfoos/" 3 nil))
143 (ert-deftest ruby-slash-symbol-is-not-mistaken-for-regexp ()
144 (ruby-assert-state ":/" 3 nil))
146 (ert-deftest ruby-slash-char-literal-is-not-mistaken-for-regexp ()
147 (ruby-assert-state "?/" 3 nil))
149 (ert-deftest ruby-regexp-is-not-mistaken-for-slash-symbol ()
150 (ruby-assert-state "x = /foo:/" 3 nil))
152 (ert-deftest ruby-indent-simple ()
153 (ruby-should-indent-buffer
154 "if foo
155 | bar
156 |end
157 |zot
159 "if foo
160 |bar
161 | end
162 | zot
163 |"))
165 (ert-deftest ruby-indent-keyword-label ()
166 (ruby-should-indent-buffer
167 "bar(class: XXX) do
168 | foo
169 |end
170 |bar
172 "bar(class: XXX) do
173 | foo
174 | end
175 | bar
176 |"))
178 (ert-deftest ruby-indent-method-with-question-mark ()
179 (ruby-should-indent-buffer
180 "if x.is_a?(XXX)
181 | foo
182 |end
184 "if x.is_a?(XXX)
185 | foo
186 | end
187 |"))
189 (ert-deftest ruby-indent-expr-in-regexp ()
190 (ruby-should-indent-buffer
191 "if /#{foo}/ =~ s
192 | x = 1
193 |end
195 "if /#{foo}/ =~ s
196 | x = 1
197 | end
198 |"))
200 (ert-deftest ruby-indent-singleton-class ()
201 (ruby-should-indent-buffer
202 "class<<bar
203 | foo
204 |end
206 "class<<bar
207 |foo
208 | end
209 |"))
211 (ert-deftest ruby-indent-inside-heredoc-after-operator ()
212 (ruby-should-indent-buffer
213 "b=<<eos
214 | 42"
215 "b=<<eos
216 | 42"))
218 (ert-deftest ruby-indent-inside-heredoc-after-space ()
219 (ruby-should-indent-buffer
220 "foo <<eos.gsub(' ', '*')
221 | 42"
222 "foo <<eos.gsub(' ', '*')
223 | 42"))
225 (ert-deftest ruby-indent-array-literal ()
226 (let ((ruby-deep-indent-paren nil))
227 (ruby-should-indent-buffer
228 "foo = [
229 | bar
232 "foo = [
233 | bar
235 |"))
236 (ruby-should-indent-buffer
237 "foo do
238 | [bar]
239 |end
241 "foo do
242 |[bar]
243 | end
244 |"))
246 (ert-deftest ruby-indent-begin-end ()
247 (ruby-should-indent-buffer
248 "begin
249 | a[b]
250 |end
252 "begin
253 | a[b]
254 | end
255 |"))
257 (ert-deftest ruby-indent-array-after-paren-and-space ()
258 (ruby-should-indent-buffer
259 "class A
260 | def foo
261 | foo( [])
262 | end
263 |end
265 "class A
266 | def foo
267 |foo( [])
268 |end
269 | end
270 |"))
272 (ert-deftest ruby-indent-after-block-in-continued-expression ()
273 (ruby-should-indent-buffer
274 "var =
275 | begin
276 | val
277 | end
278 |statement"
279 "var =
280 |begin
281 |val
282 |end
283 |statement"))
285 (ert-deftest ruby-indent-spread-args-in-parens ()
286 (let ((ruby-deep-indent-paren '(?\()))
287 (ruby-should-indent-buffer
288 "foo(1,
289 | 2,
290 | 3)
292 "foo(1,
293 | 2,
294 | 3)
295 |")))
297 (ert-deftest ruby-align-to-stmt-keywords-t ()
298 (let ((ruby-align-to-stmt-keywords t))
299 (ruby-should-indent-buffer
300 "foo = if bar?
302 |else
304 |end
306 |foo || begin
307 | bar
308 |end
310 |foo ||
311 | begin
312 | bar
313 | end
315 "foo = if bar?
317 |else
319 | end
321 | foo || begin
322 | bar
323 |end
325 | foo ||
326 | begin
327 |bar
328 | end
332 (ert-deftest ruby-align-to-stmt-keywords-case ()
333 (let ((ruby-align-to-stmt-keywords '(case)))
334 (ruby-should-indent-buffer
335 "b = case a
336 |when 13
338 |else
339 | 42
340 |end"
341 "b = case a
342 | when 13
344 | else
345 | 42
346 | end")))
348 (ert-deftest ruby-align-chained-calls ()
349 (let ((ruby-align-chained-calls t))
350 (ruby-should-indent-buffer
351 "one.two.three
352 | .four
354 |my_array.select { |str| str.size > 5 }
355 | .map { |str| str.downcase }"
356 "one.two.three
357 | .four
359 |my_array.select { |str| str.size > 5 }
360 | .map { |str| str.downcase }")))
362 (ert-deftest ruby-move-to-block-stops-at-indentation ()
363 (ruby-with-temp-buffer "def f\nend"
364 (beginning-of-line)
365 (ruby-move-to-block -1)
366 (should (looking-at "^def"))))
368 (ert-deftest ruby-toggle-block-to-do-end ()
369 (ruby-with-temp-buffer "foo {|b|\n}"
370 (beginning-of-line)
371 (ruby-toggle-block)
372 (should (string= "foo do |b|\nend" (buffer-string)))))
374 (ert-deftest ruby-toggle-block-to-brace ()
375 (let ((pairs '((17 . "foo { |b| b + 2 }")
376 (16 . "foo { |b|\n b + 2\n}"))))
377 (dolist (pair pairs)
378 (with-temp-buffer
379 (let ((fill-column (car pair)))
380 (insert "foo do |b|\n b + 2\nend")
381 (ruby-mode)
382 (beginning-of-line)
383 (ruby-toggle-block)
384 (should (string= (cdr pair) (buffer-string))))))))
386 (ert-deftest ruby-toggle-block-to-multiline ()
387 (ruby-with-temp-buffer "foo {|b| b + 1}"
388 (beginning-of-line)
389 (ruby-toggle-block)
390 (should (string= "foo do |b|\n b + 1\nend" (buffer-string)))))
392 (ert-deftest ruby-toggle-block-with-interpolation ()
393 (ruby-with-temp-buffer "foo do\n \"#{bar}\"\nend"
394 (beginning-of-line)
395 (ruby-toggle-block)
396 (should (string= "foo { \"#{bar}\" }" (buffer-string)))))
398 (ert-deftest ruby-recognize-symbols-starting-with-at-character ()
399 (ruby-assert-face ":@abc" 3 font-lock-constant-face))
401 (ert-deftest ruby-hash-character-not-interpolation ()
402 (ruby-assert-face "\"This is #{interpolation}\"" 15
403 font-lock-variable-name-face)
404 (ruby-assert-face "\"This is \\#{no interpolation} despite the #\""
405 15 font-lock-string-face)
406 (ruby-assert-face "\n#@comment, not ruby code" 5 font-lock-comment-face)
407 (ruby-assert-state "\n#@comment, not ruby code" 4 t)
408 (ruby-assert-face "# A comment cannot have #{an interpolation} in it"
409 30 font-lock-comment-face)
410 (ruby-assert-face "# #{comment}\n \"#{interpolation}\"" 16
411 font-lock-variable-name-face))
413 (ert-deftest ruby-interpolation-suppresses-quotes-inside ()
414 (let ((s "\"<ul><li>#{@files.join(\"</li><li>\")}</li></ul>\""))
415 (ruby-assert-state s 8 nil)
416 (ruby-assert-face s 9 font-lock-string-face)
417 (ruby-assert-face s 10 font-lock-variable-name-face)
418 (ruby-assert-face s 41 font-lock-string-face)))
420 (ert-deftest ruby-interpolation-suppresses-one-double-quote ()
421 (let ((s "\"foo#{'\"'}\""))
422 (ruby-assert-state s 8 nil)
423 (ruby-assert-face s 8 font-lock-variable-name-face)
424 (ruby-assert-face s 11 font-lock-string-face)))
426 (ert-deftest ruby-interpolation-suppresses-one-backtick ()
427 (let ((s "`as#{'`'}das`"))
428 (ruby-assert-state s 8 nil)))
430 (ert-deftest ruby-interpolation-keeps-non-quote-syntax ()
431 (let ((s "\"foo#{baz.tee}bar\""))
432 (ruby-with-temp-buffer s
433 (goto-char (point-min))
434 (ruby-mode)
435 (syntax-propertize (point-max))
436 (search-forward "tee")
437 (should (string= (thing-at-point 'symbol) "tee")))))
439 (ert-deftest ruby-interpolation-inside-percent-literal ()
440 (let ((s "%( #{boo} )"))
441 (ruby-assert-face s 1 font-lock-string-face)
442 (ruby-assert-face s 4 font-lock-variable-name-face)
443 (ruby-assert-face s 10 font-lock-string-face)
444 (ruby-assert-state s 8 nil)))
446 (ert-deftest ruby-interpolation-inside-percent-literal-with-paren ()
447 :expected-result :failed
448 (let ((s "%(^#{\")\"}^)"))
449 (ruby-assert-face s 3 font-lock-string-face)
450 (ruby-assert-face s 4 font-lock-variable-name-face)
451 (ruby-assert-face s 10 font-lock-string-face)
452 ;; It's confused by the closing paren in the middle.
453 (ruby-assert-state s 8 nil)))
455 (ert-deftest ruby-interpolation-inside-another-interpolation ()
456 :expected-result :failed
457 (let ((s "\"#{[a, b, c].map { |v| \"#{v}\" }.join}\""))
458 (ruby-assert-face s 1 font-lock-string-face)
459 (ruby-assert-face s 2 font-lock-variable-name-face)
460 (ruby-assert-face s 38 font-lock-string-face)
461 (ruby-assert-state s 8 nil)))
463 (ert-deftest ruby-interpolation-inside-double-quoted-percent-literals ()
464 (ruby-assert-face "%Q{foo #@bar}" 8 font-lock-variable-name-face)
465 (ruby-assert-face "%W{foo #@bar}" 8 font-lock-variable-name-face)
466 (ruby-assert-face "%r{foo #@bar}" 8 font-lock-variable-name-face)
467 (ruby-assert-face "%x{foo #@bar}" 8 font-lock-variable-name-face))
469 (ert-deftest ruby-no-interpolation-in-single-quoted-literals ()
470 (ruby-assert-face "'foo #@bar'" 7 font-lock-string-face)
471 (ruby-assert-face "%q{foo #@bar}" 8 font-lock-string-face)
472 (ruby-assert-face "%w{foo #@bar}" 8 font-lock-string-face)
473 (ruby-assert-face "%s{foo #@bar}" 8 font-lock-string-face))
475 (ert-deftest ruby-interpolation-after-dollar-sign ()
476 (ruby-assert-face "\"$#{balance}\"" 2 'font-lock-string-face)
477 (ruby-assert-face "\"$#{balance}\"" 3 'font-lock-variable-name-face))
479 (ert-deftest ruby-no-unknown-percent-literals ()
480 ;; No folding of case.
481 (ruby-assert-face "%S{foo}" 4 nil)
482 (ruby-assert-face "%R{foo}" 4 nil))
484 (ert-deftest ruby-no-nested-percent-literals ()
485 (ruby-with-temp-buffer "a = %w[b %()]"
486 (syntax-propertize (point))
487 (should (null (nth 8 (syntax-ppss))))
488 (should (eq t (nth 3 (syntax-ppss (1- (point-max))))))
489 (search-backward "[")
490 (should (eq t (nth 3 (syntax-ppss))))))
492 (ert-deftest ruby-add-log-current-method-examples ()
493 (let ((pairs '(("foo" . "#foo")
494 ("C.foo" . ".foo")
495 ("self.foo" . ".foo"))))
496 (dolist (pair pairs)
497 (let ((name (car pair))
498 (value (cdr pair)))
499 (ruby-with-temp-buffer (ruby-test-string
500 "module M
501 | class C
502 | def %s
504 | end
505 | end
506 |end"
507 name)
508 (search-backward "_")
509 (forward-line)
510 (should (string= (ruby-add-log-current-method)
511 (format "M::C%s" value))))))))
513 (ert-deftest ruby-add-log-current-method-outside-of-method ()
514 (ruby-with-temp-buffer (ruby-test-string
515 "module M
516 | class C
517 | def foo
518 | end
520 | end
521 |end")
522 (search-backward "_")
523 (should (string= (ruby-add-log-current-method)"M::C"))))
525 (ert-deftest ruby-add-log-current-method-in-singleton-class ()
526 (ruby-with-temp-buffer (ruby-test-string
527 "class C
528 | class << self
529 | def foo
531 | end
532 | end
533 |end")
534 (search-backward "_")
535 (should (string= (ruby-add-log-current-method) "C.foo"))))
537 (ert-deftest ruby-add-log-current-method-namespace-shorthand ()
538 (ruby-with-temp-buffer (ruby-test-string
539 "class C::D
540 | def foo
542 | end
543 |end")
544 (search-backward "_")
545 (should (string= (ruby-add-log-current-method) "C::D#foo"))))
547 (ert-deftest ruby-add-log-current-method-after-inner-class ()
548 (ruby-with-temp-buffer (ruby-test-string
549 "module M
550 | class C
551 | class D
552 | end
553 | def foo
555 | end
556 | end
557 |end")
558 (search-backward "_")
559 (should (string= (ruby-add-log-current-method) "M::C#foo"))))
561 (defvar ruby-block-test-example
562 (ruby-test-string
563 "class C
564 | def foo
566 | end
568 | def bar
570 | end
572 | def baz
573 |some do
575 | end
576 | end
577 |end"))
579 (defmacro ruby-deftest-move-to-block (name &rest body)
580 (declare (indent defun))
581 `(ert-deftest ,(intern (format "ruby-move-to-block-%s" name)) ()
582 (with-temp-buffer
583 (insert ruby-block-test-example)
584 (ruby-mode)
585 (goto-char (point-min))
586 ,@body)))
588 (ruby-deftest-move-to-block works-on-do
589 (forward-line 10)
590 (ruby-end-of-block)
591 (should (= 13 (line-number-at-pos)))
592 (ruby-beginning-of-block)
593 (should (= 11 (line-number-at-pos))))
595 (ruby-deftest-move-to-block zero-is-noop
596 (forward-line 4)
597 (ruby-move-to-block 0)
598 (should (= 5 (line-number-at-pos))))
600 (ruby-deftest-move-to-block ok-with-three
601 (forward-line 1)
602 (ruby-move-to-block 3)
603 (should (= 14 (line-number-at-pos))))
605 (ruby-deftest-move-to-block ok-with-minus-two
606 (forward-line 9)
607 (ruby-move-to-block -2)
608 (should (= 2 (line-number-at-pos))))
610 (ert-deftest ruby-move-to-block-skips-percent-literal ()
611 (dolist (s (list (ruby-test-string
612 "foo do
613 | a = %%w(
614 | def yaa
616 |end")
617 (ruby-test-string
618 "foo do
619 | a = %%w|
620 | end
622 |end")))
623 (ruby-with-temp-buffer s
624 (goto-char (point-min))
625 (ruby-end-of-block)
626 (should (= 5 (line-number-at-pos)))
627 (ruby-beginning-of-block)
628 (should (= 1 (line-number-at-pos))))))
630 (ert-deftest ruby-move-to-block-skips-heredoc ()
631 (ruby-with-temp-buffer
632 (ruby-test-string
633 "if something_wrong?
634 | ActiveSupport::Deprecation.warn(<<-eowarn)
635 | boo hoo
636 | end
637 | eowarn
638 |end")
639 (goto-char (point-min))
640 (ruby-end-of-block)
641 (should (= 6 (line-number-at-pos)))
642 (ruby-beginning-of-block)
643 (should (= 1 (line-number-at-pos)))))
645 (ert-deftest ruby-move-to-block-does-not-fold-case ()
646 (ruby-with-temp-buffer
647 (ruby-test-string
648 "foo do
649 | Module.to_s
650 |end")
651 (let ((case-fold-search t))
652 (ruby-beginning-of-block))
653 (should (= 1 (line-number-at-pos)))))
655 (ert-deftest ruby-move-to-block-moves-from-else-to-if ()
656 (ruby-with-temp-buffer (ruby-test-string
657 "if true
658 | nested_block do
659 | end
660 |else
661 |end")
662 (goto-char (point-min))
663 (forward-line 3)
664 (ruby-beginning-of-block)
665 (should (= 1 (line-number-at-pos)))))
667 (ert-deftest ruby-beginning-of-defun-does-not-fold-case ()
668 (ruby-with-temp-buffer
669 (ruby-test-string
670 "class C
671 | def bar
672 | Class.to_s
673 | end
674 |end")
675 (goto-char (point-min))
676 (forward-line 3)
677 (let ((case-fold-search t))
678 (beginning-of-defun))
679 (should (= 2 (line-number-at-pos)))))
681 (ert-deftest ruby-end-of-defun-skips-to-next-line-after-the-method ()
682 (ruby-with-temp-buffer
683 (ruby-test-string
684 "class D
685 | def tee
686 | 'ho hum'
687 | end
688 |end")
689 (goto-char (point-min))
690 (forward-line 1)
691 (end-of-defun)
692 (should (= 5 (line-number-at-pos)))))
694 (defvar ruby-sexp-test-example
695 (ruby-test-string
696 "class C
697 | def foo
698 | self.end
699 | D.new.class
700 | [1, 2, 3].map do |i|
701 | i + 1
702 | end.sum
703 | end
704 |end"))
706 (ert-deftest ruby-forward-sexp-skips-method-calls-with-keyword-names ()
707 (ruby-with-temp-buffer ruby-sexp-test-example
708 (goto-char (point-min))
709 (forward-line 1)
710 (ruby-forward-sexp)
711 (should (= 8 (line-number-at-pos)))))
713 (ert-deftest ruby-backward-sexp-skips-method-calls-with-keyword-names ()
714 (ruby-with-temp-buffer ruby-sexp-test-example
715 (goto-char (point-min))
716 (forward-line 7)
717 (end-of-line)
718 (ruby-backward-sexp)
719 (should (= 2 (line-number-at-pos)))))
721 (ert-deftest ruby-toggle-string-quotes-quotes-correctly ()
722 (let ((pairs
723 '(("puts '\"foo\"\\''" . "puts \"\\\"foo\\\"'\"")
724 ("puts \"'foo'\\\"\"" . "puts '\\'foo\\'\"'"))))
725 (dolist (pair pairs)
726 (ruby-with-temp-buffer (car pair)
727 (beginning-of-line)
728 (search-forward "foo")
729 (ruby-toggle-string-quotes)
730 (should (string= (buffer-string) (cdr pair)))))))
732 (ert-deftest ruby--insert-coding-comment-ruby-style ()
733 (with-temp-buffer
734 (let ((ruby-encoding-magic-comment-style 'ruby))
735 (ruby--insert-coding-comment "utf-8")
736 (should (string= "# coding: utf-8\n" (buffer-string))))))
738 (ert-deftest ruby--insert-coding-comment-emacs-style ()
739 (with-temp-buffer
740 (let ((ruby-encoding-magic-comment-style 'emacs))
741 (ruby--insert-coding-comment "utf-8")
742 (should (string= "# -*- coding: utf-8 -*-\n" (buffer-string))))))
744 (ert-deftest ruby--insert-coding-comment-custom-style ()
745 (with-temp-buffer
746 (let ((ruby-encoding-magic-comment-style 'custom)
747 (ruby-custom-encoding-magic-comment-template "# encoding: %s\n"))
748 (ruby--insert-coding-comment "utf-8")
749 (should (string= "# encoding: utf-8\n\n" (buffer-string))))))
752 (provide 'ruby-mode-tests)
754 ;;; ruby-mode-tests.el ends here