branch: elpa/evil-numbers commit 434298ed9a62839f75bf9d624aa86405a8703646 Author: Campbell Barton <ideasma...@gmail.com> Commit: Campbell Barton <ideasma...@gmail.com>
Auto format using elisp-autofmt Avoids the need for manual formatting. --- .elisp-autofmt | 0 evil-numbers.el | 259 +++++++++++++++++++++-------------- tests/evil-numbers-tests.el | 320 +++++++++++++++++++++++--------------------- 3 files changed, 327 insertions(+), 252 deletions(-) diff --git a/.elisp-autofmt b/.elisp-autofmt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/evil-numbers.el b/evil-numbers.el index 6a5fc3e743..fa897f073c 100644 --- a/evil-numbers.el +++ b/evil-numbers.el @@ -80,7 +80,9 @@ :group 'convenience) (define-obsolete-variable-alias - 'evil-numbers/padDefault 'evil-numbers-pad-default "evil-numbers v0.6") + 'evil-numbers/padDefault + 'evil-numbers-pad-default + "evil-numbers v0.6") (defcustom evil-numbers-pad-default nil "Whether numbers are padded by default." @@ -209,14 +211,18 @@ representation of NUMBER is smaller." (defun evil-numbers--format (num width base) "Format NUM with at least WIDTH space in BASE." (cond - ((= base 2) (evil-numbers--format-binary num width)) - ((= base 8) (format (format "%%0%do" width) num)) - ((= base 16) (format (format "%%0%dX" width) num)) - ((= base 10) (format (format "%%0%dd" width) num)) - (t ""))) - -(defun evil-numbers--skip-chars-impl - (ch-skip ch-sep-optional dir ch-num limit) + ((= base 2) + (evil-numbers--format-binary num width)) + ((= base 8) + (format (format "%%0%do" width) num)) + ((= base 16) + (format (format "%%0%dX" width) num)) + ((= base 10) + (format (format "%%0%dd" width) num)) + (t + ""))) + +(defun evil-numbers--skip-chars-impl (ch-skip ch-sep-optional dir ch-num limit) "Wrapper for `skip-chars-forward' and `skip-chars-backward'. CH-SKIP: Characters to skip. @@ -225,17 +231,20 @@ DIR: Direction to step in (1 -1). CH-NUM: Number of characters to step. LIMIT: Point which will not be stepped past." (let* ((is-forward (< 0 dir)) - (skip-chars-fn (if is-forward - #'skip-chars-forward - #'skip-chars-backward)) - (clamp-fn (if is-forward - #'min - #'max)) + (skip-chars-fn + (if is-forward + #'skip-chars-forward + #'skip-chars-backward)) + (clamp-fn + (if is-forward + #'min + #'max)) (skipped - (abs (funcall - skip-chars-fn ch-skip - ;; Limit. - (funcall clamp-fn (+ (point) (* ch-num dir)) limit))))) + (abs + (funcall skip-chars-fn + ch-skip + ;; Limit. + (funcall clamp-fn (+ (point) (* ch-num dir)) limit))))) ;; Step over single separators, as long as there is a number after them. ;; Allow '100,123' and '16_777_216' to be handled as single numbers. @@ -245,16 +254,24 @@ LIMIT: Point which will not be stepped past." (setq ch-num (- ch-num skipped)) (while (and (not (zerop ch-num)) (save-excursion - (and (eq 1 (evil-numbers--skip-chars-impl - ch-sep-optional nil - dir 1 limit)) + (and (eq + 1 + (evil-numbers--skip-chars-impl + ch-sep-optional + nil + dir + 1 + limit)) (progn ;; Note counted towards 'skipped' ;; as this character is to be ignored entirely. (setq skipped-next (evil-numbers--skip-chars-impl - ch-skip nil - dir ch-num limit)) + ch-skip + nil + dir + ch-num + limit)) (unless (zerop skipped-next) (setq point-next (point)) ;; Found (apply `point-new'). @@ -290,7 +307,9 @@ Each item in MATCH-CHARS is a cons pair. (match-list (list))) ;; Sanity check. - (when (if is-forward (> (point) limit) (< (point) limit)) + (when (if is-forward + (> (point) limit) + (< (point) limit)) (error "Limit is on wrong side of point (internal error)")) (unless is-forward @@ -305,14 +324,22 @@ Each item in MATCH-CHARS is a cons pair. ((integerp ch-num) (let ((skipped (evil-numbers--skip-chars-impl - ch-skip ch-sep-optional dir ch-num limit))) + ch-skip + ch-sep-optional + dir + ch-num + limit))) (when do-check (unless (eq skipped ch-num) (throw 'result nil))))) ((eq ch-num '+) (let ((skipped (evil-numbers--skip-chars-impl - ch-skip ch-sep-optional dir most-positive-fixnum limit))) + ch-skip + ch-sep-optional + dir + most-positive-fixnum + limit))) (when do-check (unless (>= skipped 1) (throw 'result nil))))) @@ -321,10 +348,13 @@ Each item in MATCH-CHARS is a cons pair. ;; Skip these characters if they exist. ((eq ch-num '*) (evil-numbers--skip-chars-impl - ch-skip ch-sep-optional dir most-positive-fixnum limit)) + ch-skip + ch-sep-optional + dir + most-positive-fixnum + limit)) ((eq ch-num '\?) - (evil-numbers--skip-chars-impl - ch-skip ch-sep-optional dir 1 limit)) + (evil-numbers--skip-chars-impl ch-skip ch-sep-optional dir 1 limit)) (t (error (format "Unknown type %S (internal error)" ch-skip)))) @@ -352,14 +382,14 @@ Each item in MATCH-CHARS is a cons pair. (defun evil-numbers--translate-with-alist (alist string) "Translate every symbol in STRING using ALIST." - (funcall - (if (stringp string) #'concat #'identity) - (mapcar (lambda (c) (cdr (assoc c alist))) string))) + (funcall (if (stringp string) + #'concat + #'identity) + (mapcar (lambda (c) (cdr (assoc c alist))) string))) (defun evil-numbers--encode-super (x) "Convert X string into super-script." - (evil-numbers--translate-with-alist - evil-numbers--superscript-alist x)) + (evil-numbers--translate-with-alist evil-numbers--superscript-alist x)) (defun evil-numbers--decode-super (x) "Convert X string from super-script into regular characters." (evil-numbers--translate-with-alist @@ -367,8 +397,7 @@ Each item in MATCH-CHARS is a cons pair. (defun evil-numbers--encode-sub (x) "Convert X string into sub-script." - (evil-numbers--translate-with-alist - evil-numbers--subscript-alist x)) + (evil-numbers--translate-with-alist evil-numbers--subscript-alist x)) (defun evil-numbers--decode-sub (x) "Convert X string from sub-script into regular characters." (evil-numbers--translate-with-alist @@ -380,14 +409,10 @@ Each item in MATCH-CHARS is a cons pair. (defun evil-numbers--inc-at-pt-impl-with-match-chars (match-chars - sign-group num-group - base - beg end - padded - do-case - range-check-fn - number-xform-fn - decode-fn encode-fn) + ;; Numeric & other options. + sign-group num-group base beg end padded do-case + ;; Callbacks. + range-check-fn number-xform-fn decode-fn encode-fn) "Perform the increment/decrement on the current line. For MATCH-CHARS docs see `evil-numbers--match-from-skip-chars'. @@ -403,26 +428,30 @@ A non nil result causes this function to return nil. When all characters are found in sequence, evaluate the number in BASE, replacing it by the result of NUMBER-XFORM-FN and return non-nil." (save-match-data - (when (and - (save-excursion - ;; Skip backwards (as needed), there may be no - ;; characters to skip back, so don't check the result. - (evil-numbers--match-from-skip-chars match-chars -1 beg nil nil) - ;; Skip forwards from the beginning, setting match data. - (evil-numbers--match-from-skip-chars match-chars 1 end t t)) - - ;; Either there is no range checking or the range must - ;; be accepted by the caller. - (or (null range-check-fn) - (funcall range-check-fn (match-beginning 0) (match-end 0)))) + (when (and (save-excursion + ;; Skip backwards (as needed), there may be no + ;; characters to skip back, so don't check the result. + (evil-numbers--match-from-skip-chars + match-chars + -1 + beg + nil + nil) + ;; Skip forwards from the beginning, setting match data. + (evil-numbers--match-from-skip-chars match-chars 1 end t t)) + + ;; Either there is no range checking or the range must + ;; be accepted by the caller. + (or (null range-check-fn) + (funcall range-check-fn (match-beginning 0) (match-end 0)))) (goto-char (match-end num-group)) - (let* ((sep-char - (nth 2 (nth (1- num-group) match-chars))) + (let* ((sep-char (nth 2 (nth (1- num-group) match-chars))) (str-prev (funcall decode-fn - (concat (match-string sign-group) - (match-string num-group)))) + (concat + (match-string sign-group) + (match-string num-group)))) (str-prev-strip (if sep-char @@ -435,8 +464,7 @@ replacing it by the result of NUMBER-XFORM-FN and return non-nil." (evil-numbers--format (abs num-next) (if padded - (- (match-end num-group) - (match-beginning num-group)) + (- (match-end num-group) (match-beginning num-group)) 1) base))) @@ -455,7 +483,11 @@ replacing it by the result of NUMBER-XFORM-FN and return non-nil." ;; This is a relatively expensive operation, ;; only apply separators back if any were found to begin with. (unless (string-equal str-prev str-prev-strip) - (setq str-next (evil-numbers--strip-chars-apply str-prev str-next sep-char)))) + (setq str-next + (evil-numbers--strip-chars-apply + str-prev + str-next + sep-char)))) ;; Replace the sign (as needed). (cond @@ -471,7 +503,8 @@ replacing it by the result of NUMBER-XFORM-FN and return non-nil." t))) -(defun evil-numbers--inc-at-pt-impl (beg end padded range-check-fn number-xform-fn) +(defun evil-numbers--inc-at-pt-impl + (beg end padded range-check-fn number-xform-fn) "Increment the number at the current POINT by AMOUNT limited by BEG and END. Keep padding when PADDED is non-nil. @@ -485,8 +518,11 @@ Return non-nil on success, leaving the point at the end of the number." ;; 0[bB][01]+, e.g. 0b101 or 0B0 (evil-numbers--inc-at-pt-impl-with-match-chars `(("+-" \?) ("0" 1) ("bB" 1) ("01" + ,evil-numbers-separator-chars)) - 1 4 ;; Sign & number groups. - 2 beg end padded nil range-check-fn number-xform-fn + ;; Sign, number groups & base. + 1 4 2 + ;; Other arguments. + beg end padded nil range-check-fn number-xform-fn + ;; Decode & encode callbacks. #'identity #'identity) ;; Find octal literals: @@ -494,41 +530,57 @@ Return non-nil on success, leaving the point at the end of the number." (evil-numbers--inc-at-pt-impl-with-match-chars `(("+-" \?) ("0" 1) ("oO" 1) ("0-7" + ,evil-numbers-separator-chars)) - 1 4 ;; Sign & number groups. - 8 beg end padded nil range-check-fn number-xform-fn + ;; Sign & number groups. + 1 4 8 + ;; Other arguments. + beg end padded nil range-check-fn number-xform-fn + ;; Decode & encode callbacks. #'identity #'identity) ;; Find hex literals: ;; 0[xX][0-9a-fA-F]+, e.g. 0xBEEF or 0Xcafe (evil-numbers--inc-at-pt-impl-with-match-chars `(("+-" \?) ("0" 1) ("xX" 1) ("[:xdigit:]" + ,evil-numbers-separator-chars)) - 1 4 ;; Sign & number groups. + ;; Sign, number groups & base. + 1 4 + ;; Base and other arguments. 16 beg end padded t range-check-fn number-xform-fn + ;; Decode & encode callbacks. #'identity #'identity) ;; Find decimal literals: ;; [0-9]+, e.g. 42 or 23. (evil-numbers--inc-at-pt-impl-with-match-chars `(("+-" \?) ("0123456789" + ,evil-numbers-separator-chars)) - 1 2 ;; Sign & number groups. - 10 beg end padded nil range-check-fn number-xform-fn + ;; Sign, number groups & base. + 1 2 10 + ;; Other arguments. + beg end padded nil range-check-fn number-xform-fn + ;; Decode & encode callbacks. #'identity #'identity) ;; Find decimal literals (super-script). (evil-numbers--inc-at-pt-impl-with-match-chars `(("⁺⁻" \?) (,evil-numbers--chars-superscript + nil)) - 1 2 ;; Sign & number groups. - 10 beg end padded nil range-check-fn number-xform-fn + ;; Sign, number groups & base. + 1 2 10 + ;; Other arguments. + beg end padded nil range-check-fn number-xform-fn + ;; Decode & encode callbacks. #'evil-numbers--decode-super #'evil-numbers--encode-super) ;; Find decimal literals (sub-script). (evil-numbers--inc-at-pt-impl-with-match-chars `(("₊₋" \?) (,evil-numbers--chars-subscript + nil)) - 1 2 ;; Sign & number groups. - 10 beg end padded nil range-check-fn number-xform-fn + ;; Sign, number groups & base. + 1 2 10 + ;; Other arguments. + beg end padded nil range-check-fn number-xform-fn + ;; Decode & encode callbacks. #'evil-numbers--decode-sub #'evil-numbers--encode-sub))) -(defun evil-numbers--inc-at-pt-impl-with-search (amount beg end padded range-check-fn) +(defun evil-numbers--inc-at-pt-impl-with-search + (amount beg end padded range-check-fn) "Increment the number at the current POINT by AMOUNT limited by BEG and END. Keep padding when PADDED is non-nil. @@ -561,13 +613,13 @@ Return non-nil on success, leaving the point at the end of the number." (setq found t))) ;; Search failed, exit the loop. - (re-search-forward - (concat "[" - "[:xdigit:]" - evil-numbers--chars-superscript - evil-numbers--chars-subscript - "]") - end t)))) + (re-search-forward (concat + "[" + "[:xdigit:]" + evil-numbers--chars-superscript + evil-numbers--chars-subscript + "]") + end t)))) found)) @@ -596,31 +648,34 @@ PADDED is whether numbers should be padded (e.g. 10 -> 09). Numbers with a leading zero are always padded. Signs are preserved when padding is enabled, for example: increasing a negative number to a positive will result in a number with a + sign." - :motion nil + :motion + nil (interactive "*<c><R>") (setq amount (or amount 1)) - (setq padded (if (consp padded) - (car padded) - (funcall (if padded #'not #'identity) - evil-numbers-pad-default))) + (setq padded + (if (consp padded) + (car padded) + (funcall (if padded + #'not + #'identity) + evil-numbers-pad-default))) (cond ;; Handle selection (block or line). ;; Run this function in a loop (falling through to the `t' case). ((and beg end type) (let ((count 1)) (save-excursion - (funcall - (if (eq type 'block) - (lambda (f) (evil-apply-on-block f beg end nil)) - (lambda (f) (funcall f beg end))) - (lambda (beg end) - (evil-with-restriction beg end - (goto-char beg) - (while (evil-numbers--inc-at-pt-impl-with-search - (* amount count) (point) (point-max) padded nil) - (when incremental - (setq count (+ count 1)))))))))) + (funcall (if (eq type 'block) + (lambda (f) (evil-apply-on-block f beg end nil)) + (lambda (f) (funcall f beg end))) + (lambda (beg end) + (evil-with-restriction + beg end (goto-char beg) + (while (evil-numbers--inc-at-pt-impl-with-search + (* amount count) (point) (point-max) padded nil) + (when incremental + (setq count (+ count 1)))))))))) ;; Handle the simple case, either the cursor is over a number, ;; or a number exists between the cursor and `end-of-line'. @@ -663,6 +718,7 @@ negative number to a positive will result in a number with a + sign." If a region is active, decrement all the numbers at a point by AMOUNT." :motion nil + (interactive "*<c><R>") (evil-numbers/inc-at-pt (- (or amount 1)) beg end type incremental padded)) @@ -676,6 +732,7 @@ n is the index of the number among the numbers in the region, starting at 1. That is increment the first number by AMOUNT, the second by 2*AMOUNT, and so on." :motion nil + (interactive "*<c><R>") (evil-numbers/inc-at-pt amount beg end type 'incremental padded)) @@ -684,6 +741,7 @@ and so on." (amount beg end type padded) "Like `evil-numbers/inc-at-pt-incremental' but with negated argument AMOUNT." :motion nil + (interactive "*<c><R>") (evil-numbers/inc-at-pt (- (or amount 1)) beg end type 'incremental padded)) @@ -691,6 +749,7 @@ and so on." ;; Local Variables: ;; fill-column: 80 +;; elisp-autofmt-load-packages-local: ("evil-macros") ;; End: ;;; evil-numbers.el ends here diff --git a/tests/evil-numbers-tests.el b/tests/evil-numbers-tests.el index f33dbcd451..2a20e0be60 100644 --- a/tests/evil-numbers-tests.el +++ b/tests/evil-numbers-tests.el @@ -25,7 +25,8 @@ (require 'ert) -(setq evil-numbers-tests-basedir (concat (file-name-directory load-file-name) "..")) +(setq evil-numbers-tests-basedir + (concat (file-name-directory load-file-name) "..")) (add-to-list 'load-path evil-numbers-tests-basedir) (require 'evil-numbers) @@ -48,7 +49,7 @@ (defmacro simulate-input (&rest keys) "Helper macro to simulate input using KEYS." - (declare (indent 1)) + (declare (indent 0)) `(let ((keys-list (list ,@keys))) (dolist (keys keys-list) (execute-kbd-macro keys)))) @@ -56,11 +57,13 @@ (defun buffer-reset-text (initial-buffer-text) "Use INITIAL-BUFFER-TEXT to initialize the buffer with text." (buffer-disable-undo) - (simulate-input (kbd "i")) + (simulate-input + (kbd "i")) (erase-buffer) ;; Don't move the cursor. (save-excursion (insert initial-buffer-text)) - (simulate-input (kbd "<escape>")) + (simulate-input + (kbd "<escape>")) (buffer-enable-undo)) (defmacro with-evil-numbers-test (initial-buffer-text &rest body) @@ -72,7 +75,8 @@ Setting the buffers text to INITIAL-BUFFER-TEXT." `(let ((inhibit-message t)) (evil-mode 1) (buffer-reset-text ,initial-buffer-text) - (prog1 (progn ,@body) + (prog1 (progn + ,@body) (evil-mode 0)))) @@ -83,21 +87,23 @@ Setting the buffers text to INITIAL-BUFFER-TEXT." "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)))))) + (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)))))) + (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 () @@ -106,16 +112,21 @@ Setting the buffers text to INITIAL-BUFFER-TEXT." ;; Test incrementing at different offsets, ;; this ensures scanning the hexadecimal is handled properly. (dotimes (i 6) - (with-evil-numbers-test - text-initial - (dotimes (_ i) - (simulate-input "l")) - (simulate-input (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)))))) + (with-evil-numbers-test text-initial + (dotimes (_ i) + (simulate-input + "l")) + (simulate-input + (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-positive-to-negative () @@ -123,81 +134,99 @@ Setting the buffers text to INITIAL-BUFFER-TEXT." (let ((text-expected " -0x1| ") (text-initial " 0x1 ")) (dotimes (i 4) - (with-evil-numbers-test - text-initial - (dotimes (_ i) - (simulate-input "l")) - (simulate-input (kbd "C-x") (kbd "C-x")) - (simulate-input "a|" (kbd "<escape>")) - (should (equal text-expected (buffer-string))))))) + (with-evil-numbers-test text-initial + (dotimes (_ i) + (simulate-input + "l")) + (simulate-input + (kbd "C-x") + (kbd "C-x")) + (simulate-input + "a|" + (kbd "<escape>")) + (should (equal text-expected (buffer-string))))))) (ert-deftest simple-hex-negative-to-positive () "Change negative hex to positive." (let ((text-expected " 0x1| ") (text-initial " -0x1 ")) (dotimes (i 5) - (with-evil-numbers-test - text-initial - (dotimes (_ i) - (simulate-input "l")) - (simulate-input (kbd "C-a") (kbd "C-a")) - (simulate-input "a|" (kbd "<escape>")) - (should (equal text-expected (buffer-string))))))) + (with-evil-numbers-test text-initial + (dotimes (_ i) + (simulate-input + "l")) + (simulate-input + (kbd "C-a") + (kbd "C-a")) + (simulate-input + "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)))))) + (with-evil-numbers-test text-initial + (simulate-input + (kbd "C-a") + "a|") + (should (equal text-expected (buffer-string)))))) (ert-deftest simple-nop-non-number-signed () "Do nothing, the value under the cursor is not a number, but it has a sign." (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)))))) + (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-before () "Do nothing, ensure the newline isn't stepped over." (let ((text-expected "|\n0") (text-initial "\n0")) - (with-evil-numbers-test - text-initial - (simulate-input (kbd "<end>") (kbd "C-a") "a|") - (should (equal text-expected (buffer-string)))))) + (with-evil-numbers-test text-initial + (simulate-input + (kbd "<end>") + (kbd "C-a") + "a|") + (should (equal text-expected (buffer-string)))))) (ert-deftest simple-nop-non-number-with-newline-after () "Do nothing, ensure the newline isn't stepped over." (let ((text-expected "0\n|") (text-initial "0\n")) - (with-evil-numbers-test - text-initial - (simulate-input "j" (kbd "C-a") "a|") - (should (equal text-expected (buffer-string)))))) + (with-evil-numbers-test text-initial + (simulate-input + "j" + (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)))))) + (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)))))) + (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." @@ -206,115 +235,102 @@ Setting the buffers text to INITIAL-BUFFER-TEXT." ;; Test at different offsets to ensure ;; there are no bugs similar to #18 occurring. (dotimes (i 8) - (with-evil-numbers-test - text-initial - (setq-local evil-numbers-separator-chars "_") - (dotimes (_ i) - (simulate-input "l")) - (simulate-input (kbd "C-a") "a|") - (should (equal text-expected (buffer-string))))))) + (with-evil-numbers-test text-initial + (setq-local evil-numbers-separator-chars "_") + (dotimes (_ i) + (simulate-input + "l")) + (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 "2|_11_111") (text-initial "1_11_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)))))) + (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)))))) + (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 + ;; Block select the column + (kbd "C-v") + "jj" + ;; Increment. + (kbd "C-a") + ;; Show cursor location. + "a|") + (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)))))) + (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") + ;; Block select the column + (kbd "C-v") + "jj" + ;; Increment. + (kbd "C-a") + ;; Show cursor location. + "a|") + (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)))))) + (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") + ;; Block select the column. + (kbd "C-v") + "jj" + ;; Increment. + (kbd "C-a") + ;; Show cursor location. + "a|") + (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)))))) + (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 + ;; Block select the column + (kbd "C-v") + "jj" + ;; Increment. + (kbd "C-M-a") + "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)))))) + (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 + ;; Block select the column + (kbd "V") + "jj" + ;; Increment. + (kbd "C-M-a") + ;; Show cursor location. + "a|") + (should (equal text-expected (buffer-string)))))) (provide 'evil-numbers-tests) ;;; evil-numbers-tests.el ends here