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

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

[elpa] externals/hyperbole 6a8154a 33/50: Add first unit tests (#46)


From: Stefan Monnier
Subject: [elpa] externals/hyperbole 6a8154a 33/50: Add first unit tests (#46)
Date: Wed, 17 Mar 2021 18:44:19 -0400 (EDT)

branch: externals/hyperbole
commit 6a8154add38ded772be3044dc36475ebb69d7a8e
Author: Mats Lidell <mats.lidell@lidells.se>
Commit: GitHub <noreply@github.com>

    Add first unit tests (#46)
---
 Changes                      |  47 ++++++
 Makefile                     |  18 ++
 test/demo-tests.el           | 383 +++++++++++++++++++++++++++++++++++++++++++
 test/hactypes-tests.el       |  34 ++++
 test/hib-kbd-tests.el        |  49 ++++++
 test/hib-social-tests.el     |  56 +++++++
 test/hibtypes-tests.el       | 249 ++++++++++++++++++++++++++++
 test/hy-test-dependencies.el |  27 +++
 test/hy-test-helpers.el      |  33 ++++
 9 files changed, 896 insertions(+)

diff --git a/Changes b/Changes
index b7568b5..dc31687 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,21 @@
+2021-02-20  Mats Lidell  <matsl@gnu.org>
+
+* test/hibtypes-tests.el (mail-address-at-p-test)
+  (mail-address-at-p-no-mail-should-fail-test, ibtypes::mail-address-test)
+  (ibtypes::pathname-test, ibtypes::pathname-lisp-variable-test)
+  (ibtypes::pathname-env-variable-test)
+  (ibtypes::pathname-emacs-lisp-file-test, ibtypes::annot-bib-test)
+  (ibtypes::ctags-vgrind-test, ibtypes::etags-test)
+  (ibtypes::text-toc-test, ibtypes::dir-summary-test, ibtypes::rfc-test)
+  (ibtypes::man-apropos-test, ibtypes::info-node-test): Tests for hibtypes.
+
+* test/hib-social-tests.el (hib-social-should-browse-twitter-url)
+  (hib-social-twitter-test, hib-social-should-browse-github-url)
+  (hib-github-user-default-test, hib-github-ignore-default-test): Test for
+    hib-social.
+
+* test/hy-test-dependencies.el: Load prerequisites for tests
+
 2021-02-15  Bob Weiner  <rsw@gnu.org>
 
 * hmouse-drv.el (hkey-window-link, hkey-ace-window-setup): Added Ace Window 
'w' command to
@@ -69,6 +87,35 @@
 2020-12-03  Bob Weiner  <rsw@gnu.org>
 
 * hibtypes.el (Info-node): Allowed for backslash double-quotes around node 
name, e.g. when in a doc string.
+2021-01-30  Mats Lidell  <matsl@gnu.org>
+
+* Makefile (test-ert, test-all): Add ert test targets
+
+* test/hib-kbd-tests.el (kbd-key-hy-about-test)
+    (kbd-key-hy-demo-factorial-test): Added.
+* test/hactypes-tests.el (display-boolean-true-test)
+    (display-boolean-false-test): Added.
+* test/hy-test-helpers.el (hy-test-helpers:consume-input-events)
+    (hy-test-helpers:should-last-message): Added helper functions.
+* test/demo-tests.el (demo-smart-mouse-keys-ref-test)
+    (demo-smart-mouse-keys-ebut-test, demo-table-of-contents-test)
+    (demo-smart-scrolling-proportional-test)
+    (demo-smart-scrolling-non-proportional-test, demo-action-key-help)
+    (demo-assist-key-help, demo-window-grid-22-test)
+    (demo-window-grid-33-test, demo-hy-rolo-test, demo-hy-info-test)
+    (demo-hy-history-test, demo-implicit-button-test)
+    (demo-implicit-button-action-button-action-type-invocation-test)
+    (demo-implicit-button-action-button-function-calls-test)
+    (demo-implicit-button-action-button-variable-display-test)
+    (demo-implicit-button-hash-link-test)
+    (demo-implicit-button-line-and-column-test)
+    (demo-org-hide-header-test, demo-manifest-test)
+    (demo-mail-compose-test, demo-social-twitter-test, demo-www-test)
+    (demo-github-user-default-test, demo-github-ignore-default-test)
+    (demo-occur-test, demo-annotated-reference-test)
+    (demo-man-appropos-test, demo-factorial-test)
+    (demo-factorial-ebutton-test): Test cases
+    (demo-should-browse-url): Test helper
 
 2020-11-22  Bob Weiner  <rsw@gnu.org>
 
diff --git a/Makefile b/Makefile
index feb8cba..cca104e 100644
--- a/Makefile
+++ b/Makefile
@@ -374,3 +374,21 @@ packageclean:
        if [ -d $(pkg_hyperbole)/man/im ]; then \
          cd $(pkg_hyperbole)/man/im && $(RM) -r .DS_Store core .place* ._* .*~ 
*~ \
            *.ps *\# *- *.orig *.rej .nfs* CVS .cvsignore; fi
+
+# Ert test
+.PHONY: test test-ert test-all
+test: test-ert
+
+BATCH=$(EMACS) $(BATCHFLAGS) $(PRELOADS)
+INTERACTIVE=$(EMACS) --quick $(PRELOADS)
+
+TEST_ERT_FILES=$(wildcard test/*tests.el)
+LOAD_TEST_ERT_FILES=$(patsubst %,(load-file \"%\"),${TEST_ERT_FILES})
+
+test-ert:
+       @echo "# Tests: $(TEST_ERT_FILES)"
+       $(BATCH) --eval "(load-file \"test/hy-test-dependencies.el\")" --eval 
"(progn $(LOAD_TEST_ERT_FILES) (ert-run-tests-batch-and-exit))"
+
+test-all:
+       @echo "# Tests: $(TEST_ERT_FILES)"
+       $(INTERACTIVE) --eval "(load-file \"test/hy-test-dependencies.el\")" 
--eval "(progn $(LOAD_TEST_ERT_FILES) (ert-run-tests-interactively t))"
diff --git a/test/demo-tests.el b/test/demo-tests.el
new file mode 100644
index 0000000..44f50e8
--- /dev/null
+++ b/test/demo-tests.el
@@ -0,0 +1,383 @@
+;;; demo-tests.el --- unit tests from examples in the DEMO         -*- 
lexical-binding: t; -*-
+
+;; Author: Mats Lidell <matsl@gnu.org>
+;;
+;; Orig-Date: 30-Jan-21 at 12:00:00
+;;
+;; Copyright (C) 2021  Free Software Foundation, Inc.
+;; See the "HY-COPY" file for license information.
+;;
+;; This file is part of GNU Hyperbole.
+
+;;; Commentary:
+
+;; Runs unit tests on some of the examples given in the DEMO file.
+
+;;; Code:
+
+(require 'ert)
+(require 'hib-kbd)
+(require 'hmouse-drv)
+(require 'hhist)
+(require 'hload-path)
+(require 'hypb)
+(require 'hib-social)
+(require 'eww)
+(require 'compile)
+
+(load (expand-file-name "hy-test-helpers"
+                        (file-name-directory (or load-file-name
+                                                 default-directory))))
+(declare-function hy-test-helpers:consume-input-events "hy-test-helpers")
+(declare-function hy-test-helpers:should-last-message "hy-test-helpers")
+(declare-function hyrolo-demo-quit "hyrolo-demo.el")
+(declare-function org-check-for-hidden "org-el")
+
+(ert-deftest demo-smart-mouse-keys-ref-test ()
+  (unwind-protect
+      (progn
+        (hypb:display-file-with-logo (expand-file-name "DEMO" hyperb:dir))
+        (goto-char (point-min))
+        (re-search-forward "#Smart Keys")
+        (action-key)
+        (should (bolp))
+        (should (looking-at "^\\* Smart")))
+    (kill-buffer "DEMO")))
+
+(ert-deftest demo-smart-mouse-keys-ebut-test ()
+  (unwind-protect
+      (progn
+        (hypb:display-file-with-logo (expand-file-name "DEMO" hyperb:dir))
+        (goto-char (point-min))
+        (re-search-forward "<(Smart")
+        (action-key)
+        (should (bolp))
+        (should (looking-at "^ +\\* Smart")))
+    (kill-buffer "DEMO")))
+
+(ert-deftest demo-table-of-contents-test ()
+  (unwind-protect
+      (progn
+        (hypb:display-file-with-logo (expand-file-name "DEMO" hyperb:dir))
+        (goto-char (point-min))
+        (re-search-forward " \* Koutl")
+        (action-key)
+        (should (bolp))
+        (should (looking-at "^* Koutliner")))
+    (kill-buffer "DEMO")))
+
+;; Smart scrolling
+(ert-deftest demo-smart-scrolling-proportional-test ()
+  (unwind-protect
+      (progn
+        (hypb:display-file-with-logo (expand-file-name "DEMO" hyperb:dir))
+        (goto-char (point-min))
+        (re-search-forward "Table of Contents")
+        (beginning-of-line)
+        (let ((smart-scroll-proportional t)
+              (pos (point)))
+          (end-of-line)
+          (action-key)
+          (beginning-of-line)
+          (should (= pos (window-start)))))
+    (kill-buffer "DEMO")))
+
+(ert-deftest demo-smart-scrolling-non-proportional-test ()
+  (unwind-protect
+      (progn
+        (hypb:display-file-with-logo (expand-file-name "DEMO" hyperb:dir))
+        (goto-char (point-min))
+        (re-search-forward "Table of Contents")
+        (let ((smart-scroll-proportional nil)
+              (pos (point)))
+          (action-key)
+          (should (< pos (point)))))
+    (kill-buffer "DEMO")))
+
+;; Hyperbole menus
+
+;; Help Buffer
+(ert-deftest demo-action-key-help ()
+  (let ((help-buffer "*Help: Hyperbole Action Key*"))
+    (if (get-buffer help-buffer)
+        (kill-buffer help-buffer))
+    (unwind-protect
+        (with-temp-buffer
+          (insert "Text")
+          (hkey-help)
+          (should (get-buffer help-buffer))
+      (kill-buffer help-buffer)))))
+
+(ert-deftest demo-assist-key-help ()
+  (let ((help-buffer "*Help: Hyperbole Assist Key*"))
+    (if (get-buffer help-buffer)
+        (kill-buffer help-buffer))
+    (unwind-protect
+        (with-temp-buffer
+          (insert "Text")
+          (hkey-help t)
+          (should (get-buffer help-buffer))
+      (kill-buffer help-buffer)))))
+
+;; Hy-control
+(ert-deftest demo-window-grid-22-test ()
+  (skip-unless (not noninteractive))
+  (unwind-protect
+      (progn
+        (hypb:display-file-with-logo (expand-file-name "DEMO" hyperb:dir))
+        (should (hact 'kbd-key "C-h h s f @ 22 RET Q"))
+        (hy-test-helpers:consume-input-events)
+        (should (eq 4 (length (window-list)))))
+    (kill-buffer "DEMO")))
+
+(ert-deftest demo-window-grid-33-test ()
+  (skip-unless (not noninteractive))
+  (unwind-protect
+      (progn
+        (hypb:display-file-with-logo (expand-file-name "DEMO" hyperb:dir))
+        (should (hact 'kbd-key "C-h h s f @ 33 RET Q"))
+        (hy-test-helpers:consume-input-events)
+        (should (eq 9 (length (window-list)))))
+    (kill-buffer "DEMO")))
+
+;; Hy-rolo
+(ert-deftest demo-hy-rolo-test ()
+  (skip-unless (not noninteractive))
+  (unwind-protect
+      (with-temp-buffer
+        (load (expand-file-name "hyrolo-demo.el" hyperb:dir))
+        (should (hact 'kbd-key "C-x 4 r work RET"))
+        (hy-test-helpers:consume-input-events)
+        (should (string= "*Hyperbole Rolo*" (buffer-name)))
+        (should (search-forward "Dunn, John")))
+    (hyrolo-demo-quit)))
+
+;; Info
+(ert-deftest demo-hy-info-test ()
+  (unwind-protect
+      (with-temp-buffer
+        (insert "\"(hyperbole)HyRolo Keys\"")
+        (goto-char 5)
+        (action-key)
+        (should (string= "*info*" (buffer-name))))
+    (kill-buffer "*info*")))
+
+;; History
+(ert-deftest demo-hy-history-test ()
+  (unwind-protect
+      (with-temp-buffer
+        (let ((tmp-buf-name (buffer-name))
+              (pm))
+          (hhist:init)
+          (insert "\"(hyperbole)HyRolo Keys\"")
+          (goto-char 5)
+          (setq pm (point-marker))
+          (action-key)
+          (should (string= "*info*" (buffer-name)))
+          (hhist:remove)
+          (should (string= tmp-buf-name (buffer-name)))
+          (should (equal pm (point-marker)))
+          ))
+    (kill-buffer "*info*")))
+
+;; Implicit Buttons
+(ert-deftest demo-implicit-button-test ()
+  (unwind-protect
+      (with-temp-buffer
+        (insert (format "\"%s\"" (expand-file-name "DEMO" hyperb:dir)))
+        (goto-char 2)
+        (action-key)
+        (should (string= "DEMO" (buffer-name))))
+    (kill-buffer "DEMO")))
+
+(ert-deftest demo-implicit-button-action-button-action-type-invocation-test ()
+  (unwind-protect
+      (with-temp-buffer
+        (insert "<link-to-file-line \"${hyperb:dir}/DEMO\" 5>")
+        (goto-char 5)
+        (action-key)
+        (should (string= "DEMO" (buffer-name)))
+        (should (looking-at "\s*Table of Contents")))
+    (kill-buffer "DEMO")))
+
+(ert-deftest demo-implicit-button-action-button-function-calls-test ()
+  (with-temp-buffer
+    (insert "<message \"%d\" (eval (+ 2 2))>")
+    (goto-char 2)
+    (action-key)
+    (hy-test-helpers:should-last-message "4")))
+
+(ert-deftest demo-implicit-button-action-button-variable-display-test ()
+  (with-temp-buffer
+    (insert "<fill-column>")
+    (goto-char 2)
+    (action-key)
+    (hy-test-helpers:should-last-message (format "fill-column = %d" 
(current-fill-column)))))
+
+(ert-deftest demo-implicit-button-hash-link-test ()
+  (unwind-protect
+      (with-temp-buffer
+        (insert (format "\"%s%s\"" (expand-file-name "README.md" hyperb:dir) 
"#why-was-hyperbole-developed"))
+        (goto-char 5)
+        (action-key)
+        (should (string= "README.md" (buffer-name)))
+        (should (looking-at "## Why was Hyperbole developed\\?")))
+    (kill-buffer "README.md")))
+
+(ert-deftest demo-implicit-button-line-and-column-test ()
+  (unwind-protect
+      (with-temp-buffer
+        (insert (format "\"%s%s\"" (expand-file-name "HY-ABOUT" hyperb:dir) 
":5:46"))
+        (goto-char 5)
+        (action-key)
+        (should (string= "HY-ABOUT" (buffer-name)))
+        (should (looking-at "hyperbole/")))
+    (kill-buffer "HY-ABOUT")))
+
+;; org
+(ert-deftest demo-org-hide-header-test ()
+  "Should work with action-key but does not. Works with org modes hide 
function."
+  :expected-result :failed
+  (with-temp-buffer
+    (org-mode)
+    (insert "* 1\n** 2\n*** 3\n")
+    (goto-char 1)
+    (should (not (org-check-for-hidden 'headlines)))
+    (action-key)
+    ;;; (org-hide-entry)
+    (should (org-check-for-hidden 'headlines))
+    ))
+
+;; Manifest
+(ert-deftest demo-manifest-test ()
+  (unwind-protect
+      (progn
+        (find-file (expand-file-name "MANIFEST" hyperb:dir))
+        (forward-line 1)
+        (should (looking-at "COPYING"))
+        (action-key)
+        (should (string= "COPYING" (buffer-name)))
+        (should (looking-at ".*GNU GENERAL PUBLIC LICENSE")))
+    (progn
+      (kill-buffer "MANIFEST")
+      (kill-buffer "COPYING"))))
+
+;; Email compose
+(ert-deftest demo-mail-compose-test ()
+  (unwind-protect
+      (with-temp-buffer
+        (insert "receiver@mail.org")
+        (goto-char 2)
+        (action-key)
+        (should (string= "*mail*" (buffer-name))))
+    (kill-buffer "*mail*")))
+
+
+(defun demo-should-browse-twitter-url (url &optional new-window)
+  "Verify call with proper URL and optional NEW-WINDOW."
+  (should (equal url "https://twitter.com/search?q=@fsf";))
+  (should (equal new-window nil)))
+
+;; Social
+(ert-deftest demo-social-twitter-test ()
+  (with-temp-buffer
+    (insert "tw@fsf")
+    (goto-char 2)
+    (let ((browse-url-browser-function 'demo-should-browse-twitter-url))
+      (action-key))))
+
+
+(defun demo-should-browse-github-url (url &optional new-window)
+  "Verify call with proper URL and optional NEW-WINDOW."
+  (should (equal url "https://github.com/rswgnu/hyperbole";))
+  (should (equal new-window nil)))
+
+;; WWW
+(ert-deftest demo-www-test ()
+  (with-temp-buffer
+    (insert "https://github.com/rswgnu/hyperbole";)
+    (goto-char 4)
+    (let ((browse-url-browser-function 'demo-should-browse-github-url)
+          (hibtypes-github-default-user "rswgnu"))
+      (action-key))))
+
+;; Github
+(ert-deftest demo-github-user-default-test ()
+  (with-temp-buffer
+    (insert "gh#/hyperbole")
+    (goto-char 4)
+    (let ((browse-url-browser-function 'demo-should-browse-github-url)
+          (hibtypes-github-default-user "rswgnu"))
+      (action-key))))
+
+(ert-deftest demo-github-ignore-default-test ()
+  (with-temp-buffer
+    (insert "gh#/rswgnu/hyperbole")
+    (goto-char 4)
+    (let ((browse-url-browser-function 'demo-should-browse-github-url)
+          (hibtypes-github-default-user "whatever"))
+      (action-key))))
+
+;; Occur
+(ert-deftest demo-occur-test ()
+  (skip-unless (not noninteractive))
+  (unwind-protect
+      (progn
+        (hypb:display-file-with-logo (expand-file-name "DEMO" hyperb:dir))
+        (should (hact 'kbd-key "C-h h f o Hyperbole RET"))
+        (hy-test-helpers:consume-input-events)
+        (set-buffer "*Occur*")
+        (should (looking-at "[0-9]+ matches in [0-9]+ lines for \"Hyperbole\" 
in buffer: DEMO")))
+    (progn
+      (kill-buffer "DEMO")
+      (kill-buffer "*Occur*"))))
+
+;; Annotated references
+(ert-deftest demo-annotated-reference-test ()
+  (unwind-protect
+      (progn
+        (hypb:display-file-with-logo (expand-file-name "DEMO" hyperb:dir))
+        (re-search-forward "\\[FSF 19\\]")
+        (backward-char 1)
+        (action-key)
+        (should (looking-at "\\[FSF 19\\] Free Software Foundation"))
+        (forward-line -2)
+        (should (looking-at "\\* References")))
+    (kill-buffer "DEMO")))
+
+;; Man appropos
+(ert-deftest demo-man-appropos-test ()
+  (unwind-protect
+      (with-temp-buffer
+        (insert "rm (1)   - remove")
+        (goto-char 4)
+        (action-key)
+        (sit-for 0.2)
+        (set-buffer "*Man 1 rm*")
+        (should (looking-at "RM\(1\)")))
+    (kill-buffer "*Man 1 rm*")))
+
+;; Explicit buttons
+(ert-deftest demo-factorial-test ()
+  (skip-unless (not noninteractive))
+  (unwind-protect
+      (progn
+        (hypb:display-file-with-logo (expand-file-name "DEMO" hyperb:dir))
+        (should (hact 'kbd-key "C-h h a factorial RET"))
+        (hy-test-helpers:consume-input-events)
+        (hy-test-helpers:should-last-message "Factorial of 5 = 120"))
+    (kill-buffer "DEMO")))
+
+(ert-deftest demo-factorial-ebutton-test ()
+  (skip-unless (not noninteractive))
+  (unwind-protect
+      (progn
+        (hypb:display-file-with-logo (expand-file-name "DEMO" hyperb:dir))
+        (re-search-forward "<(factorial)>")
+        (forward-char -5)
+        (action-key)
+        (hy-test-helpers:should-last-message "Factorial of 5 = 120"))
+    (kill-buffer "DEMO")))
+
+(provide 'demo-tests)
+;;; demo-tests.el ends here
diff --git a/test/hactypes-tests.el b/test/hactypes-tests.el
new file mode 100644
index 0000000..5f5d9d3
--- /dev/null
+++ b/test/hactypes-tests.el
@@ -0,0 +1,34 @@
+;;; hactypes-test.el -- Ert tests for hactypes        -*- lexical-binding: t; 
-*-
+;;
+;; Author: Mats Lidell <matsl@gnu.org>
+;;
+;; Orig-Date: 30-Jan-21 at 12:00:00
+;;
+;; Copyright (C) 2021  Free Software Foundation, Inc.
+;; See the "HY-COPY" file for license information.
+;;
+;; This file is part of GNU Hyperbole.
+
+;;; Commentary:
+
+;;
+
+;;; Code:
+
+(require 'ert)
+(require 'hactypes)
+(load (expand-file-name "hy-test-helpers"
+                        (file-name-directory (or load-file-name
+                                                 default-directory))))
+(declare-function hy-test-helpers:should-last-message "hy-test-helpers")
+
+(ert-deftest display-boolean-true-test ()
+  (should (actypes::display-boolean t))
+  (hy-test-helpers:should-last-message "Boolean result (True) = t"))
+
+(ert-deftest display-boolean-false-test ()
+  (should (actypes::display-boolean nil))
+    (hy-test-helpers:should-last-message "Boolean result (False) = nil"))
+
+(provide 'hactypes-tests)
+;;; hactypes-tests.el ends here
diff --git a/test/hib-kbd-tests.el b/test/hib-kbd-tests.el
new file mode 100644
index 0000000..0e8680f
--- /dev/null
+++ b/test/hib-kbd-tests.el
@@ -0,0 +1,49 @@
+;;; hib-kbd-tests.el --- unit test for hib-kbd        -*- lexical-binding: t; 
-*-
+
+;; Author: Mats Lidell <matsl@gnu.org>
+;;
+;; Orig-Date: 30-Jan-21 at 12:00:00
+;;
+;; Copyright (C) 2021  Free Software Foundation, Inc.
+;; See the "HY-COPY" file for license information.
+;;
+;; This file is part of GNU Hyperbole.
+
+;;; Commentary:
+
+;; Helper functions
+
+;;; Code:
+
+(require 'ert)
+(require 'hib-kbd)
+(load (expand-file-name "hy-test-helpers"
+                        (file-name-directory (or load-file-name
+                                                 default-directory))))
+(declare-function hy-test-helpers:consume-input-events "hy-test-helpers")
+(declare-function hy-test-helpers:should-last-message "hy-test-helpers")
+
+(ert-deftest kbd-key-hy-about-test ()
+  (skip-unless (not noninteractive))
+  (unwind-protect
+      (progn
+        (should (hact 'kbd-key "C-h h d a"))
+        (hy-test-helpers:consume-input-events)
+        (should (string= (buffer-name (current-buffer)) "HY-ABOUT" )))
+    (kill-buffer "HY-ABOUT")))
+
+(ert-deftest kbd-key-hy-demo-factorial-test ()
+  (skip-unless (not noninteractive))
+  (unwind-protect
+      (progn
+        (should (hact 'kbd-key "C-h h d d"))
+        (hy-test-helpers:consume-input-events)
+        (should (string= (buffer-name (current-buffer)) "DEMO" ))
+        (should (hact 'kbd-key "C-h h a factorial RET"))
+        (hy-test-helpers:consume-input-events)
+        (sleep-for 0.1)
+        (hy-test-helpers:should-last-message "Factorial of 5 = 120"))
+    (kill-buffer "DEMO")))
+
+(provide 'hib-kbd-tests)
+;;; hib-kbd-tests.el ends here
diff --git a/test/hib-social-tests.el b/test/hib-social-tests.el
new file mode 100644
index 0000000..690944f
--- /dev/null
+++ b/test/hib-social-tests.el
@@ -0,0 +1,56 @@
+;;; hib-social-tests.el --- Test for hib-social      -*- lexical-binding: t; 
-*-
+
+;; Author: Mats Lidell <matsl@gnu.org>
+;;
+;; Orig-Date: 20-Feb-21 at 23:24:00
+;;
+;; Copyright (C) 2021  Free Software Foundation, Inc.
+;; See the "HY-COPY" file for license information.
+;;
+;; This file is part of GNU Hyperbole.
+
+;;; Commentary:
+
+;; 
+
+;;; Code:
+
+(require 'hib-social)
+
+;; Hib-social
+(defun hib-social-should-browse-twitter-url (url &optional new-window)
+  "Verify call with proper URL and optional NEW-WINDOW."
+  (should (equal url "https://twitter.com/search?q=@fsf";))
+  (should (equal new-window nil)))
+
+(ert-deftest hib-social-twitter-test ()
+  (with-temp-buffer
+    (insert "tw@fsf")
+    (goto-char 2)
+    (let ((browse-url-browser-function 'hib-social-should-browse-twitter-url))
+      (ibtypes::social-reference))))
+
+;; Github
+(defun hib-social-should-browse-github-url (url &optional new-window)
+  "Verify call with proper URL and optional NEW-WINDOW."
+  (should (equal url "https://github.com/rswgnu/hyperbole";))
+  (should (equal new-window nil)))
+
+(ert-deftest hib-github-user-default-test ()
+  (with-temp-buffer
+    (insert "gh#/hyperbole")
+    (goto-char 4)
+    (let ((browse-url-browser-function 'hib-social-should-browse-github-url)
+          (hibtypes-github-default-user "rswgnu"))
+      (ibtypes::social-reference))))
+
+(ert-deftest hib-github-ignore-default-test ()
+  (with-temp-buffer
+    (insert "gh#/rswgnu/hyperbole")
+    (goto-char 4)
+    (let ((browse-url-browser-function 'hib-social-should-browse-github-url)
+          (hibtypes-github-default-user "whatever"))
+      (ibtypes::social-reference))))
+
+(provide 'hib-social-tests)
+;;; hib-social-tests.el ends here
diff --git a/test/hibtypes-tests.el b/test/hibtypes-tests.el
new file mode 100644
index 0000000..71041ce
--- /dev/null
+++ b/test/hibtypes-tests.el
@@ -0,0 +1,249 @@
+;;; hibtypes-tests.el --- unit test for hib-kbd        -*- lexical-binding: t; 
-*-
+
+;; Author: Mats Lidell <matsl@gnu.org>
+;;
+;; Orig-Date: 20-Feb-21 at 23:45:00
+;;
+;; Copyright (C) 2021  Free Software Foundation, Inc.
+;; See the "HY-COPY" file for license information.
+;;
+;; This file is part of GNU Hyperbole.
+
+;;; Commentary:
+
+;; Helper functions
+
+;;; Code:
+
+(require 'ert)
+(require 'hib-kbd)
+(require 'info)
+(require 'el-mock)
+
+(load (expand-file-name "hy-test-helpers"
+                        (file-name-directory (or load-file-name
+                                                 default-directory))))
+(declare-function hy-test-helpers:consume-input-events "hy-test-helpers")
+(declare-function hy-test-helpers:should-last-message "hy-test-helpers")
+
+;; (ert-deftest org-link-outside-org-mode-test ()
+
+;; Mail address
+(ert-deftest mail-address-at-p-test ()
+  (with-temp-buffer
+    (insert "someone@example.org")
+    (goto-char 4)
+    (should (mail-address-at-p))))
+
+(ert-deftest mail-address-at-p-no-mail-should-fail-test ()
+  (with-temp-buffer
+    (insert "someone@example.test")
+    (goto-char 4)
+    (should (not (mail-address-at-p)))))
+
+(ert-deftest ibtypes::mail-address-test ()
+  (unwind-protect
+      (with-temp-buffer
+        (insert "receiver@mail.org")
+        (goto-char 2)
+        (ibtypes::mail-address)
+        (should (string= "*mail*" (buffer-name))))
+    (kill-buffer "*mail*")))
+
+;; Path name
+(ert-deftest ibtypes::pathname-test ()
+  (unwind-protect
+      (with-temp-buffer
+        (insert (format "\"%s\"" (expand-file-name "DEMO" hyperb:dir)))
+        (goto-char 2)
+        (ibtypes::pathname)
+        (should (string= "DEMO" (buffer-name))))
+    (kill-buffer "DEMO")))
+
+(ert-deftest ibtypes::pathname-lisp-variable-test ()
+  (unwind-protect
+      (with-temp-buffer
+        (insert "\"${hyperb:dir}/DEMO\"")
+        (goto-char 2)
+        (ibtypes::pathname)
+        (should (string= "DEMO" (buffer-name))))
+    (kill-buffer "DEMO")))
+
+(ert-deftest ibtypes::pathname-env-variable-test ()
+  (unwind-protect
+      (with-temp-buffer
+        (insert "\"${HOME}\"")
+        (goto-char 2)
+        (ibtypes::pathname)
+        (should (equal major-mode 'dired-mode))
+        (should (= 0 (string-match "/home/.*" (file-truename 
default-directory)))))
+    nil))
+
+(ert-deftest ibtypes::pathname-emacs-lisp-file-test ()
+  (unwind-protect
+      (with-temp-buffer
+        (insert "\"hyperbole.el\"")
+        (goto-char 2)
+        (ibtypes::pathname)
+        (should (equal major-mode 'emacs-lisp-mode))
+        (should (string= "hyperbole.el" (buffer-name)))))
+  (kill-buffer "hyperbole.el"))
+
+;; Function in buffer XEmac functionality. Is there somethign similar in Emacs?
+
+;; ibtypes::annot-bib
+(ert-deftest ibtypes::annot-bib-test ()
+  (unwind-protect
+      (progn
+        (hypb:display-file-with-logo (expand-file-name "DEMO" hyperb:dir))
+        (re-search-forward "\\[FSF 19\\]")
+        (backward-char 1)
+        (ibtypes::annot-bib)
+        (should (looking-at "\\[FSF 19\\] Free Software Foundation"))
+        (forward-line -2)
+        (should (looking-at "\\* References")))
+    (kill-buffer "DEMO")))
+
+;; markdown
+; Can't find out how to use the markdown-internal-link ibtypes!?
+
+;; rfc-toc
+; Need rfc format of test buffer
+
+;; id-cflow
+; Need cross reference table built by externaö cxref program
+
+;; ctags
+; Seems ctags -v does not give the proper answer
+(ert-deftest ibtypes::ctags-vgrind-test ()
+  (unwind-protect
+      (with-temp-buffer
+        (insert "hy-test-helpers:consume-input-events hy-test-helpers.el 20\n")
+        (goto-char (point-min))
+        (forward-char 4)
+        (let ((default-directory (concat default-directory "test")))
+          (ibtypes::ctags)
+          (set-buffer "hy-test-helpers.el")
+          (should (looking-at "(defun hy-test-helpers:consume-input-events"))))
+    (kill-buffer "hy-test-helpers.el")))
+
+;; etags
+(ert-deftest ibtypes::etags-test ()
+  (unwind-protect
+      (with-temp-buffer
+        (insert "\n")
+        (insert "hy-test-helpers.el,103\n")
+        (insert "(defun hy-test-helpers:consume-input-events 20,359\n")
+        (rename-buffer (concat "TAGS" (buffer-name)))
+        (goto-char (point-min))
+        (forward-line 2)
+        (forward-char 10)
+        (let ((default-directory (concat default-directory "test")))
+          (ibtypes::etags)
+          (set-buffer "hy-test-helpers.el")
+          (should (looking-at "(defun hy-test-helpers:consume-input-events"))))
+    (kill-buffer "hy-test-helpers.el")))
+
+;; cscope
+
+;; text-toc
+(ert-deftest ibtypes::text-toc-test ()
+  (unwind-protect
+      (progn
+        (hypb:display-file-with-logo (expand-file-name "DEMO" hyperb:dir))
+        (goto-char (point-min))
+        (re-search-forward " \* Koutl")
+        (ibtypes::text-toc)
+        (should (bolp))
+        (should (looking-at "^* Koutliner")))
+    (kill-buffer "DEMO")))
+
+;; dir-summary
+(ert-deftest ibtypes::dir-summary-test ()
+  (unwind-protect
+      (progn
+        (find-file (expand-file-name "MANIFEST" hyperb:dir))
+        (goto-char (point-min))
+        (re-search-forward "HY-ABOUT")
+        (forward-char -2)
+        (let ((hpath:display-where 'this-window))
+          (ibtypes::dir-summary)
+          (should (string= "HY-ABOUT" (buffer-name)))))
+    (progn
+      (kill-buffer "MANIFEST")
+      (kill-buffer "HY-ABOUT"))))
+
+;; hib-debug
+
+;; hib-kbd
+
+;; rfc
+(ert-deftest ibtypes::rfc-test ()
+  (dolist (rfc '("RFC822" "RFC-822" "rfc 822"))
+    (with-temp-buffer
+      (insert rfc)
+      (goto-char 2)
+      (with-mock
+        (mock (actypes::link-to-rfc "822") => t)
+        (should (ibtypes::rfc))))))
+
+;; man-apropos
+(ert-deftest ibtypes::man-apropos-test ()
+  (unwind-protect
+      (with-temp-buffer
+        (insert "rm (1)   - remove")
+        (goto-char 4)
+        (ibtypes::man-apropos)
+        (sit-for 0.2)
+        (set-buffer "*Man 1 rm*")
+        (should (looking-at "RM\(1\)")))
+    (kill-buffer "*Man 1 rm*")))
+
+
+;; klink
+
+;; hlink
+
+;; elink
+
+;; glink
+
+;; ilink
+
+;; ipython-stack-frame
+
+;; ripgrep-msg
+
+;; grep-msg
+
+;; debugger-source
+
+;; pathname-line-and-column
+
+;; elisp-compiler-msg
+
+;; patch-msg
+
+;; texinfo-ref
+
+;; info-node
+(ert-deftest ibtypes::info-node-test ()
+  "Should work with ibtypes::pathname but does not. Works with action-key!?"
+  (unwind-protect
+      (with-temp-buffer
+        (insert "\"(emacs)top\"")
+        (goto-char 6)
+        (ibtypes::Info-node)
+        (should (string= "*info*" (buffer-name))))
+    (kill-buffer "*info*")))
+
+;; hyp-address
+
+;; hyp-source
+
+;; action
+
+;; completion
+
+(provide 'hibtypes-tests)
+;;; hibtypes-tests.el ends here
diff --git a/test/hy-test-dependencies.el b/test/hy-test-dependencies.el
new file mode 100644
index 0000000..e06f2ec
--- /dev/null
+++ b/test/hy-test-dependencies.el
@@ -0,0 +1,27 @@
+;;; hy-test-dependencies.el --- Dependencies for running the tests  -*- 
lexical-binding: t; -*-
+
+;; Copyright (C) 2021  Mats Lidell
+
+;; Author: Mats Lidell <matsl@gnu.org>
+;;
+;; Orig-Date: 20-Feb-21 at 23:16:00
+;;
+;; Copyright (C) 2021  Free Software Foundation, Inc.
+;; See the "HY-COPY" file for license information.
+;;
+;; This file is part of GNU Hyperbole.
+
+;;; Commentary:
+;;
+;; Load prerequisites for running the tests.
+
+;;; Code:
+
+(package-initialize)
+(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/";))
+(unless (package-installed-p 'el-mock)
+  (package-refresh-contents)
+  (package-install 'el-mock))
+
+(provide 'hy-test-dependencies)
+;;; hy-test-dependencies.el ends here
diff --git a/test/hy-test-helpers.el b/test/hy-test-helpers.el
new file mode 100644
index 0000000..c5fe773
--- /dev/null
+++ b/test/hy-test-helpers.el
@@ -0,0 +1,33 @@
+;;; hy-test-helpers.el --- unit test helpers         -*- lexical-binding: t; 
-*-
+
+;; Author: Mats Lidell <matsl@gnu.org>
+;;
+;; Orig-Date: 30-Jan-21 at 12:00:00
+;;
+;; Copyright (C) 2021  Free Software Foundation, Inc.
+;; See the "HY-COPY" file for license information.
+;;
+;; This file is part of GNU Hyperbole.
+
+;;; Commentary:
+
+;;
+
+;;; Code:
+
+(require 'ert)
+
+(defun hy-test-helpers:consume-input-events ()
+  "Use recusive-edit to consume the events kbd-key generate."
+  (run-with-timer 0.1 nil (lambda () (if (< 0 (recursion-depth)) 
(exit-recursive-edit))))
+  (recursive-edit))
+
+(defun hy-test-helpers:should-last-message (msg)
+  "Verify last message is MSG."
+  (with-current-buffer "*Messages*"
+    (should (save-excursion
+              (goto-char (point-max))
+              (search-backward msg (- (point-max) 350))))))
+
+(provide 'hy-test-helpers)
+;;; hy-test-helpers.el ends here



reply via email to

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