From 102ab1a245bc00e321c3ce893d525684d5c52daa Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Thu, 18 Oct 2018 15:49:48 +0200 Subject: [PATCH] org-pcomplete: Add tests * testing/lisp/test-org-pcomplete.el (test-org-pcomplete/clocktable): (test-org-pcomplete/drawer): (test-org-pcomplete/entity): (test-org-pcomplete/link): (test-org-pcomplete/search-heading): (test-org-pcomplete/todo): New tests. --- testing/lisp/test-org-pcomplete.el | 104 +++++++++++++++++++++++++---- 1 file changed, 90 insertions(+), 14 deletions(-) diff --git a/testing/lisp/test-org-pcomplete.el b/testing/lisp/test-org-pcomplete.el index 56f7185e5..c9fa4c908 100644 --- a/testing/lisp/test-org-pcomplete.el +++ b/testing/lisp/test-org-pcomplete.el @@ -24,21 +24,39 @@ ;;; Code: -(ert-deftest test-org-pcomplete/prop () - "Test property completion." - ;; Drawer where we are currently completing property name is - ;; malformed in any case, it'll become valid only after successful - ;; completion. We expect that this completion process will finish - ;; successfully, and there will be no interactive drawer repair - ;; attempts. +(ert-deftest test-org-pcomplete/clocktable () + "Test completion of clock table parameters." (should - (equal - "* a\n:PROPERTIES:\n:pname: \n:END:\n* b\n:PROPERTIES:\n:pname: pvalue\n:END:\n" - (org-test-with-temp-text "* a\n:PROPERTIES:\n:pna\n:END:\n* b\n:PROPERTIES:\n:pname: pvalue\n:END:\n" - (cl-letf (((symbol-function 'y-or-n-p) - (lambda (_) (error "Should not be called")))) - (pcomplete)) - (buffer-string))))) + (equal "#+begin: clocktable :scope" + (org-test-with-temp-text "#+begin: clocktable :sco" + (pcomplete) + (buffer-string))))) + +(ert-deftest test-org-pcomplete/drawer () + "Test drawer completion." + (should + (equal "* Foo\n:PROPERTIES:" + (org-test-with-temp-text "* Foo\n:" + (pcomplete) + (buffer-string)))) + (should + (equal ":DRAWER:\nContents\n:END:\n* Foo\n:DRAWER:" + (org-test-with-temp-text ":DRAWER:\nContents\n:END:\n* Foo\n:D" + (pcomplete) + (buffer-string))))) + +(ert-deftest test-org-pcomplete/entity () + "Test entity completion." + (should + (equal "\\alpha" + (org-test-with-temp-text "\\alp" + (pcomplete) + (buffer-string)))) + (should + (equal "\\frac12" + (org-test-with-temp-text "\\frac1" + (pcomplete) + (buffer-string))))) (ert-deftest test-org-pcomplete/keyword () "Test keyword and block completion." @@ -57,5 +75,63 @@ (buffer-string)) t))) +(ert-deftest test-org-pcomplete/link () + "Test link completion" + (should + (equal "[[org:" + (org-test-with-temp-text "[[o" + (let ((org-link-abbrev-alist '(("org" . "https://orgmode.org/")))) + (pcomplete)) + (buffer-string)))) + (should-not + (equal "[org:" + (org-test-with-temp-text "[[o" + (let ((org-link-abbrev-alist '(("org" . "https://orgmode.org/")))) + (pcomplete)) + (buffer-string))))) + +(ert-deftest test-org-pcomplete/prop () + "Test property completion." + (should + (equal + " +* a +:PROPERTIES: +:pname:\s +:END: +* b +:PROPERTIES: +:pname: pvalue +:END: +" + (org-test-with-temp-text " +* a +:PROPERTIES: +:pna +:END: +* b +:PROPERTIES: +:pname: pvalue +:END: +" + (pcomplete) + (buffer-string))))) + +(ert-deftest test-org-pcomplete/search-heading () + "Test search heading completion." + (should + (equal "* Foo\n[[*Foo" + (org-test-with-temp-text "* Foo\n[[*" + (pcomplete) + (buffer-string))))) + +(ert-deftest test-org-pcomplete/todo () + "Test TODO completion." + (should + (equal "* TODO" + (org-test-with-temp-text "* T" + (pcomplete) + (buffer-string))))) + (provide 'test-org-pcomplete) ;;; test-org-pcomplete.el ends here