Browse Source

Fix failing test

* lisp/org.el (org-link-search): Remove priority cookie from headlines
  during a fuzzy search.  Tiny optimization.
* testing/lisp/test-org.el (test-org/get-heading): Add tests.
Nicolas Goaziou 8 years ago
parent
commit
6dc6eb3b02
3 changed files with 45 additions and 4 deletions
  1. 3 0
      etc/ORG-NEWS
  2. 3 2
      lisp/org.el
  3. 39 2
      testing/lisp/test-org.el

+ 3 - 0
etc/ORG-NEWS

@@ -202,6 +202,9 @@ that doesn't exist in the target file, save positon before raising an
 error.  As a consequence, it is possible to jump back to the original
 error.  As a consequence, it is possible to jump back to the original
 document with ~org-mark-ring-goto~ (default binding =C-c &=).
 document with ~org-mark-ring-goto~ (default binding =C-c &=).
 
 
+*** ~org-get-heading~ accepts two more optional arguments
+
+See docstring for details.
 * Version 9.0
 * Version 9.0
 
 
 ** Incompatible changes
 ** Incompatible changes

+ 3 - 2
lisp/org.el

@@ -11146,7 +11146,8 @@ of matched result, which is either `dedicated' or `fuzzy'."
 			  org-comment-string
 			  org-comment-string
 			  (mapconcat #'regexp-quote words ".+")))
 			  (mapconcat #'regexp-quote words ".+")))
 		 (cookie-re "\\[[0-9]*\\(?:%\\|/[0-9]*\\)\\]")
 		 (cookie-re "\\[[0-9]*\\(?:%\\|/[0-9]*\\)\\]")
-		 (comment-re (format "\\`%s[ \t]+" org-comment-string)))
+		 (comment-re (eval-when-compile
+			       (format "\\`%s[ \t]+" org-comment-string))))
 	     (goto-char (point-min))
 	     (goto-char (point-min))
 	     (catch :found
 	     (catch :found
 	       (while (re-search-forward title-re nil t)
 	       (while (re-search-forward title-re nil t)
@@ -11155,7 +11156,7 @@ of matched result, which is either `dedicated' or `fuzzy'."
 			       (replace-regexp-in-string
 			       (replace-regexp-in-string
 				cookie-re ""
 				cookie-re ""
 				(replace-regexp-in-string
 				(replace-regexp-in-string
-				 comment-re "" (org-get-heading t t)))))
+				 comment-re "" (org-get-heading t t t)))))
 		   (throw :found t)))
 		   (throw :found t)))
 	       nil)))
 	       nil)))
       (beginning-of-line)
       (beginning-of-line)

+ 39 - 2
testing/lisp/test-org.el

@@ -1513,11 +1513,20 @@
    (equal "H"
    (equal "H"
 	  (org-test-with-temp-text "* H\nText<point>"
 	  (org-test-with-temp-text "* H\nText<point>"
 	    (org-get-heading))))
 	    (org-get-heading))))
-  ;; Without any optional argument, return TODO keywords and tags.
+  ;; Without any optional argument, return TODO keyword, priority
+  ;; cookie, COMMENT keyword and tags.
   (should
   (should
    (equal "TODO H"
    (equal "TODO H"
 	  (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
 	  (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
 	    (org-get-heading))))
 	    (org-get-heading))))
+  (should
+   (equal "[#A] H"
+	  (org-test-with-temp-text "* [#A] H"
+	    (org-get-heading))))
+  (should
+   (equal "COMMENT H"
+	  (org-test-with-temp-text "* COMMENT H"
+	    (org-get-heading))))
   (should
   (should
    (equal "H :tag:"
    (equal "H :tag:"
 	  (org-test-with-temp-text "* H :tag:"
 	  (org-test-with-temp-text "* H :tag:"
@@ -1545,11 +1554,39 @@
    (equal "Todo H"
    (equal "Todo H"
 	  (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
 	  (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
 	    (org-get-heading nil t))))
 	    (org-get-heading nil t))))
+  ;; With NO-PRIORITY, ignore priority.
+  (should
+   (equal "H"
+	  (org-test-with-temp-text "* [#A] H"
+	    (org-get-heading nil nil t))))
+  (should
+   (equal "H"
+	  (org-test-with-temp-text "* H"
+	    (org-get-heading nil nil t))))
+  (should
+   (equal "TODO H"
+	  (org-test-with-temp-text "* TODO [#A] H"
+	    (org-get-heading nil nil t))))
+  ;; With NO-COMMENT, ignore COMMENT keyword.
+  (should
+   (equal "H"
+	  (org-test-with-temp-text "* COMMENT H"
+	    (org-get-heading nil nil nil t))))
+  (should
+   (equal "H"
+	  (org-test-with-temp-text "* H"
+	    (org-get-heading nil nil nil t))))
+  (should
+   (equal "TODO [#A] H"
+	  (org-test-with-temp-text "* TODO [#A] COMMENT H"
+	    (org-get-heading nil nil nil t))))
   ;; On an empty headline, return value is consistent.
   ;; On an empty headline, return value is consistent.
   (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
   (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
   (should (equal "" (org-test-with-temp-text "* " (org-get-heading t))))
   (should (equal "" (org-test-with-temp-text "* " (org-get-heading t))))
   (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t))))
   (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t))))
-  (should (equal "" (org-test-with-temp-text "* " (org-get-heading t t)))))
+  (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t))))
+  (should
+   (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t)))))
 
 
 (ert-deftest test-org/in-commented-heading-p ()
 (ert-deftest test-org/in-commented-heading-p ()
   "Test `org-in-commented-heading-p' specifications."
   "Test `org-in-commented-heading-p' specifications."