]> code.delx.au - gnu-emacs-elpa/blob - packages/cycle-quotes/cycle-quotes-test.el
Merge commit '0cda39255827f283e7578cd469ae42daad9556a2' from js2-mode
[gnu-emacs-elpa] / packages / cycle-quotes / cycle-quotes-test.el
1 ;;; cycle-quotes-test.el --- Tests for cycle-quotes.el -*- lexical-binding: t; -*-
2
3 ;; Copyright (C) 2015-2016 Free Software Foundation, Inc.
4
5 ;; Author: Simen Heggestøyl <simenheg@gmail.com>
6
7 ;; This program 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 ;; This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
19
20 ;;; Commentary:
21
22 ;;; Code:
23
24 (require 'cycle-quotes)
25 (require 'ert)
26 ;; For testing triple quotes
27 (require 'python)
28
29 (ert-deftest test-cycle-quotes--set-quote-chars ()
30 (with-temp-buffer
31 (let ((st (make-syntax-table)))
32 (set-syntax-table st)
33 (modify-syntax-entry ?a "\"")
34 (modify-syntax-entry ?b "\"")
35 (cycle-quotes--set-quote-chars)
36 (should (= (length cycle-quotes--quote-chars) 3))
37 (should (memq ?a cycle-quotes--quote-chars))
38 (should (memq ?b cycle-quotes--quote-chars))
39 (should (memq ?\" cycle-quotes--quote-chars)))))
40
41 (ert-deftest test-cycle-quotes--next-quote-char ()
42 (let ((cycle-quotes--quote-chars '(?a)))
43 (should (= (cycle-quotes--next-quote-char ?a) ?a)))
44 (let ((cycle-quotes--quote-chars '(?a ?b)))
45 (should (= (cycle-quotes--next-quote-char ?a) ?b)))
46 (let ((cycle-quotes--quote-chars '(?a ?b ?c)))
47 (should (= (cycle-quotes--next-quote-char ?c) ?a))))
48
49 (ert-deftest test-cycle-quotes--fix-escapes ()
50 (with-temp-buffer
51 (insert "b\\baabc\\b")
52 (cycle-quotes--fix-escapes (point-min) (point-max) ?a ?b)
53 (should (equal (buffer-string) "bb\\a\\abcb"))))
54
55 (ert-deftest test-cycle-quotes ()
56 (with-temp-buffer
57 (let ((st (make-syntax-table)))
58 (set-syntax-table st)
59 (modify-syntax-entry ?' "\"")
60 (modify-syntax-entry ?` "\"")
61 (insert "\"Hi, it's me!\"")
62 (goto-char 5)
63 (cycle-quotes)
64 (should (equal (buffer-string) "`Hi, it's me!`"))
65 (cycle-quotes)
66 (should (equal (buffer-string) "'Hi, it\\'s me!'"))
67 (cycle-quotes)
68 (should (equal (buffer-string) "\"Hi, it's me!\"")))))
69
70 (ert-deftest test-cycle-quotes-triple-quotes ()
71 (with-temp-buffer
72 (python-mode)
73 (insert "'''Triple quotes, as found in Python.'''")
74 (goto-char 5)
75 (cycle-quotes)
76 (should (equal (buffer-string)
77 "\"\"\"Triple quotes, as found in Python.\"\"\""))
78 (cycle-quotes)
79 (should (equal (buffer-string)
80 "'''Triple quotes, as found in Python.'''"))))
81
82 (provide 'cycle-quotes-test)
83 ;;; cycle-quotes-test.el ends here