branch: externals/hyperbole commit 1fe4924b1cb6c95acf38ce2795ab7bd3b0a6cb32 Merge: 5d94882558 128ef4aa26 Author: Robert Weiner <r...@gnu.org> Commit: GitHub <nore...@github.com>
Merge pull request #361 from rswgnu/rsw Add full set of ibut:operate tests --- ChangeLog | 13 ++ hbut.el | 18 +- hypb-ert.el | 15 +- test/demo-tests.el | 4 +- test/hbut-tests.el | 474 ++++++++++++++++++++++++++++++++++++++++------------- 5 files changed, 395 insertions(+), 129 deletions(-) diff --git a/ChangeLog b/ChangeLog index a230e0e6e0..d9057b700c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2023-07-09 Bob Weiner <r...@gnu.org> + +* hypb-ert.el (hypb-ert-*): Change all calls of 'ert' to disable ert's messages + so that any test's message is displayed after an hypb-ert test case run. + +* hbut.el (ibut:operate): Update doc of each state. + +* test/hbut-tests.el: Finish adding all ibut:operate tests; still need to update + ibut:operate to conform to all tests. + +* test/demo-tests.el (demo-annotated-reference-test): Fix to always search from + buffer start. + 2023-07-08 Bob Weiner <r...@gnu.org> * test/demo-tests.el (demo-implicit-button-action-button-boolean-function-call-test): diff --git a/hbut.el b/hbut.el index 10606694ec..ec56853ba0 100644 --- a/hbut.el +++ b/hbut.el @@ -3,7 +3,7 @@ ;; Author: Bob Weiner ;; ;; Orig-Date: 18-Sep-91 at 02:57:09 -;; Last-Mod: 8-Jul-23 at 16:02:16 by Bob Weiner +;; Last-Mod: 9-Jul-23 at 02:09:54 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -2188,18 +2188,18 @@ Summary of operations based on inputs (name arg comes from \\='hbut:current attr | # | name | new-name | region | edit | operation | |----+------+----------+--------+------+-----------------------------------------------| | 1 | nil | nil | nil | nil | create: unnamed ibut from hbut:current attrs | -| 2 | nil | new-name | nil | nil | create: new-name named ibut | -| 3 | name | nil | nil | nil | create: aname named ibut | +| 2 | nil | new-name | nil | nil | ERROR: create can't rename without edit flag | +| 3 | name | nil | nil | nil | create: ibut with name | | 4 | name | new-name | nil | nil | ERROR: create can't have name and new-name | | 5 | name | new-name | region | nil | ERROR: create can't have name and new-name | -| 6 | name | nil | region | nil | create: aname named ibut (skip region) | +| 6 | name | nil | region | nil | create: ibut with name (ignore region) | | 7 | nil | nil | region | nil | create: region named ibut | -| 8 | nil | new-name | region | nil | create: new-name named ibut (skip region) | +| 8 | nil | new-name | region | nil | create: ibut with new-name (ignore region) | |----+------+----------+--------+------+-----------------------------------------------| -| 9 | nil | nil | nil | t | mod: unnamed ibut from hbut:current attrs | -| 10 | nil | new-name | nil | t | mod: add new-name to lbl-key ibut at point | -| 11 | name | nil | nil | t | mod: aname named ibut from hbut:current attrs | -| 12 | name | new-name | nil | t | mod: rename aname to new-name | +| 9 | nil | nil | nil | t | mod: remove any name from ibut | +| 10 | nil | new-name | nil | t | mod: set ibut's name to new-name | +| 11 | name | nil | nil | t | mod: name of ibut from hbut:current attrs | +| 12 | name | new-name | nil | t | mod: rename ibut with name to new-name | | 13 | name | new-name | region | t | ERROR: Can't use region to mod existing ibut | | 14 | name | nil | region | t | ERROR: Can't use region to mod existing ibut | | 15 | nil | nil | region | t | ERROR: Can't use region to mod existing ibut | diff --git a/hypb-ert.el b/hypb-ert.el index 3eccbff8fe..d3c0fb58a4 100644 --- a/hypb-ert.el +++ b/hypb-ert.el @@ -3,7 +3,7 @@ ;; Author: Mats Lidell <ma...@gnu.org> and Bob Weiner <r...@gnu.org> ;; ;; Orig-Date: 31-Mar-21 at 21:11:00 -;; Last-Mod: 25-Jun-23 at 23:20:29 by Bob Weiner +;; Last-Mod: 8-Jul-23 at 22:22:22 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -36,13 +36,13 @@ (hypb-ert-require-libraries) (let ((test-sym (intern-soft test-name))) (if test-sym - (ert test-sym) + (ert test-sym nil #'hypb-ert-message-function) (user-error "Invalid test name: %s" test-name)))) (defun hypb-ert-run-tests (test-selector) "Run the specified TEST-SELECTOR defined ert test." (hypb-ert-require-libraries) - (ert (regexp-quote test-selector))) + (ert (regexp-quote test-selector) nil #'hypb-ert-message-function)) (defun hypb-ert-get-require-symbols () "Return the list of test Lisp library symbols to require." @@ -60,7 +60,7 @@ "Run every ert test." (interactive) (hypb-ert-require-libraries) - (ert t)) + (ert t nil #'hypb-ert-message-function)) ;; The following expression is true only when an ert-deftest has been ;; instrumented by edebug: @@ -94,7 +94,7 @@ test when it is run." (when (and test-sym (ert-test-boundp test-sym)) (when (and buffer-file-name (string-prefix-p hyperb:dir buffer-file-name)) (hypb-ert-require-libraries)) - (ert test-sym)))) + (ert test-sym nil #'hypb-ert-message-function)))) (defib hyperbole-run-test-definition () "If on the name in the first line of an ert test def, eval and run the test. @@ -109,5 +109,10 @@ With an Assist Key press instead, edebug the test and step through it." (when test-name (hypb-ert-run-test-at-definition test-name t)))) +(defun hypb-ert-message-function (_msg-pat &rest _args) + "Ignore messages ert outputs so can display messages from tests run." + ;; (identity (apply #'format msg-pat args))))))) + nil) + (provide 'hypb-ert) ;;; hypb-ert.el ends here diff --git a/test/demo-tests.el b/test/demo-tests.el index 7278704098..8151ad7e27 100644 --- a/test/demo-tests.el +++ b/test/demo-tests.el @@ -3,7 +3,7 @@ ;; Author: Mats Lidell <ma...@gnu.org> ;; ;; Orig-Date: 30-Jan-21 at 12:00:00 -;; Last-Mod: 8-Jul-23 at 14:16:51 by Bob Weiner +;; Last-Mod: 9-Jul-23 at 01:21:53 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -397,6 +397,8 @@ (unwind-protect (progn (hypb:display-file-with-logo "DEMO") + (widen) + (goto-char (point-min)) (re-search-forward "\\[FSF 19\\]") (backward-char 1) (action-key) diff --git a/test/hbut-tests.el b/test/hbut-tests.el index 8f95038b07..06b655b2e1 100644 --- a/test/hbut-tests.el +++ b/test/hbut-tests.el @@ -3,7 +3,7 @@ ;; Author: Mats Lidell <ma...@gnu.org> ;; ;; Orig-Date: 30-may-21 at 09:33:00 -;; Last-Mod: 5-Jul-23 at 00:29:02 by Bob Weiner +;; Last-Mod: 9-Jul-23 at 02:09:26 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -29,7 +29,7 @@ "Check that TMP matches either of \"/tmp\" or \"/private/tmp\". Needed since hyperbole expands all links to absolute paths and /tmp can be a symbolic link." - (should (and (stringp tmp) (string-match-p "\\`\"?\\(/\\|./\\|/private/\\)tmp\"?\\'" tmp) t))) + (should (and (stringp tmp) (string-match-p "\"?\\(/\\|./\\|/private/\\)tmp\"?\\'" tmp) t))) (ert-deftest ebut-program-link-to-directory () "Programatically create ebut with link-to-directory." @@ -340,130 +340,376 @@ Needed since hyperbole expands all links to absolute paths and ;; ibut:operate tests (ert-deftest hbut-tests--ibut-operate--none () - "Create unnamed ibut. - |------+----------+--------+-----------+-----------------------------------------------| - | name | new-name | region | edit-flag | operation | - |------+----------+--------+-----------+-----------------------------------------------| - | nil | nil | nil | nil | create: unnamed ibut from hbut:current attrs | - |------+----------+--------+-----------+-----------------------------------------------|" + "Test creation of an unnamed ibut. + |----+------+----------+--------+------+-----------------------------------------------| + | # | name | new-name | region | edit | operation | + |----+------+----------+--------+------+-----------------------------------------------| + | 1 | nil | nil | nil | nil | create: unnamed ibut from hbut:current attrs | + |----+------+----------+--------+------+-----------------------------------------------|" (with-temp-buffer - (insert "/tmp") - (goto-char 2) - (should (hbut:at-p)) - (should (eq (hattr:get 'hbut:current 'actype) 'actypes::link-to-file)) - (hbut-tests:should-match-tmp-folder (buffer-substring-no-properties (point-min) (point-max))) - (erase-buffer) - (should-not (ibut:operate)) - (should (hbut:at-p)) - (should (eq (hattr:get 'hbut:current 'actype) 'actypes::link-to-file)) - (hbut-tests:should-match-tmp-folder (buffer-substring-no-properties (point-min) (point-max))))) - -(ert-deftest hbut-tests--ibut-operate--aname () - "Create aname ibut." + ;; Create in-buffer and in-memory ibut + (let (buf-str) + (insert "/tmp") + (goto-char 2) + (should (hbut:at-p)) + (should (eq (hattr:get 'hbut:current 'actype) 'actypes::link-to-file)) + (hbut-tests:should-match-tmp-folder (buffer-substring-no-properties (point-min) (point-max))) + ;; Test that ibut:operate properly creates an in-buffer ibut from its in-memory form + (erase-buffer) + (ibut:operate) + (setq buf-str (buffer-substring-no-properties (point-min) (point-max))) + (message buf-str) + (should (hbut:at-p)) + (should (eq (hattr:get 'hbut:current 'actype) 'actypes::link-to-file)) + (hbut-tests:should-match-tmp-folder (buffer-substring-no-properties (point-min) (point-max)))))) + +(ert-deftest hbut-tests--ibut-operate--rename () + "Test that unnamed ibut rename to `new-name' fails when `edit-flag' is nil. + |----+------+----------+--------+------+-----------------------------------------------| + | # | name | new-name | region | edit | operation | + |----+------+----------+--------+------+-----------------------------------------------| + | 2 | nil | new-name | nil | nil | ERROR: Can't rename without edit flag | + |----+------+----------+--------+------+-----------------------------------------------|" (with-temp-buffer - (insert "<[aname]> - /tmp") - (goto-char 2) - (should (hbut:at-p)) - (should (eq (hattr:get 'hbut:current 'actype) 'actypes::link-to-file)) - (hbut-tests:should-match-tmp-folder (buffer-substring-no-properties (point-min) (point-max))) - (erase-buffer) - ( - (hattr:set 'hbut:current 'name "aname") - (hattr:set 'hbut:current 'name "") - (should-not (ibut:operate)) - (should (hbut:at-p)) - (should (eq (hattr:get 'hbut:current 'actype) 'actypes::link-to-file)) - (should (string= "<[aname]> - /tmp<[aname]> - \"/tmp\"" - (buffer-substring-no-properties (point-min) (point-max))))))) - -(ert-deftest hbut-tests--ibut-operate--aname-region-skip-region () - "Create aname ibut and ignore region." + ;; Create in-buffer and in-memory ibut + (let ((ibut-str "<[name]> - /tmp") + buf-str) + (insert ibut-str) + (goto-char 2) + (should (hbut:at-p)) + (should (eq (hattr:get 'hbut:current 'actype) 'actypes::link-to-file)) + (hbut-tests:should-match-tmp-folder (buffer-substring-no-properties (point-min) (point-max))) + ;; Test that ibut:operate properly creates an in-buffer ibut from its in-memory form + (erase-buffer) + (should-error (ibut:operate "new-name")) + (setq buf-str (buffer-substring-no-properties (point-min) (point-max))) + (message buf-str)))) + +(ert-deftest hbut-tests--ibut-operate--name () + "Test that ibut get created with `name' from button attributes. + |----+------+----------+--------+------+-----------------------------------------------| + | # | name | new-name | region | edit | operation | + |----+------+----------+--------+------+-----------------------------------------------| + | 3 | name | nil | nil | nil | create: ibut with name | + |----+------+----------+--------+------+-----------------------------------------------|" (with-temp-buffer - (insert "<[aname]> - /tmp") - (goto-char 2) - (should (hbut:at-p)) - (end-of-buffer) - (insert "\n") - (set-mark (point)) - (insert "abcd") - (should (region-active-p)) - (should-not (ibut:operate)) - ;; Inserted just before region which is kept - (should (string= "<[aname]> - /tmp\n<[aname]> - \"/tmp\"abcd" - (buffer-substring-no-properties (point-min) (point-max)))))) + ;; Create in-buffer and in-memory ibut + (let ((ibut-str "<[name]> - /tmp") + buf-str) + (insert ibut-str) + (goto-char 2) + (should (hbut:at-p)) + (should (equal "name" (hattr:get 'hbut:current 'name))) + ;; Test that ibut:operate properly creates an in-buffer ibut from its in-memory form + (erase-buffer) + (ibut:operate) + (setq buf-str (buffer-substring-no-properties (point-min) (point-max))) + (message buf-str) + (should (hbut:at-p)) + (hbut-tests:should-match-tmp-folder buf-str) + (should (equal "name" (hattr:get 'hbut:current 'name)))))) + +(ert-deftest hbut-tests--ibut-operate--fail-rename-from-name () + "Test that named ibut rename to `new-name' fails when `edit-flag' is nil. + |----+------+----------+--------+------+-----------------------------------------------| + | # | name | new-name | region | edit | operation | + |----+------+----------+--------+------+-----------------------------------------------| + | 4 | name | new-name | nil | nil | ERROR: create can't have name and new-name | + |----+------+----------+--------+------+-----------------------------------------------|" + (with-temp-buffer + ;; Create in-buffer and in-memory ibut + (let ((ibut-str "<[name]> - /tmp") + buf-str) + (insert ibut-str) + (goto-char 2) + (should (hbut:at-p)) + (should (eq (hattr:get 'hbut:current 'actype) 'actypes::link-to-file)) + (hbut-tests:should-match-tmp-folder (buffer-substring-no-properties (point-min) (point-max))) + ;; Test that ibut:operate properly creates an in-buffer ibut from its in-memory form + (erase-buffer) + (should-error (ibut:operate "new-name")) + (setq buf-str (buffer-substring-no-properties (point-min) (point-max))) + (message buf-str)))) + +(ert-deftest hbut-tests--ibut-operate--fail-rename-from-name-ignore-region () + "Test that named ibut rename to `new-name' fails; region active, `edit-flag' nil. + |----+------+----------+--------+------+-----------------------------------------------| + | # | name | new-name | region | edit | operation | + |----+------+----------+--------+------+-----------------------------------------------| + | 5 | name | new-name | region | nil | ERROR: create can't have name and new-name | + |----+------+----------+--------+------+-----------------------------------------------|" + (with-temp-buffer + ;; Create in-buffer and in-memory ibut + (let ((ibut-str "<[name]> - /tmp") + buf-str) + (insert ibut-str) + (goto-char 2) + (should (hbut:at-p)) + (should (eq (hattr:get 'hbut:current 'actype) 'actypes::link-to-file)) + (hbut-tests:should-match-tmp-folder (buffer-substring-no-properties (point-min) (point-max))) + ;; Test that ibut:operate properly creates an in-buffer ibut from its in-memory form + (erase-buffer) + (insert "words in buffer\n") + (mark-whole-buffer) + (should-error (ibut:operate "new-name")) + (setq buf-str (buffer-substring-no-properties (point-min) (point-max))) + (message buf-str)))) + +(ert-deftest hbut-tests--ibut-operate--name-ignore-region () + "Test creation of a named ibut and ignore region. + |----+------+----------+--------+------+-----------------------------------------------| + | # | name | new-name | region | edit | operation | + |----+------+----------+--------+------+-----------------------------------------------| + | 6 | name | nil | region | nil | create: ibut with name (ignore region) | + |----+------+----------+--------+------+-----------------------------------------------|" + (with-temp-buffer + ;; Create in-buffer and in-memory ibut + (let ((ibut-str "<[name]> - /tmp") + buf-str) + (insert ibut-str "\nabcd") + (mark-whole-buffer) + (goto-char 2) + (should (hbut:at-p)) + (should (region-active-p)) + (should (eq (hattr:get 'hbut:current 'actype) 'actypes::link-to-file)) + ;; Test that ibut:operate properly creates an in-buffer ibut from its in-memory form + (erase-buffer) + (should (ibut:operate)) + (setq buf-str (buffer-substring-no-properties (point-min) (point-max))) + (message buf-str) + (should (hbut:at-p)) + (should (eq (hattr:get 'hbut:current 'actype) 'actypes::link-to-file)) + (hbut-tests:should-match-tmp-folder (buffer-substring-no-properties (point-min) (point-max)))))) (ert-deftest hbut-tests--ibut-operate--region () - "Create ibut with aname, ignore region." + "Test creation of a new ibut named from active region. + |----+------+----------+--------+------+-----------------------------------------------| + | # | name | new-name | region | edit | operation | + |----+------+----------+--------+------+-----------------------------------------------| + | 7 | nil | nil | region | nil | create: region named ibut | + |----+------+----------+--------+------+-----------------------------------------------|" (with-temp-buffer - (insert "/tmp") - (goto-char 2) - (should (hbut:at-p)) - (end-of-buffer) - (insert "\n") - (set-mark (point)) - (insert "name") - (should (region-active-p)) - (should-not (ibut:operate)) - (should (string= "/tmp\n<[name]>\"/tmp\"" - (buffer-substring-no-properties (point-min) (point-max)))))) - -(ert-deftest hbut-tests--ibut-operate--modify-named () - "Add new-name to named ibut." + ;; Create in-buffer and in-memory ibut + (let ((ibut-str "region /tmp") + buf-str) + (insert ibut-str) + (goto-char (point-min)) + (mark-word) + ;; Test that ibut:operate properly creates an in-buffer ibut from its in-memory form + (ibut:operate) + (setq buf-str (buffer-substring-no-properties (point-min) (point-max))) + (message buf-str) + (goto-char 2) + (should (hbut:at-p)) + (hbut-tests:should-match-tmp-folder buf-str) + (should (equal "region" (hattr:get 'hbut:current 'name)))))) + +(ert-deftest hbut-tests--ibut-operate--new-name-ignore-region () + "Test creation of a named ibut and ignore region. + |----+------+----------+--------+------+-----------------------------------------------| + | # | name | new-name | region | edit | operation | + |----+------+----------+--------+------+-----------------------------------------------| + | 8 | nil | new-name | region | nil | create: ibut with new-name (ignore region) | + |----+------+----------+--------+------+-----------------------------------------------|" (with-temp-buffer - (insert "<[name]> /tmp") - (goto-char 2) - (should (hbut:at-p)) - (should (eq (hattr:get 'hbut:current 'actype) 'actypes::link-to-file)) - (should-not (ibut:operate "new-name" t)) - (should (hbut:at-p)) - (should (eq (hattr:get 'hbut:current 'actype) 'actypes::link-to-file)) - (should (string= "<[new-name]> /tmp" - (buffer-substring-no-properties (point-min) (point-max)))))) - -(ert-deftest hbut-tests--ibut-operate--modify-named-skip-region () - "Add new-name to named ibut and ignore region." + ;; Create in-buffer and in-memory ibut + (let ((ibut-str "/tmp") + buf-str) + (insert ibut-str "\nabcd") + (mark-whole-buffer) + (goto-char 2) + (should (hbut:at-p)) + (should (region-active-p)) + (should (eq (hattr:get 'hbut:current 'actype) 'actypes::link-to-file)) + ;; Test that ibut:operate properly creates an in-buffer ibut from its in-memory form + (erase-buffer) + (ibut:operate "new-name")) + (setq buf-str (buffer-substring-no-properties (point-min) (point-max))) + (message buf-str) + (should (hbut:at-p)) + (should (eq (hattr:get 'hbut:current 'actype) 'actypes::link-to-file)) + (hbut-tests:should-match-tmp-folder (buffer-substring-no-properties (point-min) (point-max))))) + +(ert-deftest hbut-tests--ibut-operate--remove-name () + "Test removal of any name from ibut at point. + |----+------+----------+--------+------+-----------------------------------------------| + | # | name | new-name | region | edit | operation | + |----+------+----------+--------+------+-----------------------------------------------| + | 9 | nil | nil | nil | t | mod: remove any name from ibut | + |----+------+----------+--------+------+-----------------------------------------------|" (with-temp-buffer - (insert "<[name]> /tmp") - (goto-char 2) - (should (hbut:at-p)) - (set-mark (point-max)) - (should (region-active-p)) - (should-not (ibut:operate "new-name" t)) - (should (hbut:at-p)) - (should (eq (hattr:get 'hbut:current 'actype) 'actypes::link-to-file)) - (should (string= "<[new-name]> /tmp" - (buffer-substring-no-properties (point-min) (point-max)))))) + ;; Create in-buffer and in-memory ibut + (let ((ibut-str "<[name]> - /tmp") + buf-str) + (insert ibut-str) + (goto-char 2) + (should (hbut:at-p)) + ;; Test that ibut:operate properly creates an in-buffer ibut from its in-memory form + (ibut:operate nil t) + (setq buf-str (buffer-substring-no-properties (point-min) (point-max))) + (message buf-str) + (goto-char 2) + (should (hbut:at-p)) + (should (eq (hattr:get 'hbut:current 'actype) 'actypes::link-to-file)) + (hbut-tests:should-match-tmp-folder (buffer-substring-no-properties (point-min) (point-max))) + (should (null (hattr:get 'hbut:current 'name)))))) (ert-deftest hbut-tests--ibut-operate--add-new-name () - "Add new-name to unnamed ibut." + "Test addition of `new-name' to ibut at point. + |----+------+----------+--------+------+-----------------------------------------------| + | # | name | new-name | region | edit | operation | + |----+------+----------+--------+------+-----------------------------------------------| + | 10 | nil | new-name | nil | t | mod: set ibut's name to new-name | + |----+------+----------+--------+------+-----------------------------------------------|" + (with-temp-buffer + ;; Create in-buffer and in-memory ibut + (let ((ibut-str "/tmp") + buf-str) + (insert ibut-str) + (goto-char 2) + (should (hbut:at-p)) + ;; Test that ibut:operate properly creates an in-buffer ibut from its in-memory form + (ibut:operate "new-name" t) + (setq buf-str (buffer-substring-no-properties (point-min) (point-max))) + (message buf-str) + (goto-char 2) + (should (hbut:at-p)) + (should (eq (hattr:get 'hbut:current 'actype) 'actypes::link-to-file)) + (hbut-tests:should-match-tmp-folder (buffer-substring-no-properties (point-min) (point-max))) + (should (equal "new-name" (hattr:get 'hbut:current 'name)))))) + +(ert-deftest hbut-tests--ibut-operate--add-name () + "Test addition of `name' to ibut at point. + |----+------+----------+--------+------+-----------------------------------------------| + | # | name | new-name | region | edit | operation | + |----+------+----------+--------+------+-----------------------------------------------| + | 11 | name | nil | nil | t | mod: name of ibut from hbut:current attrs | + |----+------+----------+--------+------+-----------------------------------------------|" + (with-temp-buffer + ;; Create in-buffer and in-memory ibut + (let ((ibut-str "/tmp") + buf-str) + (insert ibut-str) + (goto-char 2) + (should (hbut:at-p)) + ;; Test that ibut:operate properly creates an in-buffer ibut from its in-memory form + (hattr:set 'hbut:current 'name "name") + (ibut:operate nil t) + (setq buf-str (buffer-substring-no-properties (point-min) (point-max))) + (message buf-str) + (goto-char 2) + (should (hbut:at-p)) + (should (eq (hattr:get 'hbut:current 'actype) 'actypes::link-to-file)) + (hbut-tests:should-match-tmp-folder (buffer-substring-no-properties (point-min) (point-max))) + (should (equal "name" (hattr:get 'hbut:current 'name)))))) + +(ert-deftest hbut-tests--ibut-operate--rename-from-name () + "Test that named ibut rename to `new-name' fails when `edit-flag' is nil. + |----+------+----------+--------+------+-----------------------------------------------| + | # | name | new-name | region | edit | operation | + |----+------+----------+--------+------+-----------------------------------------------| + | 12 | name | new-name | nil | t | mod: rename ibut with name to new-name | + |----+------+----------+--------+------+-----------------------------------------------|" + (with-temp-buffer + ;; Create in-buffer and in-memory ibut + (let ((ibut-str "<[name]> - /tmp") + buf-str) + (insert ibut-str) + (goto-char 2) + (should (hbut:at-p)) + ;; Test that ibut:operate properly creates an in-buffer ibut from its in-memory form + (ibut:operate "new-name" t) + (setq buf-str (buffer-substring-no-properties (point-min) (point-max))) + (message buf-str) + (goto-char 2) + (should (hbut:at-p)) + (should (eq (hattr:get 'hbut:current 'actype) 'actypes::link-to-file)) + (hbut-tests:should-match-tmp-folder (buffer-substring-no-properties (point-min) (point-max))) + (should (equal "new-name" (hattr:get 'hbut:current 'name)))))) + +(ert-deftest hbut-tests--ibut-operate--fail-rename-ignore-region () + "Test modification failure of an named ibut with `new-name' and active region. + |----+------+----------+--------+------+-----------------------------------------------| + | # | name | new-name | region | edit | operation | + |----+------+----------+--------+------+-----------------------------------------------| + | 13 | name | new-name | region | t | ERROR: Can't use region to mod existing ibut | + |----+------+----------+--------+------+-----------------------------------------------|" + (with-temp-buffer + (let (buf-str) + (insert "<[name]> - /tmp") + (goto-char 2) + (should (hbut:at-p)) + (set-mark (point-max)) + (should (region-active-p)) + (should-error (ibut:operate "new-name" t)) + (should (hbut:at-p)) + (setq buf-str (buffer-substring-no-properties (point-min) (point-max))) + (message buf-str) + (hbut-tests:should-match-tmp-folder buf-str) + (should (equal "name" (hattr:get 'hbut:current 'name)))))) + +(ert-deftest hbut-tests--ibut-operate--fail-name-ignore-region () + "Test modification failure of a named ibut with active region. + |----+------+----------+--------+------+-----------------------------------------------| + | # | name | new-name | region | edit | operation | + |----+------+----------+--------+------+-----------------------------------------------| + | 14 | name | nil | region | t | ERROR: Can't use region to mod existing ibut | + |----+------+----------+--------+------+-----------------------------------------------|" + (with-temp-buffer + (let (buf-str) + (insert "<[name]> - /tmp") + (goto-char 2) + (should (hbut:at-p)) + (set-mark (point-max)) + (should (region-active-p)) + (should-error (ibut:operate nil t)) + (should (hbut:at-p)) + (setq buf-str (buffer-substring-no-properties (point-min) (point-max))) + (message buf-str) + (hbut-tests:should-match-tmp-folder buf-str) + (should (equal "name" (hattr:get 'hbut:current 'name)))))) + +(ert-deftest hbut-tests--ibut-operate--fail-rename-from-region () + "Test modification failure of an unnamed ibut with active region. + |----+------+----------+--------+------+-----------------------------------------------| + | # | name | new-name | region | edit | operation | + |----+------+----------+--------+------+-----------------------------------------------| + | 15 | nil | nil | region | t | ERROR: Can't use region to mod existing ibut | + |----+------+----------+--------+------+-----------------------------------------------|" (with-temp-buffer - (insert "/tmp") - (goto-char 2) - (should (hbut:at-p)) - (should (eq (hattr:get 'hbut:current 'actype) 'actypes::link-to-file)) - (should-not (ibut:operate "new-name" t)) - ;; Missing delimiter -- Not identified as a ibut after name is inserted - ;; (should (hbut:at-p)) - ;; (should (eq (hattr:get 'hbut:current 'actype) 'actypes::link-to-file)) - ;; delimiter - (should (string= "<[new-name]>/tmp" - (buffer-substring-no-properties (point-min) (point-max)))))) - -(ert-deftest hbut-tests--ibut-operate--add-new-name-skip-region () - "Add new-name to unnamed ibut, skip active region." + (let (buf-str) + (insert "/tmp") + (goto-char 2) + (should (hbut:at-p)) + (set-mark (point-max)) + (should (region-active-p)) + (should-error (ibut:operate nil t)) + (should (hbut:at-p)) + (setq buf-str (buffer-substring-no-properties (point-min) (point-max))) + (message buf-str) + (hbut-tests:should-match-tmp-folder buf-str) + (should (null (hattr:get 'hbut:current 'name)))))) + +(ert-deftest hbut-tests--ibut-operate--fail-add-new-name-ignore-region () + "Test modification failure of an unnamed ibut with `new-name' and active region. + |----+------+----------+--------+------+-----------------------------------------------| + | # | name | new-name | region | edit | operation | + |----+------+----------+--------+------+-----------------------------------------------| + | 16 | nil | new-name | region | t | ERROR: Can't use region to mod existing ibut | + |----+------+----------+--------+------+-----------------------------------------------|" (with-temp-buffer - (insert "/tmp") - (goto-char 2) - (should (hbut:at-p)) - (set-mark (point-max)) - (should (region-active-p)) - (should-not (ibut:operate "new-name" t)) - ;; Missing delimiter -- Not identified as a ibut after name is inserted - ;; (should (hbut:at-p)) - ;; (should (eq (hattr:get 'hbut:current 'actype) 'actypes::link-to-file)) - ;; Missing delimiter - (should (string= "<[new-name]>/tmp" - )))) + (let (buf-str) + (insert "/tmp") + (goto-char 2) + (should (hbut:at-p)) + (set-mark (point-max)) + (should (region-active-p)) + (should-error (ibut:operate "new-name" t)) + (should (hbut:at-p)) + (setq buf-str (buffer-substring-no-properties (point-min) (point-max))) + (message buf-str) + (hbut-tests:should-match-tmp-folder buf-str) + (should (null (hattr:get 'hbut:current 'name)))))) ;; This file can't be byte-compiled without the `el-mock' package (because of ;; the use of the `with-mock' macro), which is not a dependency of Hyperbole.