branch: elpa/toc-org
commit da99c5d80155331a4376c95b419b1d41bf0f96f0
Author: Sergei Nosov <[email protected]>
Commit: Sergei Nosov <[email protected]>

    require ert
---
 org-toc.el | 114 ++++++++++++++++++++++++++++++++-----------------------------
 1 file changed, 59 insertions(+), 55 deletions(-)

diff --git a/org-toc.el b/org-toc.el
index e03f292ccb..101112a122 100644
--- a/org-toc.el
+++ b/org-toc.el
@@ -96,35 +96,36 @@ tags."
        (point-min) (point-max)))))
 
 (eval-after-load "ert-autoloads"
-  (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  [...]
-     "* About\n* Installation\n** via package.el\n** Manual\n* Use\n* 
Different href styles\n* Example\n")))
+  (when (require 'ert nil t)
+    (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 hre [...]
+       "* 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
@@ -135,11 +136,12 @@ rules."
     (concat "#" special-chars-fix)))
 
 (eval-after-load "ert-autoloads"
-  (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"))))
+  (when (require 'ert nil t)
+    (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
@@ -180,11 +182,12 @@ each heading into a link."
      (point-min) (point-max))))
 
 (eval-after-load "ert-autoloads"
-  (ert-deftest org-toc-test-hrefify-toc ()
-    (should (equal (org-toc-hrefify-toc "* About\n" 'upcase)
-                   " - [[ABOUT][About]]\n"))
-    (should (equal (org-toc-hrefify-toc "* About\n* Installation\n** via 
package.el\n** Manual\n* Use\n* Different href styles\n* Example\n" 'upcase)
-                   " - [[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"))))
+  (when (require 'ert nil t)
+    (ert-deftest org-toc-test-hrefify-toc ()
+      (should (equal (org-toc-hrefify-toc "* About\n" 'upcase)
+                     " - [[ABOUT][About]]\n"))
+      (should (equal (org-toc-hrefify-toc "* About\n* Installation\n** via 
package.el\n** Manual\n* Use\n* Different href styles\n* Example\n" 'upcase)
+                     " - [[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")))))
 
 (defun org-toc-flush-subheadings (toc max-depth)
   "Flush subheadings of the raw `toc' deeper than `max-depth'."
@@ -201,22 +204,23 @@ each heading into a link."
      (point-min) (point-max))))
 
 (eval-after-load "ert-autoloads"
-  (ert-deftest org-toc-test-flush-subheadings ()
-    (should (equal (org-toc-flush-subheadings "* About\n" 0)
-                   ""))
-    (should (equal (org-toc-flush-subheadings "* About\n" 1)
-                   "* About\n"))
-    (should (equal (org-toc-flush-subheadings "* About\n" 2)
-                   "* About\n"))
-
-    (should (equal (org-toc-flush-subheadings "* About\n* Installation\n** via 
package.el\n** Manual\n* Use\n* Different href styles\n* Example\n" 0)
-                   ""))
-    (should (equal (org-toc-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 (org-toc-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 (org-toc-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"))))
+  (when (require 'ert nil t)
+    (ert-deftest org-toc-test-flush-subheadings ()
+      (should (equal (org-toc-flush-subheadings "* About\n" 0)
+                     ""))
+      (should (equal (org-toc-flush-subheadings "* About\n" 1)
+                     "* About\n"))
+      (should (equal (org-toc-flush-subheadings "* About\n" 2)
+                     "* About\n"))
+
+      (should (equal (org-toc-flush-subheadings "* About\n* Installation\n** 
via package.el\n** Manual\n* Use\n* Different href styles\n* Example\n" 0)
+                     ""))
+      (should (equal (org-toc-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 (org-toc-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 (org-toc-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 org-toc-insert-toc ()
   "Looks for a headline with the TOC tag and updates it with the

Reply via email to