diff options
| author | Stefan Kangas | 2019-05-05 15:48:57 +0200 |
|---|---|---|
| committer | Basil L. Contovounesios | 2019-05-20 15:29:26 +0100 |
| commit | 4498e5a13a3b63a3024ceef102ae3b5c50f58be1 (patch) | |
| tree | 7f4d1809c602b93ac73eacf7ea25d65a87c3a85b /test | |
| parent | 9813905f834aa43eb194023f579c7e7951d96d0f (diff) | |
| download | emacs-4498e5a13a3b63a3024ceef102ae3b5c50f58be1.tar.gz emacs-4498e5a13a3b63a3024ceef102ae3b5c50f58be1.zip | |
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')
| -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 @@ | |||
| 1 | ;;; delim-col-tests.el --- Tests for delim-col.el -*- lexical-binding: t; -*- | ||
| 2 | |||
| 3 | ;; Copyright (C) 2019 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Stefan Kangas <stefankangas@gmail.com> | ||
| 6 | |||
| 7 | ;; This file is part of GNU Emacs. | ||
| 8 | |||
| 9 | ;; GNU Emacs is free software: you can redistribute it and/or modify | ||
| 10 | ;; it under the terms of the GNU General Public License as published by | ||
| 11 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 12 | ;; (at your option) any later version. | ||
| 13 | |||
| 14 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 15 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | ;; GNU General Public License for more details. | ||
| 18 | |||
| 19 | ;; You should have received a copy of the GNU General Public License | ||
| 20 | ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. | ||
| 21 | |||
| 22 | ;;; Commentary: | ||
| 23 | |||
| 24 | ;;; Code: | ||
| 25 | |||
| 26 | (require 'ert) | ||
| 27 | (require 'delim-col) | ||
| 28 | |||
| 29 | (ert-deftest delim-col-tests-delimit-columns () | ||
| 30 | (with-temp-buffer | ||
| 31 | (insert "a b c\n") | ||
| 32 | (delimit-columns-region (point-min) (point-max)) | ||
| 33 | (should (equal (buffer-string) "a, b, c\n"))) | ||
| 34 | (with-temp-buffer | ||
| 35 | (insert "a b c d\n" | ||
| 36 | "aaaa bb ccc ddddd\n" | ||
| 37 | "aaa bbb cccc dddd\n" | ||
| 38 | "aa bb ccccccc ddd\n") | ||
| 39 | (delimit-columns-region (point-min) (point-max)) | ||
| 40 | (should (equal (buffer-string) | ||
| 41 | (concat "a, b, c, d \n" | ||
| 42 | "aaaa, bb, ccc, ddddd\n" | ||
| 43 | "aaa, bbb, cccc, dddd \n" | ||
| 44 | "aa, bb, ccccccc, ddd \n"))))) | ||
| 45 | |||
| 46 | (ert-deftest delim-col-tests-delimit-rectangle () | ||
| 47 | (with-temp-buffer | ||
| 48 | (insert "a b c d\n" | ||
| 49 | "aaaa bb ccc ddddd\n" | ||
| 50 | "aaa bbb cccc dddd\n" | ||
| 51 | "aa bb ccccccc ddd\n") | ||
| 52 | (delimit-columns-rectangle 3 58) ; from first b to last c | ||
| 53 | (should (equal (buffer-string) | ||
| 54 | (concat "a b, c d\n" | ||
| 55 | "aaaa bb, ccc ddddd\n" | ||
| 56 | "aaa bbb, cccc dddd\n" | ||
| 57 | "aa bb, ccccccc ddd\n"))))) | ||
| 58 | |||
| 59 | (ert-deftest delim-col-tests-delimit-columns-str-separator () | ||
| 60 | (let ((delimit-columns-str-separator ":")) | ||
| 61 | (with-temp-buffer | ||
| 62 | (insert "a b\n") | ||
| 63 | (delimit-columns-region (point-min) (point-max)) | ||
| 64 | (should (equal (buffer-string) "a:b\n"))) | ||
| 65 | (with-temp-buffer | ||
| 66 | (insert "a b c d\n" | ||
| 67 | "aa bb cc dd\n") | ||
| 68 | (delimit-columns-rectangle 3 16) ; from first b to last c | ||
| 69 | (should (equal (buffer-string) | ||
| 70 | (concat "a b: c d\n" | ||
| 71 | "aa bb:cc dd\n")))))) | ||
| 72 | |||
| 73 | (ert-deftest delim-col-tests-delimit-columns-str-before-after () | ||
| 74 | (let ((delimit-columns-str-before "[ ") | ||
| 75 | (delimit-columns-str-after " ]")) | ||
| 76 | (with-temp-buffer | ||
| 77 | (insert "a b c\n") | ||
| 78 | (delimit-columns-region (point-min) (point-max)) | ||
| 79 | (should (equal (buffer-string) "[ a, b, c ]\n"))) | ||
| 80 | (with-temp-buffer | ||
| 81 | (insert "a b c d\n" | ||
| 82 | "aaaa bb ccc ddddd\n" | ||
| 83 | "aaa bbb cccc dddd\n" | ||
| 84 | "aa bb ccccccc ddd\n") | ||
| 85 | (delimit-columns-region (point-min) (point-max)) | ||
| 86 | (should (equal (buffer-string) | ||
| 87 | (concat "[ a, b, c, d ]\n" | ||
| 88 | "[ aaaa, bb, ccc, ddddd ]\n" | ||
| 89 | "[ aaa, bbb, cccc, dddd ]\n" | ||
| 90 | "[ aa, bb, ccccccc, ddd ]\n")))) | ||
| 91 | (with-temp-buffer | ||
| 92 | (insert "a b c d\n" | ||
| 93 | "aaaa bb ccc ddddd\n" | ||
| 94 | "aaa bbb cccc dddd\n" | ||
| 95 | "aa bb ccccccc ddd\n") | ||
| 96 | (delimit-columns-rectangle 3 58) ; from first b to last c | ||
| 97 | (should (equal (buffer-string) | ||
| 98 | (concat "a [ b, c ] d\n" | ||
| 99 | "aaaa [ bb, ccc ] ddddd\n" | ||
| 100 | "aaa [ bbb, cccc ] dddd\n" | ||
| 101 | "aa [ bb, ccccccc ] ddd\n")))))) | ||
| 102 | |||
| 103 | (ert-deftest delim-col-tests-delimit-colummns-before-after () | ||
| 104 | (let ((delimit-columns-before "<") | ||
| 105 | (delimit-columns-after ">")) | ||
| 106 | (with-temp-buffer | ||
| 107 | (insert "a b\n") | ||
| 108 | (delimit-columns-region (point-min) (point-max)) | ||
| 109 | (should (equal (buffer-string) "<a>, <b>\n"))) | ||
| 110 | (with-temp-buffer | ||
| 111 | (insert "a b c d\n" | ||
| 112 | "aa bb cc dd\n") | ||
| 113 | (delimit-columns-rectangle 3 17) | ||
| 114 | (should (equal (buffer-string) | ||
| 115 | (concat "a <b>, <c> d\n" | ||
| 116 | "aa <bb>, <cc> dd\n")))))) | ||
| 117 | |||
| 118 | (ert-deftest delim-col-tests-delimit-columns-separator () | ||
| 119 | (let ((delimit-columns-separator ",")) | ||
| 120 | (with-temp-buffer | ||
| 121 | (insert "a,b,c\n") | ||
| 122 | (delimit-columns-region (point-min) (point-max)) | ||
| 123 | (should (equal (buffer-string) "a, b, c\n"))))) | ||
| 124 | |||
| 125 | (ert-deftest delim-col-tests-delimit-columns-format/nil () | ||
| 126 | (let ((delimit-columns-format nil)) | ||
| 127 | (with-temp-buffer | ||
| 128 | (insert "a b\n" | ||
| 129 | "aa bb\n") | ||
| 130 | (delimit-columns-region (point-min) (point-max)) | ||
| 131 | (should (equal (buffer-string) | ||
| 132 | (concat "a, b\n" | ||
| 133 | "aa, bb\n")))) | ||
| 134 | (with-temp-buffer | ||
| 135 | (insert "a b c d\n" | ||
| 136 | "aa bb cc dd\n") | ||
| 137 | (delimit-columns-rectangle 3 17) ; from first b to last c | ||
| 138 | (should (equal (buffer-string) | ||
| 139 | (concat "a b, c d\n" | ||
| 140 | "aa bb, cc dd\n")))))) | ||
| 141 | |||
| 142 | (ert-deftest delim-col-tests-delimit-columns-format/separator () | ||
| 143 | (let ((delimit-columns-format 'separator) | ||
| 144 | (delimit-columns-before "<") | ||
| 145 | (delimit-columns-after ">")) | ||
| 146 | (with-temp-buffer | ||
| 147 | (insert "a b\n" | ||
| 148 | "aa bb\n") | ||
| 149 | (delimit-columns-region (point-min) (point-max)) | ||
| 150 | (should (equal (buffer-string) | ||
| 151 | (concat "<a> , <b> \n" | ||
| 152 | "<aa>, <bb>\n")))) | ||
| 153 | (with-temp-buffer | ||
| 154 | (insert "a b c d\n" | ||
| 155 | "aa bb cc dd\n") | ||
| 156 | (delimit-columns-rectangle 3 17) ; from first b to last c | ||
| 157 | (should (equal (buffer-string) | ||
| 158 | (concat "a <b> , <c> d\n" | ||
| 159 | "aa <bb>, <cc> dd\n")))))) | ||
| 160 | |||
| 161 | (ert-deftest delim-col-tests-delimit-columns-format/padding () | ||
| 162 | (let ((delimit-columns-format 'padding) | ||
| 163 | (delimit-columns-before "<") | ||
| 164 | (delimit-columns-after ">")) | ||
| 165 | (with-temp-buffer | ||
| 166 | (insert "a b\n" | ||
| 167 | "aa bb\n") | ||
| 168 | (delimit-columns-region (point-min) (point-max)) | ||
| 169 | (should (equal (buffer-string) | ||
| 170 | (concat "<a >, <b >\n" | ||
| 171 | "<aa>, <bb>\n")))) | ||
| 172 | (with-temp-buffer | ||
| 173 | (insert "a b c d\n" | ||
| 174 | "aa bb cc dd\n") | ||
| 175 | (delimit-columns-rectangle 3 17) ; from first b to last c | ||
| 176 | (should (equal (buffer-string) | ||
| 177 | (concat "a <b >, <c > d\n" | ||
| 178 | "aa <bb>, <cc> dd\n")))))) | ||
| 179 | |||
| 180 | (provide 'delim-col-tests) | ||
| 181 | ;;; delim-col-tests.el ends here | ||