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

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

[nongnu] elpa/toc-org 95a558b362 099/128: add tests for markdown-style s


From: ELPA Syncer
Subject: [nongnu] elpa/toc-org 95a558b362 099/128: add tests for markdown-style syntax
Date: Sun, 2 Jan 2022 09:59:13 -0500 (EST)

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

    add tests for markdown-style syntax
---
 toc-org-test.el | 36 +++++++++++++++++++++++++++++-------
 1 file changed, 29 insertions(+), 7 deletions(-)

diff --git a/toc-org-test.el b/toc-org-test.el
index edbf1b4d71..16a0601c49 100644
--- a/toc-org-test.el
+++ b/toc-org-test.el
@@ -141,13 +141,15 @@
   (should (equal (toc-org-format-visible-link "Context Extraction Service 
[60%]") "Context Extraction Service")))
 
 (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))
-                                        nil
-                                        hash)
-                   "- [[ABOUT][About]]\n"))
-    (should (equal (gethash "ABOUT" hash) "About")))
+  (dolist (params '((nil . "- [[ABOUT][About]]\n") ('t . "- 
[About](ABOUT)\n")))
+    (let ((hash (make-hash-table :test 'equal)))
+      (should (equal (toc-org-hrefify-toc "* About\n"
+                                          (lambda (str &optional hash) (upcase 
str))
+                                          (car params)
+                                          hash)
+                     (cdr params)))
+      (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"
@@ -239,3 +241,23 @@
      "* H1\n* TODO H2\n* TOC           :TOC:\n \n"
      "* H1\n* TODO H2\n* TOC           :TOC:\n- [[#h1][H1]]\n- [[#h2][H2]]\n")
     ))
+
+(ert-deftest test-toc-org-insert-toc-markdown ()
+  "Test the `toc-org-insert-toc' function"
+
+  (defun test-toc-org-insert-toc-gold-test-markdown (content gold)
+    (with-temp-buffer
+      (markdown-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-markdown "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-markdown
+     (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  - [Go [...]
+    ))



reply via email to

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