diff options
author | Kyle Meyer <kyle@kyleam.com> | 2014-02-02 23:50:16 -0500 |
---|---|---|
committer | Kyle Meyer <kyle@kyleam.com> | 2014-02-03 00:23:31 -0500 |
commit | 2626b234016d3a826dde5b11c321512c98e12214 (patch) | |
tree | 44aa3cb09b949a637d08b8b37784f22f3f690f63 /bog-tests.el | |
parent | 9fe3a4cc25190682554ccc6eef94dd19928af8b2 (diff) | |
download | bog-2626b234016d3a826dde5b11c321512c98e12214.tar.gz |
Add core citekey functions
Diffstat (limited to 'bog-tests.el')
-rw-r--r-- | bog-tests.el | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/bog-tests.el b/bog-tests.el new file mode 100644 index 0000000..e7ce2cc --- /dev/null +++ b/bog-tests.el @@ -0,0 +1,116 @@ +(require 'ert) +(require 'org) +(require 'bog) + + +;;; Citekey functions + +;; `bog-citekey-p' + +(ert-deftest bog-citekey-p () + (should (bog-citekey-p "name2010word")) + (should (bog-citekey-p "name1900word")) + (should-not (bog-citekey-p "name201word"))) + +(ert-deftest bog-citekey-p-with-hyphen-in-name () + (should (bog-citekey-p "hyphen-ok2010word"))) + +(ert-deftest bog-citekey-p-with-other-text () + (should (bog-citekey-p "name2010word more text"))) + +(ert-deftest bog-citekey-only-p () + (should (bog-citekey-only-p "name2010word")) + (should-not (bog-citekey-only-p "name201word")) + (should (bog-citekey-only-p "hyphen-ok2010word")) + (should-not (bog-citekey-only-p "name2010word more text"))) + +;; `bog-citekey-groups-with-delim' + +(ert-deftest bog-citekey-groups-with-delim () + (let ((citekey "name2010word")) + (should (equal (bog-citekey-groups-with-delim citekey) + "name 2010 word")) + (should (equal (bog-citekey-groups-with-delim citekey ",") + "name,2010,word")) + (should (equal (bog-citekey-groups-with-delim citekey nil '(1 3)) + "name word")))) + +;; `bog-citekey-at-point' + +(ert-deftest bog-citekey-at-point () + (let ((citekey "name2010word")) + (with-temp-buffer + (insert citekey) + (goto-char (point-min)) + (should (equal (bog-citekey-at-point) citekey))))) + +;; `bog-citekey-heading' + +(ert-deftest bog-citekey-heading-current-level () + (let ((citekey "name2010word")) + (with-temp-buffer + (insert (format "\n* top level\n\n** %s\n\nsome text\n" + citekey)) + (org-mode) + (show-all) + (should (equal (bog-citekey-heading) citekey))))) + +(ert-deftest bog-citekey-heading-in-parent () + (let ((citekey "name2010word")) + (with-temp-buffer + (insert (format "\n* top level\n\n** %s\n\n*** subheading\n\nsome text\n" + citekey)) + (org-mode) + (show-all) + (should (equal (bog-citekey-heading) citekey))))) + +(ert-deftest bog-citekey-heading-on-heading () + (let ((citekey "name2010word")) + (with-temp-buffer + (insert (format "\n* top level\n\n** %s\n\nsome text\n" + citekey)) + (org-mode) + (show-all) + (re-search-backward bog-citekey-format) + (should (equal (bog-citekey-heading) citekey))))) + +(ert-deftest bog-citekey-action-in-normal-text () + (let ((citekey "name2010word")) + (with-temp-buffer + (insert (format "\n* top level\n\n** %s\n\nsome text\n" + citekey)) + (org-mode) + (show-all) + (flet ((funcall (action citekey) citekey)) + (should (equal (bog-citekey-action nil nil nil) citekey)))))) + +;; `bog-citekey-action' + +(ert-deftest bog-citekey-action-on-heading () + (let ((citekey "name2010word")) + (with-temp-buffer + (insert (format "\n* top level\n\n** %s\n\nsome text\n" + citekey)) + (org-mode) + (show-all) + (re-search-backward bog-citekey-format) + (flet ((funcall (action citekey) citekey)) + (should (equal (bog-citekey-action nil nil nil) citekey)))))) + +(ert-deftest bog-citekey-action-on-in-text-citekey () + (let ((citekey "name2010word")) + (with-temp-buffer + (insert (format "\n* top level\n\n** other2000key\n\nsome text and %s\n" + citekey)) + (org-mode) + (show-all) + (re-search-backward bog-citekey-format) + (flet ((funcall (action citekey) citekey)) + (should (equal (bog-citekey-action nil nil nil) citekey)))))) + +(ert-deftest bog-citekey-action-no-citekey () + (with-temp-buffer + (insert "\n* top level\n\n** second\n\n") + (org-mode) + (show-all) + (should-error (bog-citekey-action nil nil nil)))) |