all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] Unit tests and lexical-binding for delim-col.el
@ 2019-05-07 20:56 Stefan Kangas
  2019-05-07 22:44 ` Basil L. Contovounesios
  0 siblings, 1 reply; 14+ messages in thread
From: Stefan Kangas @ 2019-05-07 20:56 UTC (permalink / raw)
  To: emacs-devel


[-- Attachment #1.1: Type: text/plain, Size: 594 bytes --]

Hi all,

I was looking into some area where I could contribute and ended up writing
unit
tests for `delim-col.el' and adding the lexical-binding header.

I wasn't inclined to convert the code in delim-col.el to actually take
advantage
of lexical bindings, but it compiles and runs fine with just naively adding
the
header.

Please let me know what you think or if I've made any obvious mistakes.

Thanks,
Stefan Kangas

PS. Since this patch is longer than 15 lines, I have initiated the copyright
assignment process.  It wasn't obvious if this should be done before or
after
mailing this list.

[-- Attachment #1.2: Type: text/html, Size: 779 bytes --]

[-- Attachment #2: 0001-lisp-delim-col.el-Use-lexical-binding.patch --]
[-- Type: text/x-patch, Size: 8508 bytes --]

From f11bd037478aa64b83ffe97a925357cddc886316 Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefankangas@gmail.com>
Date: Sun, 5 May 2019 15:48:57 +0200
Subject: [PATCH] * lisp/delim-col.el: Use lexical-binding

* test/lisp/delim-col-tests.el (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.
---
 lisp/delim-col.el            |   2 +-
 test/lisp/delim-col-tests.el | 183 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 184 insertions(+), 1 deletion(-)
 create mode 100644 test/lisp/delim-col-tests.el

diff --git a/lisp/delim-col.el b/lisp/delim-col.el
index a968b32052..77c378ffe6 100644
--- a/lisp/delim-col.el
+++ b/lisp/delim-col.el
@@ -1,4 +1,4 @@
-;;; delim-col.el --- prettify all columns in a region or rectangle
+;;; delim-col.el --- prettify all columns in a region or rectangle  -*- lexical-binding: t; -*-
 
 ;; Copyright (C) 1999-2019 Free Software Foundation, Inc.
 
diff --git a/test/lisp/delim-col-tests.el b/test/lisp/delim-col-tests.el
new file mode 100644
index 0000000000..6a458b1d4a
--- /dev/null
+++ b/test/lisp/delim-col-tests.el
@@ -0,0 +1,183 @@
+;;; 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
+      (buffer-string)
+      (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
+      (buffer-string)
+      (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))
+      (buffer-string)
+      (should (equal (buffer-string) "<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
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2019-07-08 22:52 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-05-07 20:56 [PATCH] Unit tests and lexical-binding for delim-col.el Stefan Kangas
2019-05-07 22:44 ` Basil L. Contovounesios
2019-05-07 23:03   ` Noam Postavsky
2019-05-08  7:36   ` Stefan Kangas
2019-05-08 12:00     ` Basil L. Contovounesios
2019-05-08 17:20       ` Stefan Kangas
2019-05-08 20:24         ` Stefan Kangas
2019-05-09 13:39           ` Basil L. Contovounesios
2019-05-09 14:38             ` Stefan Monnier
2019-05-11 10:46               ` Stefan Kangas
2019-05-20 14:40                 ` Basil L. Contovounesios
2019-05-30 18:20                   ` Stefan Kangas
2019-06-30 23:40                     ` bug#36453: [PATCH] Delegate to rectangle version in delim-col when appropriate Stefan Kangas
2019-07-08 22:52                       ` Lars Ingebrigtsen

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.