test-org-table.el 3.0 KB

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