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

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

[elpa] externals/hyperbole 121d8fd0fc 2/4: Finish adding all ibut:operat


From: ELPA Syncer
Subject: [elpa] externals/hyperbole 121d8fd0fc 2/4: Finish adding all ibut:operate tests (not all work yet)
Date: Sun, 9 Jul 2023 03:58:02 -0400 (EDT)

branch: externals/hyperbole
commit 121d8fd0fc87b9a248b05b3b319a556a9c67f775
Author: Bob Weiner <rsw@gnu.org>
Commit: Bob Weiner <rsw@gnu.org>

    Finish adding all ibut:operate tests (not all work yet)
---
 ChangeLog          |   8 +
 hbut.el            |  14 +-
 test/demo-tests.el |   4 +-
 test/hbut-tests.el | 474 ++++++++++++++++++++++++++++++++++++++++-------------
 4 files changed, 378 insertions(+), 122 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 6a24c25365..d9057b700c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,14 @@
 * 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  <rsw@gnu.org>
 
 * test/demo-tests.el 
(demo-implicit-button-action-button-boolean-function-call-test):
diff --git a/hbut.el b/hbut.el
index f43a7ff13e..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:58:20 by Bob Weiner
+;; Last-Mod:      9-Jul-23 at 02:09:54 by Bob Weiner
 ;;
 ;; SPDX-License-Identifier: GPL-3.0-or-later
 ;;
@@ -2192,14 +2192,14 @@ Summary of operations based on inputs (name arg comes 
from \\='hbut:current attr
 |  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/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 <matsl@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 <matsl@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.



reply via email to

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