[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/toc-org ad3424d457 067/128: move tests to a separate file
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/toc-org ad3424d457 067/128: move tests to a separate file |
Date: |
Sun, 2 Jan 2022 09:59:10 -0500 (EST) |
branch: elpa/toc-org
commit ad3424d4575eb9d8235a44770e2e6dcca9abdd80
Author: Sergei Nosov <sergei.nosov@gmail.com>
Commit: Sergei Nosov <sergei.nosov@gmail.com>
move tests to a separate file
see https://github.com/snosov1/toc-org/issues/34
---
toc-org.el => toc-org-test.el | 363 +-----------------------------------------
toc-org.el | 159 +-----------------
2 files changed, 2 insertions(+), 520 deletions(-)
diff --git a/toc-org.el b/toc-org-test.el
similarity index 54%
copy from toc-org.el
copy to toc-org-test.el
index fe071ed5d7..7bf8233d14 100644
--- a/toc-org.el
+++ b/toc-org-test.el
@@ -1,151 +1,5 @@
-;;; toc-org.el --- add table of contents to org-mode files (formerly, org-toc)
-
-;; Copyright (C) 2014 Sergei Nosov
-
-;; Author: Sergei Nosov <sergei.nosov [at] gmail.com>
-;; Version: 1.0
-;; Keywords: org-mode org-toc toc-org org toc table of contents
-;; URL: https://github.com/snosov1/toc-org
-
-;; This program is free software; you can redistribute it and/or
-;; modify it under the terms of the GNU General Public License as
-;; published by the Free Software Foundation; either version 2, or (at
-;; your option) any later version.
-
-;; This program is distributed in the hope that it will be useful, but
-;; WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-;; General Public License for more details.
-
-;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
-
-;;; Commentary:
-
-;; toc-org helps you to have an up-to-date table of contents in org files
-;; without exporting (useful primarily for readme files on GitHub).
-
-;; NOTE: Previous name of the package is org-toc. It was changed because of a
-;; name conflict with one of the org contrib modules.
-
-;; After installation put into your .emacs file something like
-
-;; (if (require 'toc-org nil t)
-;; (add-hook 'org-mode-hook 'toc-org-enable)
-;; (warn "toc-org not found"))
-
-;; And every time you'll be saving an org file, the first headline with a :TOC:
-;; tag will be updated with the current table of contents.
-
-;; For details, see https://github.com/snosov1/toc-org
-
-;;; Code:
-
(require 'ert)
-(require 'org)
-
-(defgroup toc-org nil
- "toc-org is a utility to have an up-to-date table of contents
-in the org files without exporting (useful primarily for readme
-files on GitHub)"
- :group 'org)
-
-;; just in case, simple regexp "^*.*:toc:\\($\\|[^ ]*:$\\)"
-(defconst toc-org-toc-org-regexp
"^*.*:toc\\([@_][0-9]\\|\\([@_][0-9][@_][a-zA-Z]+\\)\\)?:\\($\\|[^ ]*?:$\\)"
- "Regexp to find the heading with the :toc: tag")
-(defconst toc-org-tags-regexp "\s*:[[:word:]:@]*:\s*$"
- "Regexp to find tags on the line")
-(defconst toc-org-states-regexp "^*+\s+\\(TODO\s+\\|DONE\s+\\)"
- "Regexp to find states on the line")
-(defconst toc-org-priorities-regexp "^*+\s+\\(\\[#.\\]\s+\\)"
- "Regexp to find states on the line")
-(defconst toc-org-links-regexp "\\[\\[\\(.*?\\)\\]\\[\\(.*?\\)\\]\\]"
- "Regexp to find states on the line")
-(defconst toc-org-special-chars-regexp "[^[:alnum:]_-]"
- "Regexp with the special characters (which are omitted in hrefs
- by GitHub)")
-(defconst toc-org-statistics-cookies-regexp
"\s*\\[[0-9]*\\(%\\|/[0-9]*\\)\\]\s*"
- "Regexp to find statistics cookies on the line")
-(defconst toc-org-leave-todo-regexp "^#\\+OPTIONS:.*\stodo:t[\s\n]"
- "Regexp to find the todo export setting")
-(defconst toc-org-drawer-regexp "^[ ]*:\\(\\(?:\\w\\|[-_]\\)+\\):[ ]*$"
- "Regexp to match org drawers. Note: generally, it should be
-equal to `org-drawer-regexp'. However, some older versions of
-org (notably, 8.2.10) restrict the values that can be placed
-between the colons. So, the value here is set explicitly.")
-
-(defcustom toc-org-max-depth 2
- "Maximum depth of the headings to use in the table of
-contents. The default of 2 uses only the highest level headings
-and their subheadings (one and two stars)."
- :group 'toc-org)
-
-(defcustom toc-org-hrefify-default "gh"
- "Default hrefify function to use."
- :group 'toc-org)
-
-(defcustom toc-org-enable-links-opening t
- "With this option, org-open-at-point (C-c C-o) should work on
-the TOC links (even if the style is different from org)."
- :group 'toc-org)
-
-(defvar-local toc-org-hrefify-hash nil
- "Buffer local hash-table that is used to enable links
-opening. The keys are hrefified headings, the values are original
-headings.")
-
-(defun toc-org-raw-toc ()
- "Return the \"raw\" table of contents of the current file,
-i.e. simply flush everything that's not a heading and strip
-auxiliary text."
- (let ((content (buffer-substring-no-properties
- (point-min) (point-max)))
- (leave-states-p nil))
- (with-temp-buffer
- (insert content)
-
- ;; set leave-states-p variable
- (goto-char (point-min))
- (when (re-search-forward toc-org-leave-todo-regexp nil t)
- (setq leave-states-p t))
-
- ;; keep only lines starting with *s
- (goto-char (point-min))
- (keep-lines "^\*+[ ]")
-
- ;; don't include the TOC itself
- (goto-char (point-min))
- (re-search-forward toc-org-toc-org-regexp nil t)
- (beginning-of-line)
- (delete-region (point) (progn (forward-line 1) (point)))
-
- ;; strip states
- (unless leave-states-p
- (goto-char (point-min))
- (while (re-search-forward toc-org-states-regexp nil t)
- (replace-match "" nil nil nil 1)))
-
- ;; strip priorities
- (goto-char (point-min))
- (while (re-search-forward toc-org-priorities-regexp nil t)
- (replace-match "" nil nil nil 1))
-
- ;; strip tags
- ;; TODO :export: and :noexport: tags semantic should be probably
- ;; implemented
- (goto-char (point-min))
- (while (re-search-forward toc-org-tags-regexp nil t)
- (replace-match "" nil nil))
-
- ;; flatten links
- (goto-char (point-min))
- (while (re-search-forward toc-org-links-regexp nil t)
- (replace-match "\\2" nil nil))
-
- (buffer-substring-no-properties
- (point-min) (point-max)))))
+(require 'toc-org)
(ert-deftest test-toc-org-raw-toc ()
"Test the `toc-org-raw-toc' function"
@@ -186,22 +40,6 @@ auxiliary text."
"* About\n:TOC:\n drawer\n:END:\n\n* Table of Contents
:TOC:\n - [[#about][About]]\n - [[#use][Use]]\n
- [[#different-href-styles][Different href styles]]\n -
[[#example][Example]]\n\n#+OPTIONS: num: nil todo:t |:t\n\n* Installation\n**
DONE via package.el\nThis is the simplest method if you have the package.el
module\n(built-in since Emacs 24.1) you can simply use =M-x
package-install=\nand then put the following snippet in your ~/. [...]
"* About\n* Installation\n** DONE via package.el\n** TODO Manual\n"))
-(defun toc-org-hrefify-gh (str &optional hash)
- "Given a heading, transform it into a href using the GitHub
-rules."
- (let* ((spc-fix (replace-regexp-in-string " " "-" str))
- (upcase-fix (replace-regexp-in-string "[A-Z]" 'downcase spc-fix t))
- (special-chars-fix (replace-regexp-in-string
toc-org-special-chars-regexp "" upcase-fix t))
- (hrefified-base (concat "#" special-chars-fix))
- (hrefified hrefified-base)
- (idx 0))
- ;; try appending -1, -2, -3, etc. until unique href is found
- (when hash
- (while (gethash hrefified hash)
- (setq hrefified
- (concat hrefified-base "-" (number-to-string (setq idx (1+
idx)))))))
- hrefified))
-
(ert-deftest test-toc-org-hrefify-gh ()
"Test the `toc-org-hrefify-gh' function"
(should (equal (toc-org-hrefify-gh "About") "#about"))
@@ -221,18 +59,6 @@ rules."
(puthash "#about-2" "About" hash)
(should (equal (toc-org-hrefify-gh "About" hash) "#about-3"))))
-(defun toc-org-format-visible-link (str)
- "Formats the visible text of the link."
- (with-temp-buffer
- (insert str)
-
- ;; strip statistics cookies
- (goto-char (point-min))
- (while (re-search-forward toc-org-statistics-cookies-regexp nil t)
- (replace-match "" nil nil))
- (buffer-substring-no-properties
- (point-min) (point-max))))
-
(ert-deftest test-toc-org-format-visible-link ()
"Test the `toc-org-format-visible-link' function"
(should (equal (toc-org-format-visible-link "About") "About"))
@@ -241,81 +67,6 @@ rules."
(should (equal (toc-org-format-visible-link "Context Extraction Service
[3/5]") "Context Extraction Service"))
(should (equal (toc-org-format-visible-link "Context Extraction Service
[60%]") "Context Extraction Service")))
-(defun toc-org-hrefify-org (str &optional hash)
- "Given a heading, transform it into a href using the org-mode
-rules."
- (toc-org-format-visible-link str))
-
-(defun toc-org-unhrefify (type path)
- "Looks for a value in toc-org-hrefify-hash using path as a key."
- (let ((ret-type type)
- (ret-path path)
- (original-path (and (not (eq toc-org-hrefify-hash nil))
- (gethash
- (concat
- ;; Org 8.3 and above provides type as "custom-id"
- ;; and strips the leading hash symbol
- (if (equal type "custom-id") "#" "")
- (substring-no-properties path))
- toc-org-hrefify-hash
- nil))))
- (when toc-org-enable-links-opening
- (when original-path
- ;; Org 8.2 and below provides type as "thisfile"
- (when (equal type "thisfile")
- (setq ret-path original-path))
- (when (equal type "custom-id")
- (setq ret-type "fuzzy")
- (setq ret-path original-path))))
- (cons ret-type ret-path)))
-
-(defun toc-org-hrefify-toc (toc hrefify &optional hash)
- "Format the raw `toc' using the `hrefify' function to transform
-each heading into a link."
- (with-temp-buffer
- (insert toc)
- (goto-char (point-min))
-
- (while
- (progn
- (when (looking-at "\\*")
- (delete-char 1)
-
- (while (looking-at "\\*")
- (delete-char 1)
- (insert (make-string
- (+ 2 (or (bound-and-true-p org-list-indent-offset) 0))
- ?\s)))
-
- (skip-chars-forward " ")
- (insert "- ")
-
- (save-excursion
- (delete-trailing-whitespace (point) (line-end-position)))
-
- (let* ((beg (point))
- (end (line-end-position))
- (heading (buffer-substring-no-properties
- beg end))
- (hrefified (funcall hrefify heading hash)))
- (insert "[[")
- (insert hrefified)
- (insert "][")
- (insert
- (toc-org-format-visible-link
- (buffer-substring-no-properties
- (point) (line-end-position))))
- (delete-region (point) (line-end-position))
- (insert "]]")
-
- ;; maintain the hash table, if provided
- (when hash
- (puthash hrefified heading hash)))
- (= 0 (forward-line 1)))))
-
- (buffer-substring-no-properties
- (point-min) (point-max))))
-
(ert-deftest test-toc-org-hrefify-toc ()
(let ((hash (make-hash-table :test 'equal)))
(should (equal (toc-org-hrefify-toc "* About\n"
@@ -341,20 +92,6 @@ each heading into a link."
(should (equal (gethash "DIFFERENT HREF STYLES" hash) "Different href
styles"))
(should (equal (gethash "EXAMPLE" hash) "Example"))))
-(defun toc-org-flush-subheadings (toc max-depth)
- "Flush subheadings of the raw `toc' deeper than `max-depth'."
- (with-temp-buffer
- (insert toc)
- (goto-char (point-min))
-
- (let ((re "^"))
- (dotimes (i (1+ max-depth))
- (setq re (concat re "\\*")))
- (flush-lines re))
-
- (buffer-substring-no-properties
- (point-min) (point-max))))
-
(ert-deftest test-toc-org-flush-subheadings ()
(should (equal (toc-org-flush-subheadings "* About\n" 0)
""))
@@ -372,97 +109,6 @@ each heading into a link."
(should (equal (toc-org-flush-subheadings "* About\n* Installation\n** via
package.el\n** Manual\n* Use\n* Different href styles\n* Example\n" 3)
"* About\n* Installation\n** via package.el\n** Manual\n*
Use\n* Different href styles\n* Example\n")))
-(defun toc-org-insert-toc (&optional dry-run)
- "Looks for a headline with the TOC tag and updates it with the
-current table of contents.
-
-If optional second argument DRY-RUN is provided, then the buffer
-is not modified at all. Only the internal hash-table is updated
-to enable `org-open-at-point' for TOC links.
-
-To add a TOC tag, you can use the command
-`org-set-tags-command' (C-c C-q).
-
-In addition to the simple :TOC: tag, you can also use the
-following tag formats:
-
-- :TOC_2: - sets the max depth of the headlines in the table of
- contents to 2 (the default)
-
-- :TOC_2_gh: - sets the max depth as in above and also uses the
- GitHub-style hrefs in the table of contents (this style is
- default). The other supported href style is 'org', which is the
- default org style."
-
- (interactive)
- (when (eq major-mode 'org-mode)
- (save-excursion
- (goto-char (point-min))
- (let ((case-fold-search t))
- ;; find the first heading with the :TOC: tag
- (when (re-search-forward toc-org-toc-org-regexp (point-max) t)
- (let* ((tag (match-string 1))
- (depth (if tag
- (- (aref tag 1) ?0) ;; is there a better way to
convert char to number?
- toc-org-max-depth))
- (hrefify-tag (if (and tag (>= (length tag) 4))
- (downcase (substring tag 3))
- toc-org-hrefify-default))
- (hrefify-string (concat "toc-org-hrefify-" hrefify-tag))
- (hrefify (intern-soft hrefify-string)))
- (if hrefify
- (let ((new-toc
- (toc-org-hrefify-toc
- (toc-org-flush-subheadings (toc-org-raw-toc) depth)
- hrefify
- (when toc-org-hrefify-hash
- (clrhash toc-org-hrefify-hash)))))
- (unless dry-run
- (newline (forward-line 1))
-
- ;; skip drawers
- (let ((end
- (save-excursion ;; limit to next heading
- (search-forward-regexp "^\\*" (point-max)
'skip))))
- (while (re-search-forward toc-org-drawer-regexp end t)
- (skip-chars-forward "[:space:]")))
- (beginning-of-line)
-
- ;; insert newline if TOC is currently empty
- (when (looking-at "^\\*")
- (open-line 1))
-
- ;; find TOC boundaries
- (let ((beg (point))
- (end
- (save-excursion
- (when (search-forward-regexp "^\\*" (point-max)
'skip)
- (forward-line -1))
- (end-of-line)
- (point))))
- ;; update the TOC, but only if it's actually different
- ;; from the current one
- (unless (equal
- (buffer-substring-no-properties beg end)
- new-toc)
- (delete-region beg end)
- (insert new-toc)))))
- (message (concat "Hrefify function " hrefify-string " is not
found")))))))))
-
-;;;###autoload
-(defun toc-org-enable ()
- "Enable toc-org in this buffer."
- (add-hook 'before-save-hook 'toc-org-insert-toc nil t)
-
- ;; conservatively set org-link-translation-function
- (when (and (equal toc-org-enable-links-opening t)
- (or
- (not (fboundp org-link-translation-function))
- (equal org-link-translation-function 'toc-org-unhrefify)))
- (setq toc-org-hrefify-hash (make-hash-table :test 'equal))
- (setq org-link-translation-function 'toc-org-unhrefify)
- (toc-org-insert-toc t)))
-
(ert-deftest test-toc-org-insert-toc ()
"Test the `toc-org-insert-toc' function"
@@ -510,10 +156,3 @@ following tag formats:
"* H1\n* TODO H2\n* TOC :TOC:\n \n"
"* H1\n* TODO H2\n* TOC :TOC:\n - [[#h1][H1]]\n -
[[#h2][H2]]\n")
))
-
-;; Local Variables:
-;; compile-command: "emacs -batch -l ert -l *.el -f
ert-run-tests-batch-and-exit && emacs -batch -f batch-byte-compile *.el 2>&1 |
sed -n '/Warning\|Error/p' | xargs -r ls"
-;; End:
-
-(provide 'toc-org)
-;;; toc-org.el ends here
diff --git a/toc-org.el b/toc-org.el
index fe071ed5d7..1706f0ff02 100644
--- a/toc-org.el
+++ b/toc-org.el
@@ -43,7 +43,6 @@
;;; Code:
-(require 'ert)
(require 'org)
(defgroup toc-org nil
@@ -147,45 +146,6 @@ auxiliary text."
(buffer-substring-no-properties
(point-min) (point-max)))))
-(ert-deftest test-toc-org-raw-toc ()
- "Test the `toc-org-raw-toc' function"
-
- (defun test-toc-org-raw-toc-gold-test (content gold)
- (should (equal
- (with-temp-buffer
- (insert content)
- (toc-org-raw-toc))
- gold)))
- (declare-function test-toc-org-raw-toc-gold-test "toc-org") ;; suppress
compiler warning
-
- (let ((beg "* TODO [[http://somewhere.com][About]]\n:TOC:\n
drawer\n:END:\n\ntoc-org 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
- (test-toc-org-raw-toc-gold-test (concat beg ":TOC:" ) gold)
- (test-toc-org-raw-toc-gold-test (concat beg ":TOC_1:" ) gold)
- (test-toc-org-raw-toc-gold-test (concat beg ":TOC_1_qqq:" ) gold)
- (test-toc-org-raw-toc-gold-test (concat beg ":TOC@1:" ) gold)
- (test-toc-org-raw-toc-gold-test (concat beg ":TOC@1@cxv:" ) gold)
- (test-toc-org-raw-toc-gold-test (concat beg ":TOC@1_hello:" ) gold)
-
- ;; trailing symbols
- (test-toc-org-raw-toc-gold-test (concat beg ":TOC@1_hello:" "\n\n\n") gold)
- (test-toc-org-raw-toc-gold-test (concat beg ":TOC@1_hello:" "\n\n\nsdfd")
gold))
-
- ;; more complex cases
- (test-toc-org-raw-toc-gold-test
- "* About\n:TOC:\n drawer\n:END:\n\ntoc-org 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")
-
- (test-toc-org-raw-toc-gold-test
- "* About\n:TOC:\n drawer\n:END:\n\n* Table of Contents
:TOC:\n - [[#about][About]]\n - [[#use][Use]]\n
- [[#different-href-styles][Different href styles]]\n -
[[#example][Example]]\n\n#+OPTIONS: todo:t\n\n* Installation\n** DONE via
package.el\nThis is the simplest method if you have the package.el
module\n(built-in since Emacs 24.1) you can simply use =M-x
package-install=\nand then put the following snippet in your ~/.emacs file\n#
[...]
- "* About\n* Installation\n** DONE via package.el\n** TODO Manual\n")
-
- (test-toc-org-raw-toc-gold-test
- "* About\n:TOC:\n drawer\n:END:\n\n* Table of Contents
:TOC:\n - [[#about][About]]\n - [[#use][Use]]\n
- [[#different-href-styles][Different href styles]]\n -
[[#example][Example]]\n\n#+OPTIONS: num: nil todo:t |:t\n\n* Installation\n**
DONE via package.el\nThis is the simplest method if you have the package.el
module\n(built-in since Emacs 24.1) you can simply use =M-x
package-install=\nand then put the following snippet in your ~/. [...]
- "* About\n* Installation\n** DONE via package.el\n** TODO Manual\n"))
-
(defun toc-org-hrefify-gh (str &optional hash)
"Given a heading, transform it into a href using the GitHub
rules."
@@ -202,25 +162,6 @@ rules."
(concat hrefified-base "-" (number-to-string (setq idx (1+
idx)))))))
hrefified))
-(ert-deftest test-toc-org-hrefify-gh ()
- "Test the `toc-org-hrefify-gh' function"
- (should (equal (toc-org-hrefify-gh "About") "#about"))
- (should (equal (toc-org-hrefify-gh "!h@#$%^&*(){}|][:;\"'/?.>,<`~") "#h"))
- (should (equal (toc-org-hrefify-gh "!h@#$% ^&*(S){}|][:;\"'/?.>,<`~")
"#h-s"))
- (should (equal (toc-org-hrefify-gh "[60%] Context Extraction Service [60%]
[3/5]") "#60-context-extraction-service-60-35"))
- (should (equal (toc-org-hrefify-gh "Context Extraction Service [60%] [3/5]")
"#context-extraction-service-60-35"))
- (should (equal (toc-org-hrefify-gh "Context Extraction Service [3/5]")
"#context-extraction-service-35"))
- (should (equal (toc-org-hrefify-gh "Context Extraction Service [60%]")
"#context-extraction-service-60"))
-
- (let ((hash (make-hash-table :test 'equal)))
- (should (equal (toc-org-hrefify-gh "About" hash) "#about"))
- (puthash "#about" "About" hash)
- (should (equal (toc-org-hrefify-gh "About" hash) "#about-1"))
- (puthash "#about-1" "About" hash)
- (should (equal (toc-org-hrefify-gh "About" hash) "#about-2"))
- (puthash "#about-2" "About" hash)
- (should (equal (toc-org-hrefify-gh "About" hash) "#about-3"))))
-
(defun toc-org-format-visible-link (str)
"Formats the visible text of the link."
(with-temp-buffer
@@ -233,14 +174,6 @@ rules."
(buffer-substring-no-properties
(point-min) (point-max))))
-(ert-deftest test-toc-org-format-visible-link ()
- "Test the `toc-org-format-visible-link' function"
- (should (equal (toc-org-format-visible-link "About") "About"))
- (should (equal (toc-org-format-visible-link "[60%] Context Extraction
Service [60%] [3/5]") "Context Extraction Service"))
- (should (equal (toc-org-format-visible-link "Context Extraction Service
[60%] [3/5]") "Context Extraction Service"))
- (should (equal (toc-org-format-visible-link "Context Extraction Service
[3/5]") "Context Extraction Service"))
- (should (equal (toc-org-format-visible-link "Context Extraction Service
[60%]") "Context Extraction Service")))
-
(defun toc-org-hrefify-org (str &optional hash)
"Given a heading, transform it into a href using the org-mode
rules."
@@ -316,31 +249,6 @@ each heading into a link."
(buffer-substring-no-properties
(point-min) (point-max))))
-(ert-deftest test-toc-org-hrefify-toc ()
- (let ((hash (make-hash-table :test 'equal)))
- (should (equal (toc-org-hrefify-toc "* About\n"
- (lambda (str &optional hash) (upcase
str))
- hash)
- " - [[ABOUT][About]]\n"))
- (should (equal (gethash "ABOUT" hash) "About")))
- ;; check trailing space: https://github.com/snosov1/toc-org/pull/31
- (let ((hash (make-hash-table :test 'equal)))
- (should (equal (toc-org-hrefify-toc "* About \n"
- (lambda (str &optional hash) (upcase
str))
- hash)
- " - [[ABOUT][About]]\n"))
- (should (equal (gethash "ABOUT" hash) "About")))
- (let ((hash (make-hash-table :test 'equal)))
- (should (equal (toc-org-hrefify-toc "* About\n* Installation\n** via
package.el\n** Manual\n* Use\n* Different href styles\n* Example\n" (lambda
(str &optional hash) (upcase str)) hash)
- " - [[ABOUT][About]]\n - [[INSTALLATION][Installation]]\n
- [[VIA PACKAGE.EL][via package.el]]\n - [[MANUAL][Manual]]\n -
[[USE][Use]]\n - [[DIFFERENT HREF STYLES][Different href styles]]\n -
[[EXAMPLE][Example]]\n"))
- (should (equal (gethash "ABOUT" hash) "About"))
- (should (equal (gethash "INSTALLATION" hash) "Installation"))
- (should (equal (gethash "VIA PACKAGE.EL" hash) "via package.el"))
- (should (equal (gethash "MANUAL" hash) "Manual"))
- (should (equal (gethash "USE" hash) "Use"))
- (should (equal (gethash "DIFFERENT HREF STYLES" hash) "Different href
styles"))
- (should (equal (gethash "EXAMPLE" hash) "Example"))))
-
(defun toc-org-flush-subheadings (toc max-depth)
"Flush subheadings of the raw `toc' deeper than `max-depth'."
(with-temp-buffer
@@ -355,23 +263,6 @@ each heading into a link."
(buffer-substring-no-properties
(point-min) (point-max))))
-(ert-deftest test-toc-org-flush-subheadings ()
- (should (equal (toc-org-flush-subheadings "* About\n" 0)
- ""))
- (should (equal (toc-org-flush-subheadings "* About\n" 1)
- "* About\n"))
- (should (equal (toc-org-flush-subheadings "* About\n" 2)
- "* About\n"))
-
- (should (equal (toc-org-flush-subheadings "* About\n* Installation\n** via
package.el\n** Manual\n* Use\n* Different href styles\n* Example\n" 0)
- ""))
- (should (equal (toc-org-flush-subheadings "* About\n* Installation\n** via
package.el\n** Manual\n* Use\n* Different href styles\n* Example\n" 1)
- "* About\n* Installation\n* Use\n* Different href styles\n*
Example\n"))
- (should (equal (toc-org-flush-subheadings "* About\n* Installation\n** via
package.el\n** Manual\n* Use\n* Different href styles\n* Example\n" 2)
- "* About\n* Installation\n** via package.el\n** Manual\n*
Use\n* Different href styles\n* Example\n"))
- (should (equal (toc-org-flush-subheadings "* About\n* Installation\n** via
package.el\n** Manual\n* Use\n* Different href styles\n* Example\n" 3)
- "* About\n* Installation\n** via package.el\n** Manual\n*
Use\n* Different href styles\n* Example\n")))
-
(defun toc-org-insert-toc (&optional dry-run)
"Looks for a headline with the TOC tag and updates it with the
current table of contents.
@@ -463,56 +354,8 @@ following tag formats:
(setq org-link-translation-function 'toc-org-unhrefify)
(toc-org-insert-toc t)))
-(ert-deftest test-toc-org-insert-toc ()
- "Test the `toc-org-insert-toc' function"
-
- (defun test-toc-org-insert-toc-gold-test (content gold)
- (with-temp-buffer
- (org-mode)
- (insert content)
- (toc-org-insert-toc)
- (should (equal
- (buffer-substring-no-properties
- (point-min) (point-max))
- gold))))
- (declare-function test-toc-org-insert-toc-gold-test "toc-org") ;; suppress
compiler warning
-
- (let ((beg "* About\n:TOC:\n drawer\n:END:\n\ntoc-org 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* Hello\n** Good-bye\n*** Salut\n*
Table of Contents "))
- (test-toc-org-insert-toc-gold-test
- (concat beg ":TOC:")
- "* About\n:TOC:\n drawer\n:END:\n\ntoc-org 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* Hello\n** Good-bye\n*** Salut\n*
Table of Contents :TOC:\n -
[[#about][About]]\n - [[#hello][Hello]]\n - [[#g [...]
-
- (test-toc-org-insert-toc-gold-test
- (concat beg ":TOC_1:")
- "* About\n:TOC:\n drawer\n:END:\n\ntoc-org 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* Hello\n** Good-bye\n*** Salut\n*
Table of Contents :TOC_1:\n
- [[#about][About]]\n - [[#hello][Hello]]\n")
-
- (test-toc-org-insert-toc-gold-test
- (concat beg ":TOC_3:")
- "* About\n:TOC:\n drawer\n:END:\n\ntoc-org 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* Hello\n** Good-bye\n*** Salut\n*
Table of Contents :TOC_3:\n
- [[#about][About]]\n - [[#hello][Hello]]\n - [[ [...]
-
- (test-toc-org-insert-toc-gold-test
- (concat beg ":TOC_1_org:")
- "* About\n:TOC:\n drawer\n:END:\n\ntoc-org 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* Hello\n** Good-bye\n*** Salut\n*
Table of Contents
:TOC_1_org:\n - [[About][About]]\n - [[Hello][Hello]]\n")
-
- (test-toc-org-insert-toc-gold-test
- (concat beg ":TOC_3_org:")
- "* About\n:TOC:\n drawer\n:END:\n\ntoc-org 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* Hello\n** Good-bye\n*** Salut\n*
Table of Contents
:TOC_3_org:\n - [[About][About]]\n - [[Hello][Hello]]\n - [...]
-
- (test-toc-org-insert-toc-gold-test
- (concat beg ":TOC:\n:PROPERTIES:\n:VISIBILITY: content\n:END:\n")
- "* About\n:TOC:\n drawer\n:END:\n\ntoc-org 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* Hello\n** Good-bye\n*** Salut\n*
Table of Contents
:TOC:\n:PROPERTIES:\n:VISIBILITY: content\n:END:\n - [[#abou [...]
-
- (test-toc-org-insert-toc-gold-test
- "* H1\n* H2\n* TOC :TOC:\n - [[#header-1][Header 1]]\n -
[[#header-2][Header 2]]\n"
- "* H1\n* H2\n* TOC :TOC:\n - [[#h1][H1]]\n - [[#h2][H2]]\n")
-
- (test-toc-org-insert-toc-gold-test
- "* H1\n* TODO H2\n* TOC :TOC:\n \n"
- "* H1\n* TODO H2\n* TOC :TOC:\n - [[#h1][H1]]\n -
[[#h2][H2]]\n")
- ))
-
;; Local Variables:
-;; compile-command: "emacs -batch -l ert -l *.el -f
ert-run-tests-batch-and-exit && emacs -batch -f batch-byte-compile *.el 2>&1 |
sed -n '/Warning\|Error/p' | xargs -r ls"
+;; compile-command: "emacs -batch -l ert -l *.el -l *-test.el -f
ert-run-tests-batch-and-exit && emacs -batch -f batch-byte-compile *.el 2>&1 |
sed -n '/Warning\|Error/p' | xargs -r ls"
;; End:
(provide 'toc-org)
- [nongnu] elpa/toc-org fdfb7574dc 068/128: fix travis build, (continued)
- [nongnu] elpa/toc-org fdfb7574dc 068/128: fix travis build, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 40c6754d9f 083/128: replacs string-join with mapconcat, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 356b3fbb89 101/128: Define fake markdown mode in tests, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 2c4ff18a4e 092/128: document quote functionality, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 4315afd2a4 095/128: fix readme, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org cf4a624b78 122/128: Add license file with GPLv3, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 2539b4be40 097/128: add test for parenthesis in custom TODO words declaration, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org f13f79737a 020/128: Wrap test call with `(eval-after-load "ert-autoloads"...), ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org e9cf57041a 008/128: fix heading regexp, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org abbcb67166 011/128: allow _ as seprartor, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org ad3424d457 067/128: move tests to a separate file,
ELPA Syncer <=
- [nongnu] elpa/toc-org 5a8a3f9b3a 080/128: Merge pull request #42 from snosov1/remove-opening-space, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org aa52bd036d 071/128: handle headlines with COMMENT, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org d30b57f16d 077/128: Merge pull request #40 from alphapapa/update-primary-docstring, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 37f3bf2733 112/128: Add tests for the case-sensitive COMMENT regexp, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 4d259c9cea 086/128: Merge pull request #51 from snosov1/work-in-derived-modes, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org cd1868787c 087/128: Fix Emacs 26 warning, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 3315ef6c96 106/128: Merge pull request #66 from snosov1/enable-toc-org-for-markdown, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 9fefa63d42 119/128: Merge pull request #75 from Alexander-Miller/local-offset, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 7ff7abb015 029/128: update documentation on org-toc-2 in the source, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org df4ad6ff15 121/128: Merge pull request #76 from snosov1/revert-75-local-offset, ELPA Syncer, 2022/01/02