1 ;;; cycle-quotes-test.el --- Tests for cycle-quotes.el -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2015-2016 Free Software Foundation, Inc.
5 ;; Author: Simen Heggestøyl <simenheg@gmail.com>
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.
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.
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/>.
24 (require 'cycle-quotes)
26 ;; For testing triple quotes
29 (ert-deftest test-cycle-quotes--set-quote-chars ()
31 (let ((st (make-syntax-table)))
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)))))
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))))
49 (ert-deftest test-cycle-quotes--fix-escapes ()
51 (insert "b\\baabc\\b")
52 (cycle-quotes--fix-escapes (point-min) (point-max) ?a ?b)
53 (should (equal (buffer-string) "bb\\a\\abcb"))))
55 (ert-deftest test-cycle-quotes ()
57 (let ((st (make-syntax-table)))
59 (modify-syntax-entry ?' "\"")
60 (modify-syntax-entry ?` "\"")
61 (insert "\"Hi, it's me!\"")
64 (should (equal (buffer-string) "`Hi, it's me!`"))
66 (should (equal (buffer-string) "'Hi, it\\'s me!'"))
68 (should (equal (buffer-string) "\"Hi, it's me!\"")))))
70 (ert-deftest test-cycle-quotes-triple-quotes ()
73 (insert "'''Triple quotes, as found in Python.'''")
76 (should (equal (buffer-string)
77 "\"\"\"Triple quotes, as found in Python.\"\"\""))
79 (should (equal (buffer-string)
80 "'''Triple quotes, as found in Python.'''"))))
82 (provide 'cycle-quotes-test)
83 ;;; cycle-quotes-test.el ends here