emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/csv-mode 3fe170f 32/34: Add tests for CSV mode


From: Stefan Monnier
Subject: [elpa] externals/csv-mode 3fe170f 32/34: Add tests for CSV mode
Date: Sun, 29 Nov 2020 18:46:18 -0500 (EST)

branch: externals/csv-mode
commit 3fe170f89763918ef04e15a9d3d457a59af2aa35
Author: Simen Heggestøyl <simenheg@gmail.com>
Commit: Simen Heggestøyl <simenheg@gmail.com>

    Add tests for CSV mode
    
    * packages/csv-mode/csv-mode-tests.el: New file with tests for
    csv-mode.el.
---
 csv-mode-tests.el | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 102 insertions(+)

diff --git a/csv-mode-tests.el b/csv-mode-tests.el
new file mode 100644
index 0000000..b5e0b49
--- /dev/null
+++ b/csv-mode-tests.el
@@ -0,0 +1,102 @@
+;;; csv-mode-tests.el --- Tests for CSV mode         -*- lexical-binding: t; 
-*-
+
+;; Copyright (C) 2020  Free Software Foundation, Inc
+
+;; Author: Simen Heggestøyl <simenheg@gmail.com>
+;; Keywords:
+
+;; This program 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.
+
+;; This program 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 this program.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;
+
+;;; Code:
+
+(require 'ert)
+(require 'csv-mode)
+(eval-when-compile (require 'subr-x))
+
+(ert-deftest csv-mode-tests-end-of-field ()
+  (with-temp-buffer
+    (csv-mode)
+    (insert "aaa,bbb")
+    (goto-char (point-min))
+    (csv-end-of-field)
+    (should (equal (buffer-substring (point-min) (point))
+                   "aaa"))
+    (forward-char)
+    (csv-end-of-field)
+    (should (equal (buffer-substring (point-min) (point))
+                   "aaa,bbb"))))
+
+(ert-deftest csv-mode-tests-end-of-field-with-quotes ()
+  (with-temp-buffer
+    (csv-mode)
+    (insert "aaa,\"b,b\"")
+    (goto-char (point-min))
+    (csv-end-of-field)
+    (should (equal (buffer-substring (point-min) (point))
+                   "aaa"))
+    (forward-char)
+    (csv-end-of-field)
+    (should (equal (buffer-substring (point-min) (point))
+                   "aaa,\"b,b\""))))
+
+(ert-deftest csv-mode-tests-beginning-of-field ()
+  (with-temp-buffer
+    (csv-mode)
+    (insert "aaa,bbb")
+    (csv-beginning-of-field)
+    (should (equal (buffer-substring (point) (point-max))
+                   "bbb"))
+    (backward-char)
+    (csv-beginning-of-field)
+    (should (equal (buffer-substring (point) (point-max))
+                   "aaa,bbb"))))
+
+(ert-deftest csv-mode-tests-beginning-of-field-with-quotes ()
+  (with-temp-buffer
+    (csv-mode)
+    (insert "aaa,\"b,b\"")
+    (csv-beginning-of-field)
+    (should (equal (buffer-substring (point) (point-max))
+                   "\"b,b\""))
+    (backward-char)
+    (csv-beginning-of-field)
+    (should (equal (buffer-substring (point) (point-max))
+                   "aaa,\"b,b\""))))
+
+(defun csv-mode-tests--align-fields (before after)
+  (with-temp-buffer
+    (insert (string-join before "\n"))
+    (csv-align-fields t (point-min) (point-max))
+    (should (equal (buffer-string) (string-join after "\n")))))
+
+(ert-deftest csv-mode-tests-align-fields ()
+  (csv-mode-tests--align-fields
+   '("aaa,bbb,ccc"
+     "1,2,3")
+   '("aaa, bbb, ccc"
+     "1  , 2  , 3")))
+
+(ert-deftest csv-mode-tests-align-fields-with-quotes ()
+  (csv-mode-tests--align-fields
+   '("aaa,\"b,b\",ccc"
+     "1,2,3")
+   '("aaa, \"b,b\", ccc"
+     "1  , 2    , 3")))
+
+(provide 'csv-mode-tests)
+;;; csv-mode-tests.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]