branch: externals/org
commit 52b3c6a1a111b64324536adb6a2ffeb21bf5e3fc
Author: Morgan Smith <[email protected]>
Commit: Ihor Radchenko <[email protected]>

    test-org/move-subtree: Factor common logic
    
    * testing/lisp/test-org.el (test-org/move-subtree): Factor common logic
---
 testing/lisp/test-org.el | 101 +++++++++++++++++++++++------------------------
 1 file changed, 50 insertions(+), 51 deletions(-)

diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 7205ab9488..155a99d963 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -5888,57 +5888,56 @@ Text.
 
 (ert-deftest test-org/move-subtree ()
   "Test `org-metaup' and `org-metadown' on headings."
-  (should
-   (equal "* H2\n* H1\n"
-          (org-test-with-temp-text "* H1<point>\n* H2\n"
-            (org-metadown)
-            (buffer-string))))
-  (should
-   (equal "* H2\n* H1\n"
-          (org-test-with-temp-text "* H1\n* H2<point>\n"
-            (org-metaup)
-            (buffer-string))))
-  (should-error
-   (org-test-with-temp-text "* H1\n* H2<point>\n"
-     (org-metadown)
-     (buffer-string)))
-  (should-error
-   (org-test-with-temp-text "* H1<point>\n* H2\n"
-     (org-metaup)
-     (buffer-string)))
-  (should-error
-   (org-test-with-temp-text "* H1\n** H1.2<point>\n* H2"
-     (org-metadown)
-     (buffer-string)))
-  (should-error
-   (org-test-with-temp-text "* H1\n** H1.2<point>\n"
-     (org-metaup)
-     (buffer-string)))
-  ;; With selection
-  (should
-   (equal "* T\n** H3\n** H1\n** H2\n"
-          (org-test-with-temp-text "* T\n** <point>H1\n** H2\n** H3\n"
-            (set-mark (point))
-            (search-forward "H2")
-            (org-metadown)
-            (buffer-string))))
-  (should
-   (equal "* T\n** H1\n** H2\n** H0\n** H3\n"
-          (org-test-with-temp-text "* T\n** H0\n** <point>H1\n** H2\n** H3\n"
-            (set-mark (point))
-            (search-forward "H2")
-            (org-metaup)
-            (buffer-string))))
-  (should-error
-   (org-test-with-temp-text "* T\n** <point>H1\n** H2\n* T2\n"
-     (set-mark (point))
-     (search-forward "H2")
-     (org-metadown)))
-  (should-error
-   (org-test-with-temp-text "* T\n** <point>H1\n** H2\n* T2\n"
-     (set-mark (point))
-     (search-forward "H2")
-     (org-metaup))))
+  (cl-flet*
+      ((test-move-subtree (direction
+                           initial-text
+                           &optional expected selection)
+         (org-test-with-temp-text initial-text
+           (when selection
+             (set-mark (point))
+             (search-forward selection))
+           (cl-ecase direction
+             (up   (org-metaup))
+             (down (org-metadown)))
+           (should (equal expected
+                          (buffer-string))))))
+    (test-move-subtree 'down
+                       "* H1<point>\n* H2\n"
+                       "* H2\n* H1\n")
+    (test-move-subtree 'up
+                       "* H1\n* H2<point>\n"
+                       "* H2\n* H1\n")
+    (should-error
+     (test-move-subtree 'down
+                        "* H1\n* H2<point>\n"))
+    (should-error
+     (test-move-subtree 'up
+                        "* H1<point>\n* H2\n"))
+    (should-error
+     (test-move-subtree 'down
+                        "* H1\n** H1.2<point>\n* H2"))
+    (should-error
+     (test-move-subtree 'up
+                        "* H1\n** H1.2<point>\n"))
+    ;; With selection
+    (test-move-subtree 'down
+                       "* T\n** <point>H1\n** H2\n** H3\n"
+                       "* T\n** H3\n** H1\n** H2\n"
+                       "H2")
+    (test-move-subtree 'up
+                       "* T\n** H0\n** <point>H1\n** H2\n** H3\n"
+                       "* T\n** H1\n** H2\n** H0\n** H3\n"
+                       "H2")
+    (should-error
+     (test-move-subtree 'down
+                        "* T\n** <point>H1\n** H2\n* T2\n"
+                        nil
+                        "H2"))
+    (should-error
+     (test-move-subtree 'up
+                        "* T\n** <point>H1\n** H2\n* T2\n"
+                        nil
+                        "H2"))))
 
 (ert-deftest test-org/demote ()
   "Test `org-demote' specifications."

Reply via email to