[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org 87da1ff15b 2/3: org-cite-basic-export-citation: Fix
From: |
ELPA Syncer |
Subject: |
[elpa] externals/org 87da1ff15b 2/3: org-cite-basic-export-citation: Fix prefix/suffix being ignored |
Date: |
Tue, 16 Jan 2024 09:58:21 -0500 (EST) |
branch: externals/org
commit 87da1ff15b3762e158179cdc88ef6460ae38e923
Author: Ihor Radchenko <yantar92@posteo.net>
Commit: Ihor Radchenko <yantar92@posteo.net>
org-cite-basic-export-citation: Fix prefix/suffix being ignored
* lisp/oc-basic.el (org-cite-basic-export-citation): Honour prefix and
suffix in citation references and citations.
* testing/examples/Basic.bib: New example bibliography used by tests.
* testing/lisp/test-oc-basic.el:
(test-org-cite-basic/parse-bibliography):
(test-org-cite-basic/export-citation): New file, adding tests for
oc-basic processor.
Reported-by: William Denton <william@williamdenton.org>
Link:
https://orgmode.org/list/FMaPNvYf_8jqVxcU2L5kgiMuejm0NqK3e9D7CzhSzG-fmESTZKgtAJy1LG_zNDLS6o_oQ-gF_G-6DXlXA2iQ_yAjNjLgeB86JTU46Sv8Wec=@williamdenton.org
---
lisp/oc-basic.el | 34 +++++----
testing/examples/Basic.bib | 9 +++
testing/lisp/test-oc-basic.el | 160 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 190 insertions(+), 13 deletions(-)
diff --git a/lisp/oc-basic.el b/lisp/oc-basic.el
index 8eebde333a..f896fdf404 100644
--- a/lisp/oc-basic.el
+++ b/lisp/oc-basic.el
@@ -667,22 +667,30 @@ export communication channel, as a property list."
;; "author" style.
(`(,(or "author" "a") . ,variant)
(let ((caps (member variant '("caps" "c"))))
- (org-export-data
- (org-cite-mapconcat
- (lambda (key)
- (or
- (let ((author (org-cite-basic--get-author key info)))
- (if caps (org-cite-capitalize author) author))
- "??"))
- (org-cite-get-references citation t)
- org-cite-basic-author-year-separator)
+ (org-cite-basic--format-author-year
+ citation
+ (lambda (p c s) (org-cite-concat p c s))
+ (lambda (prefix author _ suffix)
+ (org-cite-concat
+ prefix
+ (if caps (org-cite-capitalize author) author)
+ suffix))
info)))
;; "noauthor" style.
(`(,(or "noauthor" "na") . ,variant)
- (format (if (funcall has-variant-p variant 'bare) "%s" "(%s)")
- (mapconcat (lambda (key) (or (org-cite-basic--get-year key
info) "????"))
- (org-cite-get-references citation t)
- org-cite-basic-author-year-separator)))
+ (let ((bare? (funcall has-variant-p variant 'bare)))
+ (org-cite-basic--format-author-year
+ citation
+ (lambda (prefix contents suffix)
+ (org-cite-concat
+ (unless bare? "(")
+ prefix
+ contents
+ suffix
+ (unless bare? ")")))
+ (lambda (prefix _ year suffix)
+ (org-cite-concat prefix year suffix))
+ info)))
;; "nocite" style.
(`(,(or "nocite" "n") . ,_) nil)
;; "text" and "note" styles.
diff --git a/testing/examples/Basic.bib b/testing/examples/Basic.bib
new file mode 100644
index 0000000000..addc70e528
--- /dev/null
+++ b/testing/examples/Basic.bib
@@ -0,0 +1,9 @@
+@book{friends,
+ title = {{{LaTeX}} and Friends},
+ author = {van Dongen, M.R.C.},
+ date = {2012},
+ location = {Berlin},
+ publisher = {Springer},
+ doi = {10.1007/978-3-642-23816-1},
+ isbn = {9783642238161}
+}
diff --git a/testing/lisp/test-oc-basic.el b/testing/lisp/test-oc-basic.el
new file mode 100644
index 0000000000..f0bf9d0d0f
--- /dev/null
+++ b/testing/lisp/test-oc-basic.el
@@ -0,0 +1,160 @@
+;;; test-oc-basic.el --- Tests for Org Cite basic processor -*-
lexical-binding: t; -*-
+
+;; Copyright (C) 2024 Ihor Radchenko
+
+;; Author: Ihor Radchenko <yantar92 at posteo dot net>
+
+;; 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/>.
+
+;;; Commentary:
+
+;; Unit tests for Org cite basic processor.
+
+;;; Code:
+
+(require 'oc-basic)
+
+(ert-deftest test-org-cite-basic/parse-bibliography ()
+ "Test `org-cite-basic--parse-bibliography'."
+ ;; Bibtex bibliography.
+ (org-test-with-temp-text
+ (format "#+bibliography: %s"
+ (expand-file-name "examples/Basic.bib" org-test-dir))
+ (let ((data (org-cite-basic--parse-bibliography)))
+ (should (= 1 (length data)))
+ (should (equal (expand-file-name "examples/Basic.bib" org-test-dir)
+ (caar data)))
+ (dolist (k (hash-table-keys (cdar data)))
+ (when (equal k "friends")
+ (should (equal (gethash k (cdar data))
+ '((type . "book")
+ (id . "friends")
+ (title . "{{LaTeX}} and Friends")
+ (author . "van Dongen, M.R.C.")
+ (date . "2012")
+ (location . "Berlin")
+ (publisher . "Springer")
+ (doi . "10.1007/978-3-642-23816-1")
+ (isbn . "9783642238161")))))))))
+
+(ert-deftest test-org-cite-basic/export-citation ()
+ "Test `org-cite-basic-export-citation'."
+ ;; Default "nil" citation style.
+ (org-test-with-temp-text
+ (format
+ "#+bibliography: %s
+#+cite_export: basic
+Default: [cite:Citing ; @friends; and @friends also; is duplication.]"
+ (expand-file-name "examples/Basic.bib" org-test-dir))
+ (let ((export-buffer "*Test ASCII Export*")
+ (org-export-show-temporary-export-buffer nil))
+ (org-export-to-buffer 'ascii export-buffer)
+ (with-current-buffer export-buffer
+ (let ((case-fold-search t))
+ (search-forward "Default: (Citing van Dongen, M.R.C., 2012, and van
Dongen, M.R.C., 2012
+also is duplication.)" nil t)))))
+ ;; "author" citation style.
+ (org-test-with-temp-text
+ (format
+ "#+bibliography: %s
+#+cite_export: basic
+Author: [cite/a:Citing ; @friends; and @friends also; is duplication.]"
+ (expand-file-name "examples/Basic.bib" org-test-dir))
+ (let ((export-buffer "*Test ASCII Export*")
+ (org-export-show-temporary-export-buffer nil))
+ (org-export-to-buffer 'ascii export-buffer)
+ (with-current-buffer export-buffer
+ (let ((case-fold-search t))
+ (should
+ (search-forward "Author: Citing van Dongen, M.R.C., and van Dongen,
M.R.C. also is
+duplication." nil t))))))
+ ;; "note" citation style.
+ (org-test-with-temp-text
+ (format
+ "#+bibliography: %s
+#+cite_export: basic
+Note: [cite/ft:Citing ; @friends; and @friends also; is duplication.]"
+ (expand-file-name "examples/Basic.bib" org-test-dir))
+ (let ((export-buffer "*Test ASCII Export*")
+ (org-export-show-temporary-export-buffer nil))
+ (org-export-to-buffer 'ascii export-buffer)
+ (with-current-buffer export-buffer
+ (let ((case-fold-search t))
+ (should
+ (search-forward "[1] Citing van Dongen, M.R.C. (2012), and van
Dongen, M.R.C. (2012) also
+is duplication." nil t))))))
+ ;; "nocite" citation style.
+ (org-test-with-temp-text
+ (format
+ "#+bibliography: %s
+#+cite_export: basic
+Nocite (should be blank): [cite/n:Citing ; @friends; and @friends also; is
duplication.]"
+ (expand-file-name "examples/Basic.bib" org-test-dir))
+ (let ((export-buffer "*Test ASCII Export*")
+ (org-export-show-temporary-export-buffer nil))
+ (org-export-to-buffer 'ascii export-buffer)
+ (with-current-buffer export-buffer
+ (let ((case-fold-search t))
+ (should (search-forward "Nocite (should be blank):\n" nil t))
+ (goto-char (point-min))
+ (should-not (search-forward "2012" nil t))
+ (goto-char (point-min))
+ (should-not (search-forward "Dongen" nil t))))))
+ ;; "noauthor" citation style.
+ (org-test-with-temp-text
+ (format
+ "#+bibliography: %s
+#+cite_export: basic
+Noauthor: [cite/na:Citing ; @friends; and @friends also; is duplication.]"
+ (expand-file-name "examples/Basic.bib" org-test-dir))
+ (let ((export-buffer "*Test ASCII Export*")
+ (org-export-show-temporary-export-buffer nil))
+ (org-export-to-buffer 'ascii export-buffer)
+ (with-current-buffer export-buffer
+ (let ((case-fold-search t))
+ (should
+ (search-forward "Noauthor: (Citing 2012, and 2012 also is
duplication.)" nil t))))))
+ ;; "numeric" citation style.
+ (org-test-with-temp-text
+ (format
+ "#+bibliography: %s
+#+cite_export: basic
+Numeric (should \"use global affixes and ignore local ones\"): [cite/nb:Citing
; @friends; and @friends also; is duplication.]"
+ (expand-file-name "examples/Basic.bib" org-test-dir))
+ (let ((export-buffer "*Test ASCII Export*")
+ (org-export-show-temporary-export-buffer nil))
+ (org-export-to-buffer 'ascii export-buffer)
+ (with-current-buffer export-buffer
+ (let ((case-fold-search t))
+ (should
+ (search-forward "Numeric (should \"use global affixes and ignore
local ones\"): (Citing 1,
+1 is duplication.)" nil t))))))
+ ;; "text" citation style.
+ (org-test-with-temp-text
+ (format
+ "#+bibliography: %s
+#+cite_export: basic
+Text: [cite/t: Citing ; @friends; and @friends also; is duplication.]"
+ (expand-file-name "examples/Basic.bib" org-test-dir))
+ (let ((export-buffer "*Test ASCII Export*")
+ (org-export-show-temporary-export-buffer nil))
+ (org-export-to-buffer 'ascii export-buffer)
+ (with-current-buffer export-buffer
+ (let ((case-fold-search t))
+ (should
+ (search-forward "Text: Citing van Dongen, M.R.C. (2012), and van
Dongen, M.R.C. (2012)
+also is duplication." nil t)))))))
+
+(provide 'test-oc-basic)
+;;; test-oc-basic.el ends here