diff --git a/ChangeLog b/ChangeLog index 5947b195..b9fc060b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2026-03-26 Mats Lidell + +* test/hui-tests.el (hui--kill-region-delimited-text-and-yank-back): + Remove expected-result tag and expand tests. + (hui-tests--selectable-thing-and-bounds): Add test. + 2026-03-24 Mats Lidell * hui-mouse.el (profiler-report-find-entry) diff --git a/test/hui-tests.el b/test/hui-tests.el index b03d2fa9..a96c3942 100644 --- a/test/hui-tests.el +++ b/test/hui-tests.el @@ -1511,40 +1511,108 @@ line 1 (ert-deftest hui--kill-region-delimited-text-and-yank-back () "Verify multiple `hui:kill-region' calls followed by a `yank' works properly." - :expected-result :failed (with-temp-buffer (let ((transient-mark-mode t) (mark-even-if-inactive t) last-command) - (insert "") - (goto-char 2) - (setq last-command #'ignore) - (call-interactively #'hui:kill-region) - (should (string= (buffer-string) "<>")) - (yank) - (should (string= (buffer-string) "")))) - (with-temp-buffer - (let ((transient-mark-mode t) - (mark-even-if-inactive t) - last-command) - (insert "\n") - (goto-char 1) - (setq last-command #'ignore) - (call-interactively #'hui:kill-region) - (should (string= (buffer-string) "\n")) - (yank) - (should (string= (buffer-string) "\n")))) + (fundamental-mode) + (dolist (pos '(1 2)) + (dolist (text '("{hi}" "(hi)" "[hi]" "\"hi\"")) + (ert-info ((format "Kill thing: '%s' at pos: %s in mode: %s" text pos major-mode)) + (erase-buffer) + (insert (format "%s\n" text)) + (goto-char pos) + (setq last-command #'ignore) + (call-interactively #'hui:kill-region) + (should (string= (buffer-string) "\n")) + (yank) + (should (string= (buffer-string) (format "%s\n" text)))))) + + (text-mode) + (dolist (pos '(1 2)) + (dolist (text '("{hi}" "(hi)" "[hi]")) + (ert-info ((format "Kill thing: '%s' at pos: %s in mode: %s" text pos major-mode)) + (erase-buffer) + (insert (format "%s\n" text)) + (goto-char pos) + (setq last-command #'ignore) + (call-interactively #'hui:kill-region) + (should (string= (buffer-string) "\n")) + (yank) + (should (string= (buffer-string) (format "%s\n" text)))))) + + (let ((text "\"hi\"") + (pos 1)) + (ert-info ((format "Kill thing: '%s' at pos: %s in mode: %s" text pos major-mode)) + (erase-buffer) + (insert (format "%s\n" text)) + (goto-char pos) + (setq last-command #'ignore) + (call-interactively #'hui:kill-region) + (should (string= (buffer-string) "\n")) + (yank) + (should (string= (buffer-string) (format "%s\n" text))))) + + (let ((text "\"hi\"") + (pos 2)) + (ert-info ((format "Kill thing: '%s' at pos: %s in mode: %s" text pos major-mode)) + (erase-buffer) + (insert (format "%s\n" text)) + (goto-char 2) + (setq last-command #'ignore) + (call-interactively #'hui:kill-region) + (should (string= (buffer-string) "\"\"\n")) + (yank) + (should (string= (buffer-string) (format "%s\n" text)))))))) + +(ert-deftest hui-tests--selectable-thing-and-bounds () + "Verify `hui:selectable-thing-and-bounds'." (with-temp-buffer (let ((transient-mark-mode t) (mark-even-if-inactive t) last-command) - (insert "") - (goto-char 1) - (setq last-command #'ignore) - (call-interactively #'hui:kill-region) - (should (string= (buffer-string) "")) - (yank) - (should (string= (buffer-string) ""))))) + (fundamental-mode) + (dolist (text '("{hi}" "(hi)" "[hi]")) + (erase-buffer) + (insert (format "%s\n" text)) + (ert-info ((format "Select thing: '%s' at pos 1" text)) + (goto-char 1) + (should (equal `(sexp-start ,text 1 5) (hui:selectable-thing-and-bounds)))) + (ert-info ((format "Select thing: '%s' at pos 2" text)) + (goto-char 2) + (should (equal `(symbol ,text 1 5) (hui:selectable-thing-and-bounds))))) + + (ert-info ((format "Select thing within \"\" delimiters in mode: %s" major-mode)) + (erase-buffer) + (insert "\"hi\"\n") + (goto-char 1) + (should (equal '(string "\"hi\"" 1 5) (hui:selectable-thing-and-bounds))) + (goto-char 2) + (should (equal '(symbol "\"hi\"" 1 5) (hui:selectable-thing-and-bounds)))) + + (text-mode) + (ert-info ((format "Select thing within \"\" delimiters in mode: %s" major-mode)) + (erase-buffer) + (insert "\"hi\"\n") + (goto-char 1) + (should (equal '(string "\"hi\"" 1 5) (hui:selectable-thing-and-bounds))) + (goto-char 2) + (should (equal '(symbol "hi" 2 4) (hui:selectable-thing-and-bounds)))) + + (ert-info ("Select thing within <> delimiters") + (erase-buffer) + (insert "\n") + (goto-char 1) + (should (equal '(sexp-start "" 1 5) (hui:selectable-thing-and-bounds))) + (goto-char 2) + (should (equal '(symbol "hi" 2 4) (hui:selectable-thing-and-bounds)))) + + (ert-info ("Select thing within delimiters at eof fails") + (dolist (text '("{hi}" "(hi)" "[hi]" "" "\"hi\"")) + (erase-buffer) + (insert text) + (goto-char 1) + (should-not (hui:selectable-thing-and-bounds))))))) ;; This file can't be byte-compiled without the `el-mock' which ;; is not part of the actual dependencies, so: