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

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

[nongnu] elpa/evil-numbers 29859e64c0 138/145: Add automated tests, reso


From: ELPA Syncer
Subject: [nongnu] elpa/evil-numbers 29859e64c0 138/145: Add automated tests, resolve #22
Date: Thu, 6 Jan 2022 03:00:25 -0500 (EST)

branch: elpa/evil-numbers
commit 29859e64c0f9e68f5eac5662c56d468678cbac2b
Author: Campbell Barton <ideasman42@gmail.com>
Commit: Campbell Barton <ideasman42@gmail.com>

    Add automated tests, resolve #22
---
 tests/evil-numbers-test-watch.sh |   8 ++
 tests/evil-numbers-test.el       | 268 +++++++++++++++++++++++++++++++++++++++
 tests/evil-numbers-test.sh       |   9 ++
 3 files changed, 285 insertions(+)

diff --git a/tests/evil-numbers-test-watch.sh b/tests/evil-numbers-test-watch.sh
new file mode 100755
index 0000000000..434fa2f948
--- /dev/null
+++ b/tests/evil-numbers-test-watch.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+SCRIPT_PATH="$(dirname "${BASH_SOURCE[0]}")"
+echo $SCRIPT_PATH
+while true; do
+    inotifywait -e close_write "$SCRIPT_PATH/evil-numbers-test.el"
+    tput clear
+    "$SCRIPT_PATH/evil-numbers-test.sh"
+done
diff --git a/tests/evil-numbers-test.el b/tests/evil-numbers-test.el
new file mode 100644
index 0000000000..5a5a999e2e
--- /dev/null
+++ b/tests/evil-numbers-test.el
@@ -0,0 +1,268 @@
+;;; evil-numbers-test.el --- Testing -*- lexical-binding: t -*-
+
+;; This file is not part of GNU Emacs.
+
+;; 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 <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; See: `evil-numbers-test.sh' for launching this script.
+
+;; TODO: tests that handle bugs. #20, #21, #24, #26, #27
+;; Bugs fixed in:
+;; c37a4cf92a9cf8aa9f8bd752ea856a9d1bc6c84c
+
+(require 'ert)
+
+;; ;; Caller ensures this.
+;; (require 'evil-numbers)
+
+;; ---------------------------------------------------------------------------
+;; Global State
+
+;; VIM keys.
+(global-set-key (kbd "C-a") 'evil-numbers/inc-at-pt)
+(global-set-key (kbd "C-x") 'evil-numbers/dec-at-pt)
+
+;; Not VIM keys.
+(global-set-key (kbd "C-M-a") 'evil-numbers/inc-at-pt-incremental)
+(global-set-key (kbd "C-M-x") 'evil-numbers/dec-at-pt-incremental)
+
+
+;; ---------------------------------------------------------------------------
+;; Internal Functions/Macros
+
+(defmacro simulate-input (&rest keys)
+  "Helper macro to simulate input."
+  (declare (indent 1))
+  `(let ((keys-list (list ,@keys)))
+     (dolist (keys keys-list)
+       (execute-kbd-macro keys))))
+
+(defun buffer-reset-text (initial-buffer)
+  (buffer-disable-undo)
+  (simulate-input (kbd "i"))
+  (erase-buffer)
+  ;; Don't move the cursor.
+  (save-excursion (insert initial-buffer))
+  (simulate-input (kbd "<escape>"))
+  (buffer-enable-undo))
+
+(defmacro with-evil-numbers-test (initial-buffer-text &rest body)
+  "Run BODY adding any message call to the MESSAGE-LIST list."
+  (declare (indent 1))
+  ;; Messages make test output noisy (mainly evil mode switching messages).
+  ;; Disable when debugging tests.
+  `(let ((inhibit-message t))
+     (evil-mode 1)
+     (buffer-reset-text ,initial-buffer-text)
+     (prog1 (progn ,@body)
+       (evil-mode 0))))
+
+
+;; ---------------------------------------------------------------------------
+;; Tests
+
+(ert-deftest simple ()
+  "Check a single number increments."
+  (let ((text-expected "2|")
+        (text-initial "1"))
+    (with-evil-numbers-test
+     text-initial
+     ;; Select the line & increment.
+     (simulate-input (kbd "C-a") "a|")
+     (should (equal text-expected (buffer-string))))))
+
+(ert-deftest simple-negative ()
+  "Check a single number increments."
+  (let ((text-expected "-1|")
+        (text-initial "0"))
+    (with-evil-numbers-test
+     text-initial
+     ;; Select the line & increment.
+     (simulate-input (kbd "C-x") "a|")
+     (should (equal text-expected (buffer-string))))))
+
+;; See bug #18.
+(ert-deftest simple-hex ()
+  "Check hexadecimal is detected at all parts."
+  (let ((text-initial " 0xFFF "))
+    (dolist (keys-offset (list "" "l" "ll" "lll" "llll" "lllll"))
+      (with-evil-numbers-test
+       text-initial
+       (simulate-input (kbd keys-offset) (kbd "C-a") "a|")
+       (should (equal " 0x1000| " (buffer-string)))))
+    (with-evil-numbers-test
+     text-initial
+     (simulate-input (kbd "llllll") (kbd "C-a") "a|" (kbd "<escape>"))
+     (should (equal " 0xFFF |" (buffer-string))))))
+
+;; See bug #17.
+(ert-deftest simple-hex-negative ()
+  "Check hexadecimal is detected at all parts."
+  (let ((text-expected " -0x1| ")
+        (text-initial " 0x0 "))
+    (with-evil-numbers-test
+     text-initial
+     (simulate-input (kbd "C-x") "a|" (kbd "<escape>"))
+     (should (equal text-expected (buffer-string))))))
+
+(ert-deftest simple-nop-non-number ()
+  "Do nothing, the value under the cursor is not a number."
+  (let ((text-expected "X|")
+        (text-initial "X"))
+    (with-evil-numbers-test
+     text-initial
+     (simulate-input (kbd "C-a") "a|")
+     (should (equal text-expected (buffer-string))))))
+
+;; See bug #25.
+(ert-deftest simple-nop-non-number-with-newline ()
+  "Do nothing, ensure the newline isn't stepped over."
+  (let ((text-expected "X|\n0")
+        (text-initial "X\n0"))
+    (with-evil-numbers-test
+     text-initial
+     (simulate-input (kbd "<end>") (kbd "C-a") "a|")
+     (should (equal text-expected (buffer-string))))))
+
+(ert-deftest simple-nop-cursor-after-decimal ()
+  "Do nothing, the cursor is after the number so it shouldn't be modified."
+  (let ((text-expected "1 |\n")
+        (text-initial "1 \n"))
+    (with-evil-numbers-test
+     text-initial
+     (simulate-input (kbd "<end>") (kbd "C-a") "a|")
+     (should (equal text-expected (buffer-string))))))
+
+(ert-deftest simple-nop-cursor-after-hex ()
+  "Do nothing, the cursor is after the number so it shouldn't be modified."
+  (let ((text-expected "0xBEEF |\n")
+        (text-initial "0xBEEF \n"))
+    (with-evil-numbers-test
+     text-initial
+     (simulate-input (kbd "<end>") (kbd "C-a") "a|")
+     (should (equal text-expected (buffer-string))))))
+
+(ert-deftest simple-separator-chars ()
+  "Check a single number increments."
+  (let ((text-expected "111_111_111|")
+        (text-initial "111_111_110"))
+    (with-evil-numbers-test
+     text-initial
+     (setq-local evil-numbers-separator-chars "_")
+     (simulate-input (kbd "C-a") "a|")
+     (should (equal text-expected (buffer-string))))))
+
+(ert-deftest simple-separator-chars-disabled ()
+  "Check a single number increments."
+  (let ((text-expected "111|_111_111")
+        (text-initial "110_111_111"))
+    (with-evil-numbers-test
+     text-initial
+     (setq-local evil-numbers-separator-chars nil)
+     (simulate-input (kbd "C-a") "a|")
+     (should (equal text-expected (buffer-string))))))
+
+(ert-deftest selected-block-column-first ()
+  "Block selection test."
+  (let ((text-expected
+         (concat "1| 0 0\n"
+                 "1 0 0\n"
+                 "1 0 0\n"))
+        (text-initial
+         (concat "0 0 0\n"
+                 "0 0 0\n"
+                 "0 0 0\n")))
+    (with-evil-numbers-test
+     text-initial
+     (simulate-input
+      (kbd "C-v") "jj"          ;; Block select the column
+      (kbd "C-a")               ;; Increment.
+      "a|")                     ;; Show cursor location.
+     (should (equal text-expected (buffer-string))))))
+
+(ert-deftest selected-block-column-second ()
+  "Block selection test."
+  (let ((text-expected
+         (concat "0 1| 0\n"
+                 "0 1 0\n"
+                 "0 1 0\n"))
+        (text-initial
+         (concat "0 0 0\n"
+                 "0 0 0\n"
+                 "0 0 0\n")))
+    (with-evil-numbers-test
+     text-initial
+     (simulate-input
+      (kbd "w")
+      (kbd "C-v") "jj"          ;; Block select the column
+      (kbd "C-a")               ;; Increment.
+      "a|")                     ;; Show cursor location.
+     (should (equal text-expected (buffer-string))))))
+
+(ert-deftest selected-block-column-third ()
+  "Block selection test."
+  (let ((text-expected
+         (concat "0 0 1|\n"
+                 "0 0 1\n"
+                 "0 0 1\n"))
+        (text-initial
+         (concat "0 0 0\n"
+                 "0 0 0\n"
+                 "0 0 0\n")))
+    (with-evil-numbers-test
+     text-initial
+     (simulate-input
+      (kbd "ww")
+      (kbd "C-v") "jj"          ;; Block select the column
+      (kbd "C-a")               ;; Increment.
+      "a|")                     ;; Show cursor location.
+     (should (equal text-expected (buffer-string))))))
+
+(ert-deftest selected-block-column-first-incremental ()
+  "Incremental block selection test."
+  (let ((text-expected
+         (concat "1| 0 0\n"
+                 "2 0 0\n"
+                 "3 0 0\n"))
+        (text-initial
+         (concat "0 0 0\n"
+                 "0 0 0\n"
+                 "0 0 0\n")))
+    (with-evil-numbers-test
+     text-initial
+     (simulate-input
+      (kbd "C-v") "jj"          ;; Block select the column
+      (kbd "C-M-a")             ;; Increment.
+      "a|")                     ;; Show cursor location.
+     (should (equal text-expected (buffer-string))))))
+
+(ert-deftest selected-lines-incremental ()
+  "Incremental line selection test."
+  (let ((text-expected
+         (concat "1| 2 3\n"
+                 "4 5 6\n"
+                 "7 8 9\n"))
+        (text-initial
+         (concat "0 0 0\n"
+                 "0 0 0\n"
+                 "0 0 0\n")))
+    (with-evil-numbers-test
+     text-initial
+     (simulate-input
+      (kbd "V") "jj"            ;; Block select the column
+      (kbd "C-M-a")             ;; Increment.
+      "a|")                     ;; Show cursor location.
+     (should (equal text-expected (buffer-string))))))
diff --git a/tests/evil-numbers-test.sh b/tests/evil-numbers-test.sh
new file mode 100755
index 0000000000..9eac61a369
--- /dev/null
+++ b/tests/evil-numbers-test.sh
@@ -0,0 +1,9 @@
+#!/bin/bash
+SCRIPT_PATH="$(dirname "${BASH_SOURCE[0]}")"
+emacs \
+    -batch \
+    --eval "(package-initialize)" \
+    -l ert \
+    -l "$SCRIPT_PATH/../evil-numbers.el" \
+    -l $SCRIPT_PATH/evil-numbers-test.el \
+    -f ert-run-tests-batch-and-exit



reply via email to

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