all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Kangas <stefan@marxist.se>
To: emacs-devel@gnu.org
Subject: [PATCH] Unit tests and lexical-binding for delim-col.el
Date: Tue, 7 May 2019 22:56:00 +0200	[thread overview]
Message-ID: <CADwFkmmydG_3f4qMrBuzFwZ39UjM+9OFVAbttP+O=H3Pr3S9OQ@mail.gmail.com> (raw)


[-- 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


             reply	other threads:[~2019-05-07 20:56 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-07 20:56 Stefan Kangas [this message]
2019-05-07 22:44 ` [PATCH] Unit tests and lexical-binding for delim-col.el 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CADwFkmmydG_3f4qMrBuzFwZ39UjM+9OFVAbttP+O=H3Pr3S9OQ@mail.gmail.com' \
    --to=stefan@marxist.se \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.