[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."
- [nongnu] branch elpa/toc-org created (now a2cb4c254f), ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org cc367dee40 002/128: fix issues mentioned in the PR, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 1df1f58c5e 003/128: update readme, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 32441dd37e 007/128: add missing quotes to readme, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 928e215c13 001/128: init, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org b1fc800d3f 005/128: fix old name, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org a3db0cfc07 006/128: fix typo, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 49e3bcb8db 009/128: update readme with different href styles, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org c3a549fd96 012/128: add a couple of tests,
ELPA Syncer <=
- [nongnu] elpa/toc-org 9c5861ceee 004/128: add parent group to fix compilation warning, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 91670bcc41 014/128: add badges, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 8364e88da3 015/128: fix travis badge, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 381abe6c52 032/128: add a renaming note, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 99195a69fd 036/128: update MELPA badge, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 14daed1a53 040/128: make C-c C-o work with any href style, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 3421f6192d 038/128: add a rename note to the commentary, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org f345f768cb 051/128: Merge pull request #13 from JAremko/master, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org ac2c33dcf8 055/128: remove unnecessary spaces, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 1d52ece078 016/128: another fix to travis badge, ELPA Syncer, 2022/01/02