From a737f20ca42738170e89129a2f4b5baeb9492f9a Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sat, 26 Mar 2016 00:20:08 +0100 Subject: [PATCH] org-table: Add tests * testing/lisp/test-org-table.el (test-org-table/eval-formula): (test-org-table/last-rc): New tests. (test-org-table/first-rc): Add tests. --- testing/lisp/test-org-table.el | 63 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/testing/lisp/test-org-table.el b/testing/lisp/test-org-table.el index 2bfebb44f..efa88fd2d 100644 --- a/testing/lisp/test-org-table.el +++ b/testing/lisp/test-org-table.el @@ -1673,7 +1673,41 @@ See also `test-org-table/copy-field'." (buffer-string))))) -;;; Field formulas +;;; Formulas + +(ert-deftest test-org-table/eval-formula () + "Test `org-table-eval-formula' specifications." + ;; Error when not on a table field. + (should-error + (org-test-with-temp-text "Text" + (org-table-eval-formula))) + (should-error + (org-test-with-temp-text "| a |\n|---|" + (org-table-eval-formula))) + (should-error + (org-test-with-temp-text "| a |\n#+TBLFM:" + (org-table-eval-formula))) + ;; Handle @<, @>, $< and $>. + (should + (equal "| 1 |\n| 1 |" + (org-test-with-temp-text "| |\n| 1 |" + (org-table-eval-formula nil "@>" nil nil t) + (buffer-string)))) + (should + (equal "| 1 |\n| 1 |" + (org-test-with-temp-text "| 1 |\n| |" + (org-table-eval-formula nil "@<" nil nil t) + (buffer-string)))) + (should + (equal "| 1 | 1 |" + (org-test-with-temp-text "| | 1 |" + (org-table-eval-formula nil "$>" nil nil t) + (buffer-string)))) + (should + (equal "| 1 | 1 |" + (org-test-with-temp-text "| 1 | |" + (org-table-eval-formula nil "$<" nil nil t) + (buffer-string))))) (ert-deftest test-org-table/field-formula-outside-table () "If `org-table-formula-create-columns' is nil, then a formula @@ -1840,7 +1874,7 @@ is t, then new columns should be added as needed" (buffer-string))))) (ert-deftest test-org-table/first-rc () - "Test \"$<\" constructs in formulas." + "Test \"$<\" and \"@<\" constructs in formulas." (should (org-string-match-p "| 1 | 2 |" @@ -1848,6 +1882,31 @@ is t, then new columns should be added as needed" "| | 2 | #+TBLFM: $<=1" (org-table-calc-current-TBLFM) + (buffer-string)))) + (should + (org-string-match-p + "| 2 |\n| 2 |" + (org-test-with-temp-text + "| 2 |\n| | +#+TBLFM: @2$1=@<" + (org-table-calc-current-TBLFM) + (buffer-string))))) + +(ert-deftest test-org-table/last-rc () + "Test \"$>\" and \"@>\" constructs in formulas." + (should + (org-string-match-p + "| 2 | 1 |" + (org-test-with-temp-text + "| 2 | |\n#+TBLFM: $>=1" + (org-table-calc-current-TBLFM) + (buffer-string)))) + (should + (org-string-match-p + "| 2 |\n| 2 |" + (org-test-with-temp-text + "| 2 |\n| |\n#+TBLFM: @>$1=@<" + (org-table-calc-current-TBLFM) (buffer-string))))) -- 2.11.4.GIT