Add ERT for table alignment within Org buffer
[org-mode.git] / testing / lisp / test-org-table.el
blob4c899a86b39fa78ec87977edce4cc3c5be1dc942
1 ;;; test-org-table.el --- tests for org-table.el
3 ;; Copyright (c) David Maus
4 ;; Authors: David Maus
6 ;; This file is not part of GNU Emacs.
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ;;;; Comments:
23 ;; Template test file for Org-mode tests
25 ;;; Code:
27 (ert-deftest test-org-table/align ()
28 "Align columns within Org buffer, depends on `org-table-number-regexp'."
29 (org-test-table-target-expect "
30 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
31 | ab | 12 | 12.2 | 2.4e-08 | 2x10^12 | 4.034+-0.02 | 2.7(10) | >3.5 |
32 | ab | ab | ab | ab | ab | ab | ab | ab |
34 (org-test-table-target-expect "
35 | 0 | 0 | 0 | 0 | 0 | 0 |
36 | <-0x0ab.cf | >-36#0vw.yz | nan | uinf | -inf | inf |
37 | ab | ab | ab | ab | ab | ab |
38 "))
40 (ert-deftest test-org-table/org-table-convert-refs-to-an/1 ()
41 "Simple reference @1$1."
42 (should
43 (string= "A1" (org-table-convert-refs-to-an "@1$1"))))
45 ;; TODO: Test broken
46 ;; (ert-deftest test-org-table/org-table-convert-refs-to-an/2 ()
47 ;; "Self reference @1$1."
48 ;; (should
49 ;; (string= "A1 = $0" (org-table-convert-refs-to-an "@1$1 = $0"))))
51 (ert-deftest test-org-table/org-table-convert-refs-to-an/3 ()
52 "Remote reference."
53 (should
54 (string= "C& = remote(FOO, @@#B&)" (org-table-convert-refs-to-an "$3 = remote(FOO, @@#$2)"))))
56 (ert-deftest test-org-table/org-table-convert-refs-to-rc/1 ()
57 "Simple reference @1$1."
58 (should
59 (string= "@1$1" (org-table-convert-refs-to-rc "A1"))))
61 (ert-deftest test-org-table/org-table-convert-refs-to-rc/2 ()
62 "Self reference $0."
63 (should
64 (string= "@1$1 = $0" (org-table-convert-refs-to-rc "A1 = $0"))))
66 ;; TODO: Test Broken
67 ;; (ert-deftest test-org-table/org-table-convert-refs-to-rc/3 ()
68 ;; "Remote reference."
69 ;; (should
70 ;; (string= "$3 = remote(FOO, @@#$2)" (org-table-convert-refs-to-rc "C& = remote(FOO, @@#B&)"))))
72 (ert-deftest test-org-table/simple-formula ()
73 (org-test-with-temp-text-in-file "
75 * simple formula
76 :PROPERTIES:
77 :ID: 563523f7-3f3e-49c9-9622-9216cc9a5d95
78 :END:
80 #+tblname: simple-formula
81 | 1 |
82 | 2 |
83 | 3 |
84 | 4 |
85 |----|
86 | |
87 #+TBLFM: $1=vsum(@1..@-1)
89 (re-search-forward (regexp-quote "#+tblname: simple-formula") nil t)
90 (forward-line 1)
91 (should (org-at-table-p))
92 (should (org-table-recalculate 'all))
93 (should (string= "10" (first (nth 5 (org-table-to-lisp)))))))
95 (provide 'test-org-table)
97 ;;; test-org-table.el ends here