diff options
author | Stefan Kangas <stefankangas@gmail.com> | 2019-05-05 15:48:57 +0200 |
---|---|---|
committer | Basil L. Contovounesios <contovob@tcd.ie> | 2019-05-20 15:29:26 +0100 |
commit | 4498e5a13a3b63a3024ceef102ae3b5c50f58be1 (patch) | |
tree | 7f4d1809c602b93ac73eacf7ea25d65a87c3a85b /test/lisp/delim-col-tests.el | |
parent | 9813905f834aa43eb194023f579c7e7951d96d0f (diff) | |
download | emacs-4498e5a13a3b63a3024ceef102ae3b5c50f58be1.tar.gz |
Use lexical-binding in delim-col.el and add tests
Thanks to Basil L. Contovounesios for additional cleanups.
For discussion, see the following thread:
https://lists.gnu.org/archive/html/emacs-devel/2019-05/msg00177.html
* lisp/delim-col.el: Use lexical-binding.
* test/lisp/delim-col-tests.el: New file.
(delim-col-tests-delimit-colummns-before-after)
(delim-col-tests-delimit-columns)
(delim-col-tests-delimit-columns-format/nil)
(delim-col-tests-delimit-columns-format/padding)
(delim-col-tests-delimit-columns-format/separator)
(delim-col-tests-delimit-columns-separator)
(delim-col-tests-delimit-columns-str-before-after)
(delim-col-tests-delimit-columns-str-separator)
(delim-col-tests-delimit-rectangle): New unit tests.
Diffstat (limited to 'test/lisp/delim-col-tests.el')
-rw-r--r-- | test/lisp/delim-col-tests.el | 181 |
1 files changed, 181 insertions, 0 deletions
diff --git a/test/lisp/delim-col-tests.el b/test/lisp/delim-col-tests.el new file mode 100644 index 00000000000..f2a0377b07b --- /dev/null +++ b/test/lisp/delim-col-tests.el @@ -0,0 +1,181 @@ +;;; delim-col-tests.el --- Tests for delim-col.el -*- lexical-binding: t; -*- + +;; Copyright (C) 2019 Free Software Foundation, Inc. + +;; Author: Stefan Kangas <stefankangas@gmail.com> + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;;; Code: + +(require 'ert) +(require 'delim-col) + +(ert-deftest delim-col-tests-delimit-columns () + (with-temp-buffer + (insert "a b c\n") + (delimit-columns-region (point-min) (point-max)) + (should (equal (buffer-string) "a, b, c\n"))) + (with-temp-buffer + (insert "a b c d\n" + "aaaa bb ccc ddddd\n" + "aaa bbb cccc dddd\n" + "aa bb ccccccc ddd\n") + (delimit-columns-region (point-min) (point-max)) + (should (equal (buffer-string) + (concat "a, b, c, d \n" + "aaaa, bb, ccc, ddddd\n" + "aaa, bbb, cccc, dddd \n" + "aa, bb, ccccccc, ddd \n"))))) + +(ert-deftest delim-col-tests-delimit-rectangle () + (with-temp-buffer + (insert "a b c d\n" + "aaaa bb ccc ddddd\n" + "aaa bbb cccc dddd\n" + "aa bb ccccccc ddd\n") + (delimit-columns-rectangle 3 58) ; from first b to last c + (should (equal (buffer-string) + (concat "a b, c d\n" + "aaaa bb, ccc ddddd\n" + "aaa bbb, cccc dddd\n" + "aa bb, ccccccc ddd\n"))))) + +(ert-deftest delim-col-tests-delimit-columns-str-separator () + (let ((delimit-columns-str-separator ":")) + (with-temp-buffer + (insert "a b\n") + (delimit-columns-region (point-min) (point-max)) + (should (equal (buffer-string) "a:b\n"))) + (with-temp-buffer + (insert "a b c d\n" + "aa bb cc dd\n") + (delimit-columns-rectangle 3 16) ; from first b to last c + (should (equal (buffer-string) + (concat "a b: c d\n" + "aa bb:cc dd\n")))))) + +(ert-deftest delim-col-tests-delimit-columns-str-before-after () + (let ((delimit-columns-str-before "[ ") + (delimit-columns-str-after " ]")) + (with-temp-buffer + (insert "a b c\n") + (delimit-columns-region (point-min) (point-max)) + (should (equal (buffer-string) "[ a, b, c ]\n"))) + (with-temp-buffer + (insert "a b c d\n" + "aaaa bb ccc ddddd\n" + "aaa bbb cccc dddd\n" + "aa bb ccccccc ddd\n") + (delimit-columns-region (point-min) (point-max)) + (should (equal (buffer-string) + (concat "[ a, b, c, d ]\n" + "[ aaaa, bb, ccc, ddddd ]\n" + "[ aaa, bbb, cccc, dddd ]\n" + "[ aa, bb, ccccccc, ddd ]\n")))) + (with-temp-buffer + (insert "a b c d\n" + "aaaa bb ccc ddddd\n" + "aaa bbb cccc dddd\n" + "aa bb ccccccc ddd\n") + (delimit-columns-rectangle 3 58) ; from first b to last c + (should (equal (buffer-string) + (concat "a [ b, c ] d\n" + "aaaa [ bb, ccc ] ddddd\n" + "aaa [ bbb, cccc ] dddd\n" + "aa [ bb, ccccccc ] ddd\n")))))) + +(ert-deftest delim-col-tests-delimit-colummns-before-after () + (let ((delimit-columns-before "<") + (delimit-columns-after ">")) + (with-temp-buffer + (insert "a b\n") + (delimit-columns-region (point-min) (point-max)) + (should (equal (buffer-string) "<a>, <b>\n"))) + (with-temp-buffer + (insert "a b c d\n" + "aa bb cc dd\n") + (delimit-columns-rectangle 3 17) + (should (equal (buffer-string) + (concat "a <b>, <c> d\n" + "aa <bb>, <cc> dd\n")))))) + +(ert-deftest delim-col-tests-delimit-columns-separator () + (let ((delimit-columns-separator ",")) + (with-temp-buffer + (insert "a,b,c\n") + (delimit-columns-region (point-min) (point-max)) + (should (equal (buffer-string) "a, b, c\n"))))) + +(ert-deftest delim-col-tests-delimit-columns-format/nil () + (let ((delimit-columns-format nil)) + (with-temp-buffer + (insert "a b\n" + "aa bb\n") + (delimit-columns-region (point-min) (point-max)) + (should (equal (buffer-string) + (concat "a, b\n" + "aa, bb\n")))) + (with-temp-buffer + (insert "a b c d\n" + "aa bb cc dd\n") + (delimit-columns-rectangle 3 17) ; from first b to last c + (should (equal (buffer-string) + (concat "a b, c d\n" + "aa bb, cc dd\n")))))) + +(ert-deftest delim-col-tests-delimit-columns-format/separator () + (let ((delimit-columns-format 'separator) + (delimit-columns-before "<") + (delimit-columns-after ">")) + (with-temp-buffer + (insert "a b\n" + "aa bb\n") + (delimit-columns-region (point-min) (point-max)) + (should (equal (buffer-string) + (concat "<a> , <b> \n" + "<aa>, <bb>\n")))) + (with-temp-buffer + (insert "a b c d\n" + "aa bb cc dd\n") + (delimit-columns-rectangle 3 17) ; from first b to last c + (should (equal (buffer-string) + (concat "a <b> , <c> d\n" + "aa <bb>, <cc> dd\n")))))) + +(ert-deftest delim-col-tests-delimit-columns-format/padding () + (let ((delimit-columns-format 'padding) + (delimit-columns-before "<") + (delimit-columns-after ">")) + (with-temp-buffer + (insert "a b\n" + "aa bb\n") + (delimit-columns-region (point-min) (point-max)) + (should (equal (buffer-string) + (concat "<a >, <b >\n" + "<aa>, <bb>\n")))) + (with-temp-buffer + (insert "a b c d\n" + "aa bb cc dd\n") + (delimit-columns-rectangle 3 17) ; from first b to last c + (should (equal (buffer-string) + (concat "a <b >, <c > d\n" + "aa <bb>, <cc> dd\n")))))) + +(provide 'delim-col-tests) +;;; delim-col-tests.el ends here |