mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-11-25 07:27:57 +00:00
Be stricter when updating radio targets
* lisp/org.el (org-all-targets): Make sure the regexp really matched a radio target. * testing/lisp/test-org.el: Add test.
This commit is contained in:
parent
e2e545269a
commit
bbdd81ad37
10
lisp/org.el
10
lisp/org.el
@ -5678,13 +5678,15 @@ by a #."
|
||||
|
||||
(defun org-all-targets (&optional radio)
|
||||
"Return a list of all targets in this file.
|
||||
With optional argument RADIO, only find radio targets."
|
||||
(let ((re (if radio org-radio-target-regexp org-target-regexp))
|
||||
rtn)
|
||||
When optional argument RADIO is non-nil, only find radio
|
||||
targets."
|
||||
(let ((re (if radio org-radio-target-regexp org-target-regexp)) rtn)
|
||||
(save-excursion
|
||||
(goto-char (point-min))
|
||||
(while (re-search-forward re nil t)
|
||||
(add-to-list 'rtn (downcase (org-match-string-no-properties 1))))
|
||||
(let ((obj (org-element-context)))
|
||||
(when (memq (org-element-type obj) '(radio-target target))
|
||||
(add-to-list 'rtn (downcase (org-element-property :value obj))))))
|
||||
rtn)))
|
||||
|
||||
(defun org-make-target-link-regexp (targets)
|
||||
|
@ -11,162 +11,68 @@
|
||||
;; Template test file for Org-mode tests
|
||||
|
||||
;;; Code:
|
||||
(ert-deftest test-org/org-link-escape-ascii-character ()
|
||||
"Escape an ascii character."
|
||||
(should
|
||||
(string=
|
||||
"%5B"
|
||||
(org-link-escape "["))))
|
||||
|
||||
(ert-deftest test-org/org-link-escape-ascii-ctrl-character ()
|
||||
"Escape an ascii control character."
|
||||
(should
|
||||
(string=
|
||||
"%09"
|
||||
(org-link-escape "\t"))))
|
||||
|
||||
(ert-deftest test-org/org-link-escape-multibyte-character ()
|
||||
"Escape an unicode multibyte character."
|
||||
(should
|
||||
(string=
|
||||
"%E2%82%AC"
|
||||
(org-link-escape "€"))))
|
||||
|
||||
(ert-deftest test-org/org-link-escape-custom-table ()
|
||||
"Escape string with custom character table."
|
||||
(should
|
||||
(string=
|
||||
"Foo%3A%42ar%0A"
|
||||
(org-link-escape "Foo:Bar\n" '(?\: ?\B)))))
|
||||
|
||||
(ert-deftest test-org/org-link-escape-custom-table-merge ()
|
||||
"Escape string with custom table merged with default table."
|
||||
(should
|
||||
(string=
|
||||
"%5BF%6F%6F%3A%42ar%0A%5D"
|
||||
(org-link-escape "[Foo:Bar\n]" '(?\: ?\B ?\o) t))))
|
||||
|
||||
(ert-deftest test-org/org-link-unescape-ascii-character ()
|
||||
"Unescape an ascii character."
|
||||
(should
|
||||
(string=
|
||||
"["
|
||||
(org-link-unescape "%5B"))))
|
||||
|
||||
(ert-deftest test-org/org-link-unescape-ascii-ctrl-character ()
|
||||
"Unescpae an ascii control character."
|
||||
(should
|
||||
(string=
|
||||
"\n"
|
||||
(org-link-unescape "%0A"))))
|
||||
|
||||
(ert-deftest test-org/org-link-unescape-multibyte-character ()
|
||||
"Unescape unicode multibyte character."
|
||||
(should
|
||||
(string=
|
||||
"€"
|
||||
(org-link-unescape "%E2%82%AC"))))
|
||||
|
||||
(ert-deftest test-org/org-link-unescape-ascii-extended-char ()
|
||||
"Unescape old style percent escaped character."
|
||||
(should
|
||||
(string=
|
||||
"àâçèéêîôùû"
|
||||
(decode-coding-string (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1))))
|
||||
|
||||
(ert-deftest test-org/org-link-escape-url-with-escaped-char ()
|
||||
"Escape and unscape a URL that includes an escaped char.
|
||||
http://article.gmane.org/gmane.emacs.orgmode/21459/"
|
||||
(should
|
||||
(string=
|
||||
"http://some.host.com/form?&id=blah%2Bblah25"
|
||||
(org-link-unescape (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
|
||||
|
||||
(ert-deftest test-org/accumulated-properties-in-drawers ()
|
||||
"Ensure properties accumulate in subtree drawers."
|
||||
(org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
|
||||
(org-babel-next-src-block)
|
||||
(should (equal '(2 1) (org-babel-execute-src-block)))))
|
||||
|
||||
|
||||
|
||||
;;; Links
|
||||
;;; Comments
|
||||
|
||||
;;;; Fuzzy links
|
||||
|
||||
;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
|
||||
;; a target keyword (aka an invisible target: #+TARGET: text), to
|
||||
;; a named element (#+name: text) and to headlines (* Text).
|
||||
|
||||
(ert-deftest test-org/fuzzy-links ()
|
||||
"Test fuzzy links specifications."
|
||||
;; 1. Fuzzy link goes in priority to a matching target.
|
||||
(org-test-with-temp-text
|
||||
"#+TARGET: Test\n#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n[[Test]]"
|
||||
(goto-line 6)
|
||||
(org-open-at-point)
|
||||
(should (looking-at "<<Test>>")))
|
||||
;; 2. Fuzzy link should then go to a matching target keyword.
|
||||
(org-test-with-temp-text
|
||||
"#+NAME: Test\n|a|b|\n#+TARGET: Test\n* Test\n[[Test]]"
|
||||
(goto-line 5)
|
||||
(org-open-at-point)
|
||||
(should (looking-at "#\\+TARGET: Test")))
|
||||
;; 3. Then fuzzy link points to an element with a given name.
|
||||
(org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n[[Test]]"
|
||||
(goto-line 5)
|
||||
(org-open-at-point)
|
||||
(should (looking-at "#\\+NAME: Test")))
|
||||
;; 4. A target still lead to a matching headline otherwise.
|
||||
(org-test-with-temp-text "* Head1\n* Head2\n*Head3\n[[Head2]]"
|
||||
(goto-line 4)
|
||||
(org-open-at-point)
|
||||
(should (looking-at "\\* Head2")))
|
||||
;; 5. With a leading star in link, enforce heading match.
|
||||
(org-test-with-temp-text "#+TARGET: Test\n* Test\n<<Test>>\n[[*Test]]"
|
||||
(goto-line 4)
|
||||
(org-open-at-point)
|
||||
(should (looking-at "\\* Test"))))
|
||||
|
||||
|
||||
|
||||
;;; Macros
|
||||
|
||||
(ert-deftest test-org/macro-replace-all ()
|
||||
"Test `org-macro-replace-all' specifications."
|
||||
;; Standard test.
|
||||
(ert-deftest test-org/comment-dwim ()
|
||||
"Test `comment-dwim' behaviour in an Org buffer."
|
||||
;; No region selected, no comment on current line and line not
|
||||
;; empty: insert comment on line above.
|
||||
(should
|
||||
(equal
|
||||
"#+MACRO: A B\n1 B 3"
|
||||
(org-test-with-temp-text "#+MACRO: A B\n1 {{{A}}} 3"
|
||||
(progn (org-macro-initialize-templates)
|
||||
(org-macro-replace-all org-macro-templates)
|
||||
(buffer-string)))))
|
||||
;; Macro with arguments.
|
||||
(equal "# \nComment"
|
||||
(org-test-with-temp-text "Comment"
|
||||
(progn (call-interactively 'comment-dwim)
|
||||
(buffer-string)))))
|
||||
;; No region selected, no comment on current line and line empty:
|
||||
;; insert comment on this line.
|
||||
(should
|
||||
(equal
|
||||
"#+MACRO: macro $1 $2\nsome text"
|
||||
(org-test-with-temp-text "#+MACRO: macro $1 $2\n{{{macro(some,text)}}}"
|
||||
(progn (org-macro-initialize-templates)
|
||||
(org-macro-replace-all org-macro-templates)
|
||||
(buffer-string)))))
|
||||
;; Macro with "eval".
|
||||
(equal "# \nParagraph"
|
||||
(org-test-with-temp-text "\nParagraph"
|
||||
(progn (call-interactively 'comment-dwim)
|
||||
(buffer-string)))))
|
||||
;; No region selected, and a comment on this line: indent it.
|
||||
(should
|
||||
(equal
|
||||
"#+MACRO: add (eval (+ $1 $2))\n3"
|
||||
(org-test-with-temp-text "#+MACRO: add (eval (+ $1 $2))\n{{{add(1,2)}}}"
|
||||
(progn (org-macro-initialize-templates)
|
||||
(org-macro-replace-all org-macro-templates)
|
||||
(buffer-string)))))
|
||||
;; Nested macros.
|
||||
(equal "* Headline\n # Comment"
|
||||
(org-test-with-temp-text "* Headline\n# Comment"
|
||||
(progn (forward-line)
|
||||
(let ((org-adapt-indentation t))
|
||||
(call-interactively 'comment-dwim))
|
||||
(buffer-string)))))
|
||||
;; Also recognize single # at column 0 as comments.
|
||||
(should
|
||||
(equal
|
||||
"#+MACRO: in inner\n#+MACRO: out {{{in}}} outer\ninner outer"
|
||||
(org-test-with-temp-text
|
||||
"#+MACRO: in inner\n#+MACRO: out {{{in}}} outer\n{{{out}}}"
|
||||
(progn (org-macro-initialize-templates)
|
||||
(org-macro-replace-all org-macro-templates)
|
||||
(buffer-string))))))
|
||||
(equal "# Comment"
|
||||
(org-test-with-temp-text "# Comment"
|
||||
(progn (forward-line)
|
||||
(call-interactively 'comment-dwim)
|
||||
(buffer-string)))))
|
||||
;; Region selected and only comments and blank lines within it:
|
||||
;; un-comment all commented lines.
|
||||
(should
|
||||
(equal "Comment 1\n\nComment 2"
|
||||
(org-test-with-temp-text "# Comment 1\n\n# Comment 2"
|
||||
(progn
|
||||
(transient-mark-mode 1)
|
||||
(push-mark (point) t t)
|
||||
(goto-char (point-max))
|
||||
(call-interactively 'comment-dwim)
|
||||
(buffer-string)))))
|
||||
;; Region selected without comments: comment all non-blank lines.
|
||||
(should
|
||||
(equal "# Comment 1\n\n# Comment 2"
|
||||
(org-test-with-temp-text "Comment 1\n\nComment 2"
|
||||
(progn
|
||||
(transient-mark-mode 1)
|
||||
(push-mark (point) t t)
|
||||
(goto-char (point-max))
|
||||
(call-interactively 'comment-dwim)
|
||||
(buffer-string)))))
|
||||
;; In front of a keyword without region, insert a new comment.
|
||||
(should
|
||||
(equal "# \n#+KEYWORD: value"
|
||||
(org-test-with-temp-text "#+KEYWORD: value"
|
||||
(progn (call-interactively 'comment-dwim)
|
||||
(buffer-string))))))
|
||||
|
||||
|
||||
|
||||
@ -319,70 +225,171 @@ http://article.gmane.org/gmane.emacs.orgmode/21459/"
|
||||
|
||||
|
||||
|
||||
;;; Comments
|
||||
;;; Links
|
||||
|
||||
(ert-deftest test-org/comment-dwim ()
|
||||
"Test `comment-dwim' behaviour in an Org buffer."
|
||||
;; No region selected, no comment on current line and line not
|
||||
;; empty: insert comment on line above.
|
||||
;;;; Fuzzy Links
|
||||
|
||||
;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
|
||||
;; a target keyword (aka an invisible target: #+TARGET: text), to
|
||||
;; a named element (#+name: text) and to headlines (* Text).
|
||||
|
||||
(ert-deftest test-org/fuzzy-links ()
|
||||
"Test fuzzy links specifications."
|
||||
;; 1. Fuzzy link goes in priority to a matching target.
|
||||
(org-test-with-temp-text
|
||||
"#+TARGET: Test\n#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n[[Test]]"
|
||||
(goto-line 6)
|
||||
(org-open-at-point)
|
||||
(should (looking-at "<<Test>>")))
|
||||
;; 2. Fuzzy link should then go to a matching target keyword.
|
||||
(org-test-with-temp-text
|
||||
"#+NAME: Test\n|a|b|\n#+TARGET: Test\n* Test\n[[Test]]"
|
||||
(goto-line 5)
|
||||
(org-open-at-point)
|
||||
(should (looking-at "#\\+TARGET: Test")))
|
||||
;; 3. Then fuzzy link points to an element with a given name.
|
||||
(org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n[[Test]]"
|
||||
(goto-line 5)
|
||||
(org-open-at-point)
|
||||
(should (looking-at "#\\+NAME: Test")))
|
||||
;; 4. A target still lead to a matching headline otherwise.
|
||||
(org-test-with-temp-text "* Head1\n* Head2\n*Head3\n[[Head2]]"
|
||||
(goto-line 4)
|
||||
(org-open-at-point)
|
||||
(should (looking-at "\\* Head2")))
|
||||
;; 5. With a leading star in link, enforce heading match.
|
||||
(org-test-with-temp-text "#+TARGET: Test\n* Test\n<<Test>>\n[[*Test]]"
|
||||
(goto-line 4)
|
||||
(org-open-at-point)
|
||||
(should (looking-at "\\* Test"))))
|
||||
|
||||
|
||||
;;;; Link Escaping
|
||||
|
||||
(ert-deftest test-org/org-link-escape-ascii-character ()
|
||||
"Escape an ascii character."
|
||||
(should
|
||||
(equal "# \nComment"
|
||||
(org-test-with-temp-text "Comment"
|
||||
(progn (call-interactively 'comment-dwim)
|
||||
(buffer-string)))))
|
||||
;; No region selected, no comment on current line and line empty:
|
||||
;; insert comment on this line.
|
||||
(string=
|
||||
"%5B"
|
||||
(org-link-escape "["))))
|
||||
|
||||
(ert-deftest test-org/org-link-escape-ascii-ctrl-character ()
|
||||
"Escape an ascii control character."
|
||||
(should
|
||||
(equal "# \nParagraph"
|
||||
(org-test-with-temp-text "\nParagraph"
|
||||
(progn (call-interactively 'comment-dwim)
|
||||
(buffer-string)))))
|
||||
;; No region selected, and a comment on this line: indent it.
|
||||
(string=
|
||||
"%09"
|
||||
(org-link-escape "\t"))))
|
||||
|
||||
(ert-deftest test-org/org-link-escape-multibyte-character ()
|
||||
"Escape an unicode multibyte character."
|
||||
(should
|
||||
(equal "* Headline\n # Comment"
|
||||
(org-test-with-temp-text "* Headline\n# Comment"
|
||||
(progn (forward-line)
|
||||
(let ((org-adapt-indentation t))
|
||||
(call-interactively 'comment-dwim))
|
||||
(buffer-string)))))
|
||||
;; Also recognize single # at column 0 as comments.
|
||||
(string=
|
||||
"%E2%82%AC"
|
||||
(org-link-escape "€"))))
|
||||
|
||||
(ert-deftest test-org/org-link-escape-custom-table ()
|
||||
"Escape string with custom character table."
|
||||
(should
|
||||
(equal "# Comment"
|
||||
(org-test-with-temp-text "# Comment"
|
||||
(progn (forward-line)
|
||||
(call-interactively 'comment-dwim)
|
||||
(buffer-string)))))
|
||||
;; Region selected and only comments and blank lines within it:
|
||||
;; un-comment all commented lines.
|
||||
(string=
|
||||
"Foo%3A%42ar%0A"
|
||||
(org-link-escape "Foo:Bar\n" '(?\: ?\B)))))
|
||||
|
||||
(ert-deftest test-org/org-link-escape-custom-table-merge ()
|
||||
"Escape string with custom table merged with default table."
|
||||
(should
|
||||
(equal "Comment 1\n\nComment 2"
|
||||
(org-test-with-temp-text "# Comment 1\n\n# Comment 2"
|
||||
(progn
|
||||
(transient-mark-mode 1)
|
||||
(push-mark (point) t t)
|
||||
(goto-char (point-max))
|
||||
(call-interactively 'comment-dwim)
|
||||
(buffer-string)))))
|
||||
;; Region selected without comments: comment all non-blank lines.
|
||||
(string=
|
||||
"%5BF%6F%6F%3A%42ar%0A%5D"
|
||||
(org-link-escape "[Foo:Bar\n]" '(?\: ?\B ?\o) t))))
|
||||
|
||||
(ert-deftest test-org/org-link-unescape-ascii-character ()
|
||||
"Unescape an ascii character."
|
||||
(should
|
||||
(equal "# Comment 1\n\n# Comment 2"
|
||||
(org-test-with-temp-text "Comment 1\n\nComment 2"
|
||||
(progn
|
||||
(transient-mark-mode 1)
|
||||
(push-mark (point) t t)
|
||||
(goto-char (point-max))
|
||||
(call-interactively 'comment-dwim)
|
||||
(buffer-string)))))
|
||||
;; In front of a keyword without region, insert a new comment.
|
||||
(string=
|
||||
"["
|
||||
(org-link-unescape "%5B"))))
|
||||
|
||||
(ert-deftest test-org/org-link-unescape-ascii-ctrl-character ()
|
||||
"Unescpae an ascii control character."
|
||||
(should
|
||||
(equal "# \n#+KEYWORD: value"
|
||||
(org-test-with-temp-text "#+KEYWORD: value"
|
||||
(progn (call-interactively 'comment-dwim)
|
||||
(buffer-string))))))
|
||||
(string=
|
||||
"\n"
|
||||
(org-link-unescape "%0A"))))
|
||||
|
||||
(ert-deftest test-org/org-link-unescape-multibyte-character ()
|
||||
"Unescape unicode multibyte character."
|
||||
(should
|
||||
(string=
|
||||
"€"
|
||||
(org-link-unescape "%E2%82%AC"))))
|
||||
|
||||
(ert-deftest test-org/org-link-unescape-ascii-extended-char ()
|
||||
"Unescape old style percent escaped character."
|
||||
(should
|
||||
(string=
|
||||
"àâçèéêîôùû"
|
||||
(decode-coding-string (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1))))
|
||||
|
||||
(ert-deftest test-org/org-link-escape-url-with-escaped-char ()
|
||||
"Escape and unscape a URL that includes an escaped char.
|
||||
http://article.gmane.org/gmane.emacs.orgmode/21459/"
|
||||
(should
|
||||
(string=
|
||||
"http://some.host.com/form?&id=blah%2Bblah25"
|
||||
(org-link-unescape (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
|
||||
|
||||
|
||||
|
||||
;;; Mark region
|
||||
;;; Macros
|
||||
|
||||
(ert-deftest test-org/macro-replace-all ()
|
||||
"Test `org-macro-replace-all' specifications."
|
||||
;; Standard test.
|
||||
(should
|
||||
(equal
|
||||
"#+MACRO: A B\n1 B 3"
|
||||
(org-test-with-temp-text "#+MACRO: A B\n1 {{{A}}} 3"
|
||||
(progn (org-macro-initialize-templates)
|
||||
(org-macro-replace-all org-macro-templates)
|
||||
(buffer-string)))))
|
||||
;; Macro with arguments.
|
||||
(should
|
||||
(equal
|
||||
"#+MACRO: macro $1 $2\nsome text"
|
||||
(org-test-with-temp-text "#+MACRO: macro $1 $2\n{{{macro(some,text)}}}"
|
||||
(progn (org-macro-initialize-templates)
|
||||
(org-macro-replace-all org-macro-templates)
|
||||
(buffer-string)))))
|
||||
;; Macro with "eval".
|
||||
(should
|
||||
(equal
|
||||
"#+MACRO: add (eval (+ $1 $2))\n3"
|
||||
(org-test-with-temp-text "#+MACRO: add (eval (+ $1 $2))\n{{{add(1,2)}}}"
|
||||
(progn (org-macro-initialize-templates)
|
||||
(org-macro-replace-all org-macro-templates)
|
||||
(buffer-string)))))
|
||||
;; Nested macros.
|
||||
(should
|
||||
(equal
|
||||
"#+MACRO: in inner\n#+MACRO: out {{{in}}} outer\ninner outer"
|
||||
(org-test-with-temp-text
|
||||
"#+MACRO: in inner\n#+MACRO: out {{{in}}} outer\n{{{out}}}"
|
||||
(progn (org-macro-initialize-templates)
|
||||
(org-macro-replace-all org-macro-templates)
|
||||
(buffer-string))))))
|
||||
|
||||
|
||||
|
||||
;;; Node Properties
|
||||
|
||||
(ert-deftest test-org/accumulated-properties-in-drawers ()
|
||||
"Ensure properties accumulate in subtree drawers."
|
||||
(org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
|
||||
(org-babel-next-src-block)
|
||||
(should (equal '(2 1) (org-babel-execute-src-block)))))
|
||||
|
||||
|
||||
|
||||
;;; Mark Region
|
||||
|
||||
(ert-deftest test-org/mark-subtree ()
|
||||
"Test `org-mark-subtree' specifications."
|
||||
@ -409,7 +416,7 @@ http://article.gmane.org/gmane.emacs.orgmode/21459/"
|
||||
(forward-line 2)
|
||||
(org-mark-subtree 1)
|
||||
(list (region-beginning) (region-end))))))
|
||||
;; Do not get fooled with inlinetasks.
|
||||
;; Do not get fooled by inlinetasks.
|
||||
(when (featurep 'org-inlinetask)
|
||||
(should
|
||||
(= 1
|
||||
@ -421,7 +428,7 @@ http://article.gmane.org/gmane.emacs.orgmode/21459/"
|
||||
|
||||
|
||||
|
||||
;; Navigation
|
||||
;;; Navigation
|
||||
|
||||
(ert-deftest test-org/forward-element ()
|
||||
"Test `org-forward-element' specifications."
|
||||
@ -750,6 +757,23 @@ Text.
|
||||
(overlays-in (point-min) (point-max)))))))
|
||||
|
||||
|
||||
|
||||
;;; Targets and Radio Targets
|
||||
|
||||
(ert-deftest test-org/all-targets ()
|
||||
"Test `org-all-targets' specifications."
|
||||
;; Without an argument.
|
||||
(should
|
||||
(equal '("radio-target" "target")
|
||||
(org-test-with-temp-text "<<target>> <<<radio-target>>>\n: <<verb>>"
|
||||
(org-all-targets))))
|
||||
;; With argument.
|
||||
(should
|
||||
(equal '("radio-target")
|
||||
(org-test-with-temp-text "<<target>> <<<radio-target>>>"
|
||||
(org-all-targets t)))))
|
||||
|
||||
|
||||
(provide 'test-org)
|
||||
|
||||
;;; test-org.el ends here
|
||||
|
Loading…
Reference in New Issue
Block a user