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

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

[nongnu] elpa/toc-org c3a549fd96 012/128: add a couple of tests


From: ELPA Syncer
Subject: [nongnu] elpa/toc-org c3a549fd96 012/128: add a couple of tests
Date: Sun, 2 Jan 2022 09:59:06 -0500 (EST)

branch: elpa/toc-org
commit c3a549fd968202d0028087d7146dff447a424181
Author: Sergei Nosov <sergei.nosov@gmail.com>
Commit: Sergei Nosov <sergei.nosov@gmail.com>

    add a couple of tests
---
 .travis.yml | 10 ++++++++++
 org-toc.el  | 40 +++++++++++++++++++++++++++++++++++++++-
 2 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000000..efb9943f79
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,10 @@
+language: emacs-lisp
+before_install:
+  # PPA for stable Emacs packages
+  - sudo add-apt-repository -y ppa:cassou/emacs
+  # PPA for Emacs nightlies
+  - sudo add-apt-repository -y ppa:ubuntu-elisp/ppa
+  # Update and install the Emacs for our environment
+  - sudo apt-get update -qq
+  - sudo apt-get install -qq -yy emacs24-nox emacs24-el
+script: emacs -batch -l ert -l *.el -f ert-run-tests-batch-and-exit
\ No newline at end of file
diff --git a/org-toc.el b/org-toc.el
index 4ae1e55107..7e85aca1ac 100644
--- a/org-toc.el
+++ b/org-toc.el
@@ -50,6 +50,8 @@ files on GitHub)"
 ;; just in case, simple regexp "^*.*:toc:\\($\\|[^ ]*:$\\)"
 (defconst org-toc-org-toc-regexp 
"^*.*:toc\\([@_][0-9]\\|\\([@_][0-9][@_][a-zA-Z]+\\)\\)?:\\($\\|[^ ]*:$\\)"
   "Regexp to find the heading with the :toc: tag")
+(defconst org-toc-tags-regexp "\s*:[[:word:]:@]*:\s*$"
+  "Regexp to find tags on the line")
 (defconst org-toc-special-chars-regexp "[][~`!@#$%^&*()+={}|\:;\"'<,>.?/]"
   "Regexp with the special characters (which are omitted in hrefs
   by GitHub)")
@@ -86,12 +88,42 @@ tags."
       ;; TODO :export: and :noexport: tags semantic should be probably
       ;; implemented
       (goto-char (point-min))
-      (while (re-search-forward "\s*:[[:word:]:@]*:\s*$" nil t)
+      (while (re-search-forward org-toc-tags-regexp nil t)
         (replace-match "" nil nil))
 
       (buffer-substring-no-properties
        (point-min) (point-max)))))
 
+(ert-deftest org-toc-test-raw-toc ()
+  "Test the `org-toc-raw-toc' function"
+
+  (defun org-toc-test-raw-toc-gold-test (content gold)
+    (should (equal
+             (with-temp-buffer
+               (insert content)
+               (org-toc-raw-toc))
+             gold)))
+
+  (let ((beg "* About\n:TOC:\n drawer\n:END:\n\norg-toc is a utility to have 
an up-to-date table of contents in the\norg files without exporting (useful 
primarily for readme files on\nGitHub).\n\nIt is similar to the 
[[https://github.com/ardumont/markdown-toc][markdown-toc]] package, but works 
for org files.\n:TOC:\n  drawer\n:END:\n\n* Table of Contents                   
                                  ")
+        (gold "* About\n"))
+
+    ;; different TOC styles
+    (org-toc-test-raw-toc-gold-test (concat beg ":TOC:"         ) gold)
+    (org-toc-test-raw-toc-gold-test (concat beg ":TOC_1:"       ) gold)
+    (org-toc-test-raw-toc-gold-test (concat beg ":TOC_1_qqq:"   ) gold)
+    (org-toc-test-raw-toc-gold-test (concat beg ":TOC@1:"       ) gold)
+    (org-toc-test-raw-toc-gold-test (concat beg ":TOC@1@cxv:"   ) gold)
+    (org-toc-test-raw-toc-gold-test (concat beg ":TOC@1_hello:" ) gold)
+
+    ;; trailing symbols
+    (org-toc-test-raw-toc-gold-test (concat beg ":TOC@1_hello:" "\n\n\n") gold)
+    (org-toc-test-raw-toc-gold-test (concat beg ":TOC@1_hello:" "\n\n\nsdfd") 
gold))
+
+  ;; more complex case
+  (org-toc-test-raw-toc-gold-test
+   "* About\n:TOC:\n drawer\n:END:\n\norg-toc is a utility to have an 
up-to-date table of contents in the\norg files without exporting (useful 
primarily for readme files on\nGitHub).\n\nIt is similar to the 
[[https://github.com/ardumont/markdown-toc][markdown-toc]] package, but works 
for org files.\n:TOC:\n  drawer\n:END:\n\n* Table of Contents                   
                                  :TOC:\n - [[#about][About]]\n - 
[[#use][Use]]\n - [[#different-href-styles][Different href st [...]
+   "* About\n* Installation\n** via package.el\n** Manual\n* Use\n* Different 
href styles\n* Example\n"))
+
 (defun org-toc-hrefify-gh (str)
   "Given a heading, transform it into a href using the GitHub
 rules."
@@ -101,6 +133,12 @@ rules."
          )
     (concat "#" special-chars-fix)))
 
+(ert-deftest org-toc-test-hrefify-gh ()
+  "Test the `org-toc-hrefify-gh' function"
+  (should (equal (org-toc-hrefify-gh "About") "#about"))
+  (should (equal (org-toc-hrefify-gh "!h@#$%^&*(){}|][:;\"'/?.>,<`~") "#h"))
+  (should (equal (org-toc-hrefify-gh "!h@#$% ^&*(S){}|][:;\"'/?.>,<`~") 
"#h-s")))
+
 (defun org-toc-hrefify-org (str)
   "Given a heading, transform it into a href using the org-mode
 rules."



reply via email to

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