emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
blob 3b8f85a2b1fbfb4b189782d63819a4ad589c0f1f 6175 bytes (raw)
name: testing/lisp/test-org-info.el 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
 
;;; test-org-info.el --- Tests for "org-info.el"     -*- lexical-binding: t; -*-

;; Copyright (C) 2017, 2019  Nicolas Goaziou

;; Author: Nicolas Goaziou <mail@nicolasgoaziou.fr>

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <https://www.gnu.org/licenses/>.

;;; Code:

(ert-deftest test-org-info/export ()
  "Test `org-info-export' specifications."
  ;; Export to HTML.  Without node, refer to "Top".
  (should
   (equal (org-info-export "filename#node" nil 'html)
	  "<a href=\"filename.html#node\">filename#node</a>"))
  (should
   (equal (org-info-export "filename" nil 'html)
	  "<a href=\"filename.html#Top\">filename</a>"))
  ;; Directory index. Top anchor actually should not be added,
  ;; but it should be rather rare case to add special code path
  (should
   (equal (org-info-export "dir" nil 'html)
	  "<a href=\"https://www.gnu.org/manual/manual.html#Top\">dir</a>"))
  ;; When exporting to HTML, ensure node names are expanded according
  ;; to (info "(texinfo) HTML Xref Node Name Expansion").
  (should
   (equal "_005f"
	  (let ((name (org-info-export "#_" nil 'html)))
	    (and (string-match "#\\(.*\\)\"" name)
		 (match-string 1 name)))))
  (should
   (equal "_002d"
	  (let ((name (org-info-export "#-" nil 'html)))
	    (and (string-match "#\\(.*\\)\"" name)
		 (match-string 1 name)))))
  (should
   (equal "A-node"
	  (let ((name (org-info-export "#A node" nil 'html)))
	    (and (string-match "#\\(.*\\)\"" name)
		 (match-string 1 name)))))
  (should
   (equal "A-node-_002d_002d_002d-with-_005f_0027_0025"
	  (let ((name (org-info-export "#A  node --- with _'%" nil 'html)))
	    (and (string-match "#\\(.*\\)\"" name)
		 (match-string 1 name)))))
  ;; Export to Texinfo.  Without a node name, refer to "Top".
  (should
   (equal (org-info-export "filename" nil 'texinfo)
	  "@ref{Top,,,filename,}"))
  (should
   (equal (org-info-export "filename#node" nil 'texinfo)
	  "@ref{node,,,filename,}"))
  ;; "Top" is preserved, "::" as node separator.
  (should
   (equal "@ref{Top,,,emacs,}"
          (org-info-export "emacs::Top" nil 'texinfo)))

  ;; Description.
  (should
   (equal "@ref{Top,Emacs,,emacs,}"
          (org-info-export "emacs" "Emacs" 'texinfo)))
  (should
   (equal "@ref{Destructuring with pcase Patterns,pcase-let,,emacs,}"
          (org-info-export "emacs#Destructuring with pcase Patterns"
                           "pcase-let" 'texinfo))))

(ert-deftest test-org-info/link-file-node ()
  "Test parse info links by `org-info--link-file-node'."
  (should (equal '("success" . "Hash Separator")
                 (org-info--link-file-node "success#Hash Separator")))
  ;; Other separators
  (should (equal '("success" . "Single Colon Separator")
                 (org-info--link-file-node "success:Single Colon Separator")))
  (should (equal '("success" . "Double Colon Separator")
                 (org-info--link-file-node "success::Double Colon Separator")))
  (should (equal '("success" . "Hash Colon Separator")
                 (org-info--link-file-node "success#:Hash Colon Separator")))
  ;; Partial specification
  (should (equal '("nodeless" . "Top")
                 (org-info--link-file-node "nodeless")))
  (should (equal '("dir" . "Top")
                 (org-info--link-file-node "")))
  (should (equal '("dir" . "Top")
                 (org-info--link-file-node nil)))
  (should (equal '("org" . "Introduction")
                 (org-info--link-file-node "#Introduction")))
  ;; Trailing separator
  (should (equal '("trailing-hash" . "Top")
                 (org-info--link-file-node "trailing-hash#")))
  (should (equal '("trailing-single-colon" . "Top")
                 (org-info--link-file-node "trailing-single-colon:")))
  (should (equal '("trailing-double-colon" . "Top")
                 (org-info--link-file-node "trailing-double-colon::")))
  (should (equal '("trailing-hash-colon" . "Top")
                 (org-info--link-file-node "trailing-hash-colon#:")))
  ;; Trim spaces
  (should (equal '("trim" . "Spaces")
                 (org-info--link-file-node " trim # Spaces \t"))))

(ert-deftest test-org-info/description-as-command ()
  "Test `org-info-description-as-command'."
  (let ((cases
         '(("info file" "info:file")
           ("info strip-top-hash" "info:strip-top-hash#Top")
           ("info strip-top-single-colon" "info:strip-top-single-colon:Top")
           ("info strip-top-double-colon" "info:strip-top-double-colon::Top")
           ("info \"(pass) Hash\"" "info:pass#Hash")
           ("info \"(pass) Double Colon\"" "info:pass:: Double Colon")
           ("info \"(info) Advanced\"" "info:info:Advanced")
           ("info \"(dir)\"" "info:")
           ("info \"(org) Tables\"" "info::Tables")
           (nil "http://orgmode.org/index.html#Not-info-link"))))
    (dolist (expectation-input cases)
      (let ((expectation (car expectation-input))
            (input (cadr expectation-input)))
        (should (equal
                 expectation
                 (org-info-description-as-command input nil))))))
  (let ((cases
         '(("Override link" "info:ignored#Link" "Override link")
           ("Fallback description" "http://not.info/link" "Fallback description")
           ("Link is nil" nil "Link is nil"))))
        (dolist (expectation-input-desc cases)
      (let ((expectation (car expectation-input-desc))
            (input (cadr expectation-input-desc))
            (desc (nth 2 expectation-input-desc)))
        (should (equal
                 expectation
                 (org-info-description-as-command input desc)))))))

(provide 'test-org-info)
;;; test-org-info.el ends here

debug log:

solving 3b8f85a2b ...
found 3b8f85a2b in https://list.orgmode.org/orgmode/tdb8kd$7mo$1@ciao.gmane.io/
found 94923169c in https://git.savannah.gnu.org/cgit/emacs/org-mode.git
preparing index
index prepared:
100644 94923169cfa0ab48ba079dca58a55671cf8cb6b4	testing/lisp/test-org-info.el

applying [1/1] https://list.orgmode.org/orgmode/tdb8kd$7mo$1@ciao.gmane.io/
diff --git a/testing/lisp/test-org-info.el b/testing/lisp/test-org-info.el
index 94923169c..3b8f85a2b 100644

Checking patch testing/lisp/test-org-info.el...
Applied patch testing/lisp/test-org-info.el cleanly.

index at:
100644 3b8f85a2b1fbfb4b189782d63819a4ad589c0f1f	testing/lisp/test-org-info.el

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).