test-org-table.el 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. ;;; test-org-table.el --- tests for org-table.el
  2. ;; Copyright (c) David Maus
  3. ;; Authors: David Maus, Michael Brand
  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. First the tests that are
  17. ;; also a howto example collection as a user documentation, more or
  18. ;; less all those using `org-test-table-target-expect'. Then the
  19. ;; internal and more abstract tests. See also the doc string of
  20. ;; `org-test-table-target-expect'.
  21. ;;; Code:
  22. (require 'org-table) ; `org-table-make-reference'
  23. (ert-deftest test-org-table/simple-formula/no-grouping/no-title-row ()
  24. "Simple sum without grouping rows, without title row."
  25. (org-test-table-target-expect
  26. "
  27. | 2 |
  28. | 4 |
  29. | 8 |
  30. | replace |
  31. "
  32. "
  33. | 2 |
  34. | 4 |
  35. | 8 |
  36. | 14 |
  37. "
  38. 1
  39. ;; Calc formula
  40. "#+TBLFM: @>$1 = vsum(@<..@>>)"
  41. ;; Lisp formula
  42. "#+TBLFM: @>$1 = '(+ @<..@>>); N"))
  43. (ert-deftest test-org-table/simple-formula/no-grouping/with-title-row ()
  44. "Simple sum without grouping rows, with title row."
  45. (org-test-table-target-expect
  46. "
  47. | foo |
  48. |---------|
  49. | 2 |
  50. | 4 |
  51. | 8 |
  52. | replace |
  53. "
  54. "
  55. | foo |
  56. |-----|
  57. | 2 |
  58. | 4 |
  59. | 8 |
  60. | 14 |
  61. "
  62. 1
  63. ;; Calc formula
  64. "#+TBLFM: @>$1 = vsum(@I..@>>)"
  65. ;; Lisp formula
  66. "#+TBLFM: @>$1 = '(+ @I..@>>); N"))
  67. (ert-deftest test-org-table/simple-formula/with-grouping/no-title-row ()
  68. "Simple sum with grouping rows, how not to do."
  69. ;; The first example has a problem, see the second example in this
  70. ;; ert-deftest.
  71. (org-test-table-target-expect
  72. "
  73. | 2 |
  74. | 4 |
  75. | 8 |
  76. |---------|
  77. | replace |
  78. "
  79. "
  80. | 2 |
  81. | 4 |
  82. | 8 |
  83. |----|
  84. | 14 |
  85. "
  86. 1
  87. ;; Calc formula
  88. "#+TBLFM: $1 = vsum(@<..@>>)"
  89. ;; Lisp formula
  90. "#+TBLFM: $1 = '(+ @<..@>>); N")
  91. ;; The problem is that the first three rows with the summands are
  92. ;; considered the header and therefore column formulas are not
  93. ;; applied on them as shown below. Also export behaves unexpected.
  94. ;; See next ert-deftest how to group rows right.
  95. (org-test-table-target-expect
  96. "
  97. | 2 | replace |
  98. | 4 | replace |
  99. | 8 | replace |
  100. |---------+---------|
  101. | replace | replace |
  102. "
  103. "
  104. | 2 | replace |
  105. | 4 | replace |
  106. | 8 | replace |
  107. |----+---------|
  108. | 14 | 28 |
  109. "
  110. 2
  111. ;; Calc formula
  112. "#+TBLFM: @>$1 = vsum(@<..@>>) :: $2 = 2 * $1"
  113. ;; Lisp formula
  114. "#+TBLFM: @>$1 = '(+ @<..@>>); N :: $2 = '(* 2 $1); N"))
  115. (ert-deftest test-org-table/simple-formula/with-grouping/with-title-row ()
  116. "Simple sum with grouping rows, how to do it right."
  117. ;; Always add a top row with the column names separated by hline to
  118. ;; get the desired header when you want to group rows.
  119. (org-test-table-target-expect
  120. "
  121. | foo | bar |
  122. |---------+---------|
  123. | 2 | replace |
  124. | 4 | replace |
  125. | 8 | replace |
  126. |---------+---------|
  127. | replace | replace |
  128. "
  129. "
  130. | foo | bar |
  131. |-----+-----|
  132. | 2 | 4 |
  133. | 4 | 8 |
  134. | 8 | 16 |
  135. |-----+-----|
  136. | 14 | 28 |
  137. "
  138. 2
  139. ;; Calc formula
  140. "#+TBLFM: @>$1 = vsum(@I..@>>) :: $2 = 2 * $1"
  141. ;; Lisp formula
  142. "#+TBLFM: @>$1 = '(+ @I..@>>); N :: $2 = '(* 2 $1); N"))
  143. (ert-deftest test-org-table/align ()
  144. "Align columns within Org buffer, depends on `org-table-number-regexp'."
  145. (org-test-table-target-expect "
  146. | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
  147. | ab | 12 | 12.2 | 2.4e-08 | 2x10^12 | 4.034+-0.02 | 2.7(10) | >3.5 |
  148. | ab | ab | ab | ab | ab | ab | ab | ab |
  149. ")
  150. (org-test-table-target-expect "
  151. | 0 | 0 | 0 | 0 | 0 | 0 |
  152. | <-0x0ab.cf | >-36#0vw.yz | nan | uinf | -inf | inf |
  153. | ab | ab | ab | ab | ab | ab |
  154. "))
  155. (defconst references/target-normal "
  156. | 0 | 1 | replace | replace | replace | replace | replace | replace |
  157. | z | 1 | replace | replace | replace | replace | replace | replace |
  158. | | 1 | replace | replace | replace | replace | replace | replace |
  159. | | | replace | replace | replace | replace | replace | replace |
  160. "
  161. "Normal numbers and non-numbers for Lisp and Calc formula.")
  162. (defconst references/target-special "
  163. | nan | 1 | replace | replace | replace | replace | replace | replace |
  164. | uinf | 1 | replace | replace | replace | replace | replace | replace |
  165. | -inf | 1 | replace | replace | replace | replace | replace | replace |
  166. | inf | 1 | replace | replace | replace | replace | replace | replace |
  167. "
  168. "Special numbers for Calc formula.")
  169. (ert-deftest test-org-table/references/format-specifier-EL ()
  170. "Basic: Assign field reference, sum of field references, sum
  171. and len of simple range reference (no row) and complex range
  172. reference (with row). Format specifier EL."
  173. ;; Empty fields are kept during parsing field but lost as list
  174. ;; elements within Lisp formula syntactically when used literally
  175. ;; and not enclosed with " within fields, see last columns with len.
  176. (org-test-table-target-expect
  177. references/target-normal
  178. ;; All the #ERROR show that for Lisp calculations N has to be used.
  179. "
  180. | 0 | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
  181. | z | 1 | z | #ERROR | #ERROR | #ERROR | 2 | 2 |
  182. | | 1 | | 1 | 1 | 1 | 1 | 1 |
  183. | | | | 0 | 0 | 0 | 0 | 0 |
  184. "
  185. 1 (concat
  186. "#+TBLFM: $3 = '(identity \"$1\"); EL :: $4 = '(+ $1 $2); EL :: "
  187. "$5 = '(+ $1..$2); EL :: $6 = '(+ @0$1..@0$2); EL :: "
  188. "$7 = '(length '($1..$2)); EL :: $8 = '(length '(@0$1..@0$2)); EL"))
  189. ;; Empty fields are kept during parsing field _and_ as list elements
  190. ;; within Lisp formula syntactically even when used literally when
  191. ;; enclosed with " within fields, see last columns with len.
  192. (org-test-table-target-expect
  193. "
  194. | \"0\" | \"1\" | repl | repl | repl | repl | repl | repl |
  195. | \"z\" | \"1\" | repl | repl | repl | repl | repl | repl |
  196. | \"\" | \"1\" | repl | repl | repl | repl | repl | repl |
  197. | \"\" | \"\" | repl | repl | repl | repl | repl | repl |
  198. "
  199. "
  200. | \"0\" | \"1\" | \"0\" | 1 | #ERROR | #ERROR | 2 | 2 |
  201. | \"z\" | \"1\" | \"z\" | 1 | #ERROR | #ERROR | 2 | 2 |
  202. | \"\" | \"1\" | \"\" | 1 | #ERROR | #ERROR | 2 | 2 |
  203. | \"\" | \"\" | \"\" | 0 | #ERROR | #ERROR | 2 | 2 |
  204. "
  205. 1 (concat
  206. "#+TBLFM: $3 = '(concat \"\\\"\" $1 \"\\\"\"); EL :: "
  207. "$4 = '(+ (string-to-number $1) (string-to-number $2)); EL :: "
  208. "$5 = '(+ $1..$2); EL :: $6 = '(+ @0$1..@0$2); EL :: "
  209. "$7 = '(length '($1..$2)); EL :: $8 = '(length '(@0$1..@0$2)); EL")))
  210. (ert-deftest test-org-table/references/format-specifier-E ()
  211. "Basic: Assign field reference, sum of field references, sum
  212. and len of simple range reference (no row) and complex range
  213. reference (with row). Format specifier E."
  214. (let ((lisp
  215. (concat
  216. "#+TBLFM: $3 = '(identity $1); E :: $4 = '(+ $1 $2); E :: "
  217. "$5 = '(+ $1..$2); E :: $6 = '(+ @0$1..@0$2); E :: "
  218. "$7 = '(length '($1..$2)); E :: $8 = '(length '(@0$1..@0$2)); E"))
  219. (calc
  220. (concat
  221. "#+TBLFM: $3 = $1; E :: $4 = $1 + $2; E :: "
  222. "$5 = vsum($1..$2); E :: $6 = vsum(@0$1..@0$2); E :: "
  223. "$7 = vlen($1..$2); E :: $8 = vlen(@0$1..@0$2); E")))
  224. (org-test-table-target-expect
  225. references/target-normal
  226. ;; All the #ERROR show that for Lisp calculations N has to be used.
  227. "
  228. | 0 | 1 | 0 | #ERROR | #ERROR | #ERROR | 2 | 2 |
  229. | z | 1 | z | #ERROR | #ERROR | #ERROR | 2 | 2 |
  230. | | 1 | | #ERROR | #ERROR | #ERROR | 2 | 2 |
  231. | | | | #ERROR | #ERROR | #ERROR | 2 | 2 |
  232. "
  233. 1 lisp)
  234. (org-test-table-target-expect
  235. references/target-normal
  236. "
  237. | 0 | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
  238. | z | 1 | z | z + 1 | z + 1 | z + 1 | 2 | 2 |
  239. | | 1 | 0 | 1 | #ERROR | #ERROR | #ERROR | #ERROR |
  240. | | | 0 | 0 | #ERROR | #ERROR | #ERROR | #ERROR |
  241. "
  242. 1 calc)
  243. (org-test-table-target-expect
  244. references/target-special
  245. "
  246. | nan | 1 | nan | nan | nan | nan | 2 | 2 |
  247. | uinf | 1 | uinf | uinf | uinf | uinf | 2 | 2 |
  248. | -inf | 1 | -inf | -inf | -inf | -inf | 2 | 2 |
  249. | inf | 1 | inf | inf | inf | inf | 2 | 2 |
  250. "
  251. 1 calc)))
  252. (ert-deftest test-org-table/references/format-specifier-EN ()
  253. "Basic: Assign field reference, sum of field references, sum
  254. and len of simple range reference (no row) and complex range
  255. reference (with row). Format specifier EN."
  256. (let ((lisp (concat
  257. "#+TBLFM: $3 = '(identity $1); EN :: $4 = '(+ $1 $2); EN :: "
  258. "$5 = '(+ $1..$2); EN :: $6 = '(+ @0$1..@0$2); EN :: "
  259. "$7 = '(length '($1..$2)); EN :: "
  260. "$8 = '(length '(@0$1..@0$2)); EN"))
  261. (calc (concat
  262. "#+TBLFM: $3 = $1; EN :: $4 = $1 + $2; EN :: "
  263. "$5 = vsum($1..$2); EN :: $6 = vsum(@0$1..@0$2); EN :: "
  264. "$7 = vlen($1..$2); EN :: $8 = vlen(@0$1..@0$2); EN")))
  265. (org-test-table-target-expect
  266. references/target-normal
  267. "
  268. | 0 | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
  269. | z | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
  270. | | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
  271. | | | 0 | 0 | 0 | 0 | 2 | 2 |
  272. "
  273. 1 lisp calc)
  274. (org-test-table-target-expect
  275. references/target-special
  276. "
  277. | nan | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
  278. | uinf | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
  279. | -inf | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
  280. | inf | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
  281. "
  282. 1 calc)))
  283. (ert-deftest test-org-table/references/format-specifier-L ()
  284. "Basic: Assign field reference, sum of field references, sum
  285. and len of simple range reference (no row) and complex range
  286. reference (with row). Format specifier L."
  287. (org-test-table-target-expect
  288. references/target-normal
  289. ;; All the #ERROR show that for Lisp calculations N has to be used.
  290. ;; TODO: Len for range reference with only empty fields should be 0.
  291. "
  292. | 0 | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
  293. | z | 1 | z | #ERROR | #ERROR | #ERROR | 2 | 2 |
  294. | | 1 | | 1 | 1 | 1 | 1 | 1 |
  295. | | | | 0 | 0 | 0 | 1 | 1 |
  296. "
  297. 1 (concat
  298. "#+TBLFM: $3 = '(identity \"$1\"); L :: $4 = '(+ $1 $2); L :: "
  299. "$5 = '(+ $1..$2); L :: $6 = '(+ @0$1..@0$2); L :: "
  300. "$7 = '(length '($1..$2)); L :: $8 = '(length '(@0$1..@0$2)); L")))
  301. (ert-deftest test-org-table/references/format-specifier-none ()
  302. "Basic: Assign field reference, sum of field references, sum
  303. and len of simple range reference (no row) and complex range
  304. reference (with row). No format specifier."
  305. (let ((lisp (concat
  306. "#+TBLFM: $3 = '(identity $1) :: $4 = '(+ $1 $2) :: "
  307. "$5 = '(+ $1..$2) :: $6 = '(+ @0$1..@0$2) :: "
  308. "$7 = '(length '($1..$2)) :: $8 = '(length '(@0$1..@0$2))"))
  309. (calc (concat
  310. "#+TBLFM: $3 = $1 :: $4 = $1 + $2 :: "
  311. "$5 = vsum($1..$2) :: $6 = vsum(@0$1..@0$2) :: "
  312. "$7 = vlen($1..$2) :: $8 = vlen(@0$1..@0$2)")))
  313. (org-test-table-target-expect
  314. references/target-normal
  315. ;; All the #ERROR show that for Lisp calculations N has to be used.
  316. "
  317. | 0 | 1 | 0 | #ERROR | #ERROR | #ERROR | 2 | 2 |
  318. | z | 1 | z | #ERROR | #ERROR | #ERROR | 2 | 2 |
  319. | | 1 | | #ERROR | #ERROR | #ERROR | 1 | 1 |
  320. | | | | #ERROR | #ERROR | #ERROR | 1 | 1 |
  321. "
  322. 1 lisp)
  323. (org-test-table-target-expect
  324. references/target-normal
  325. "
  326. | 0 | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
  327. | z | 1 | z | z + 1 | z + 1 | z + 1 | 2 | 2 |
  328. | | 1 | 0 | 1 | 1 | 1 | 1 | 1 |
  329. | | | 0 | 0 | 0 | 0 | 1 | 1 |
  330. "
  331. 1 calc)
  332. (org-test-table-target-expect
  333. references/target-special
  334. "
  335. | nan | 1 | nan | nan | nan | nan | 2 | 2 |
  336. | uinf | 1 | uinf | uinf | uinf | uinf | 2 | 2 |
  337. | -inf | 1 | -inf | -inf | -inf | -inf | 2 | 2 |
  338. | inf | 1 | inf | inf | inf | inf | 2 | 2 |
  339. "
  340. 1 calc)))
  341. (ert-deftest test-org-table/references/format-specifier-N ()
  342. "Basic: Assign field reference, sum of field references, sum
  343. and len of simple range reference (no row) and complex range
  344. reference (with row). Format specifier N."
  345. (let ((lisp
  346. (concat
  347. "#+TBLFM: $3 = '(identity $1); N :: $4 = '(+ $1 $2); N :: "
  348. "$5 = '(+ $1..$2); N :: $6 = '(+ @0$1..@0$2); N :: "
  349. "$7 = '(length '($1..$2)); N :: $8 = '(length '(@0$1..@0$2)); N"))
  350. (calc
  351. (concat
  352. "#+TBLFM: $3 = $1; N :: $4 = $1 + $2; N :: "
  353. "$5 = vsum($1..$2); N :: $6 = vsum(@0$1..@0$2); N :: "
  354. "$7 = vlen($1..$2); N :: $8 = vlen(@0$1..@0$2); N")))
  355. (org-test-table-target-expect
  356. references/target-normal
  357. ;; TODO: Len for simple range reference with empty field should
  358. ;; also be 1
  359. "
  360. | 0 | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
  361. | z | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
  362. | | 1 | 0 | 1 | 1 | 1 | 2 | 1 |
  363. | | | 0 | 0 | 0 | 0 | 2 | 1 |
  364. "
  365. 1 lisp calc)
  366. (org-test-table-target-expect
  367. references/target-special
  368. "
  369. | nan | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
  370. | uinf | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
  371. | -inf | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
  372. | inf | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
  373. "
  374. 1 calc)))
  375. (ert-deftest test-org-table/compare ()
  376. "Basic: Compare field references in Calc."
  377. (org-test-table-target-expect
  378. "
  379. | | 0 | z | nan | uinf | -inf | inf |
  380. |------+------+------+------+------+------+------|
  381. | 0 | repl | repl | repl | repl | repl | repl |
  382. | z | repl | repl | repl | repl | repl | repl |
  383. | nan | repl | repl | repl | repl | repl | repl |
  384. | uinf | repl | repl | repl | repl | repl | repl |
  385. | -inf | repl | repl | repl | repl | repl | repl |
  386. | inf | repl | repl | repl | repl | repl | repl |
  387. "
  388. "
  389. | | 0 | z | nan | uinf | -inf | inf |
  390. |------+---+---+-----+------+------+-----|
  391. | 0 | x | | | | | |
  392. | z | | x | | | | |
  393. | nan | | | x | | | |
  394. | uinf | | | | x | | |
  395. | -inf | | | | | x | |
  396. | inf | | | | | | x |
  397. "
  398. 1
  399. ;; Compare field reference ($1) with field reference (@1)
  400. "#+TBLFM: @I$<<..@>$> = if(\"$1\" = \"@1\", x, string(\"\")); E"
  401. ;; Compare field reference ($1) with absolute term
  402. (concat "#+TBLFM: "
  403. "$2 = if(\"$1\" = \"(0)\" , x, string(\"\")); E :: "
  404. "$3 = if(\"$1\" = \"(z)\" , x, string(\"\")); E :: "
  405. "$4 = if(\"$1\" = \"(nan)\" , x, string(\"\")); E :: "
  406. "$5 = if(\"$1\" = \"(uinf)\", x, string(\"\")); E :: "
  407. "$6 = if(\"$1\" = \"(-inf)\", x, string(\"\")); E :: "
  408. "$7 = if(\"$1\" = \"(inf)\" , x, string(\"\")); E"))
  409. ;; Check field reference converted from an empty field: Despite this
  410. ;; field reference will not end up in a result, Calc evaluates it.
  411. ;; Make sure that also then there is no Calc error.
  412. (org-test-table-target-expect
  413. "
  414. | 0 | replace |
  415. | z | replace |
  416. | nan | replace |
  417. "
  418. "
  419. | 0 | 1 |
  420. | z | z + 1 |
  421. | nan | nan |
  422. "
  423. 1 "#+TBLFM: $2 = if(\"$1\" = \"nan\", string(\"\"), $1 + 1); E"))
  424. (ert-deftest test-org-table/empty-field ()
  425. "Examples how to deal with empty fields."
  426. ;; Empty fields in simple and complex range reference: Suppress them
  427. ;; ($5 and $6) or keep them and use 0 ($7 and $8)
  428. ;; Calc formula
  429. (org-test-table-target-expect
  430. "\n| | | 5 | 7 | replace | replace | replace | replace |\n"
  431. "\n| | | 5 | 7 | 6 | 6 | 3 | 3 |\n"
  432. 1
  433. (concat "#+TBLFM: "
  434. "$5 = vmean($1..$4) :: $6 = vmean(@0$1..@0$4) :: "
  435. "$7 = vmean($1..$4); EN :: $8 = vmean(@0$1..@0$4); EN"))
  436. ;; Lisp formula
  437. ;; TODO: Len for simple range reference with empty field should also
  438. ;; be 6
  439. (org-test-table-target-expect
  440. "\n| | | 5 | 7 | replace | replace | replace | replace |\n"
  441. "\n| | | 5 | 7 | 3 | 6 | 3 | 3 |\n"
  442. 1
  443. (concat "#+TBLFM: "
  444. "$5 = '(/ (+ $1..$4 ) (length '( $1..$4 ))); N :: "
  445. "$6 = '(/ (+ @0$1..@0$4) (length '(@0$1..@0$4))); N :: "
  446. "$7 = '(/ (+ $1..$4 ) (length '( $1..$4 ))); EN :: "
  447. "$8 = '(/ (+ @0$1..@0$4) (length '(@0$1..@0$4))); EN")))
  448. ;; End of table examples and beginning of internal tests.
  449. (ert-deftest test-org-table/org-table-make-reference/format-specifier-EL ()
  450. (fset 'f 'org-table-make-reference)
  451. ;; For Lisp formula only
  452. (should (equal "0" (f "0" t nil 'literal)))
  453. (should (equal "z" (f "z" t nil 'literal)))
  454. (should (equal "" (f "" t nil 'literal)))
  455. (should (equal "0 1" (f '("0" "1") t nil 'literal)))
  456. (should (equal "z 1" (f '("z" "1") t nil 'literal)))
  457. (should (equal " 1" (f '("" "1") t nil 'literal)))
  458. (should (equal " " (f '("" "" ) t nil 'literal))))
  459. (ert-deftest test-org-table/org-table-make-reference/format-specifier-E ()
  460. (fset 'f 'org-table-make-reference)
  461. ;; For Lisp formula
  462. (should (equal "\"0\"" (f "0" t nil t)))
  463. (should (equal "\"z\"" (f "z" t nil t)))
  464. (should (equal "\"\"" (f "" t nil t)))
  465. (should (equal "\"0\" \"1\"" (f '("0" "1") t nil t)))
  466. (should (equal "\"z\" \"1\"" (f '("z" "1") t nil t)))
  467. (should (equal "\"\" \"1\"" (f '("" "1") t nil t)))
  468. (should (equal "\"\" \"\"" (f '("" "" ) t nil t)))
  469. ;; For Calc formula
  470. (should (equal "(0)" (f "0" t nil nil)))
  471. (should (equal "(z)" (f "z" t nil nil)))
  472. (should (equal "(0)" (f "" t nil nil)))
  473. (should (equal "[0,1]" (f '("0" "1") t nil nil)))
  474. (should (equal "[z,1]" (f '("z" "1") t nil nil)))
  475. (should (equal "[,1]" (f '("" "1") t nil nil)))
  476. (should (equal "[,]" (f '("" "" ) t nil nil)))
  477. ;; For Calc formula, special numbers
  478. (should (equal "(nan)" (f "nan" t nil nil)))
  479. (should (equal "(uinf)" (f "uinf" t nil nil)))
  480. (should (equal "(-inf)" (f "-inf" t nil nil)))
  481. (should (equal "(inf)" (f "inf" t nil nil)))
  482. (should (equal "[nan,1]" (f '( "nan" "1") t nil nil)))
  483. (should (equal "[uinf,1]" (f '("uinf" "1") t nil nil)))
  484. (should (equal "[-inf,1]" (f '("-inf" "1") t nil nil)))
  485. (should (equal "[inf,1]" (f '( "inf" "1") t nil nil))))
  486. (ert-deftest test-org-table/org-table-make-reference/format-specifier-EN ()
  487. (fset 'f 'org-table-make-reference)
  488. ;; For Lisp formula
  489. (should (equal "0" (f "0" t t t)))
  490. (should (equal "0" (f "z" t t t)))
  491. (should (equal "0" (f "" t t t)))
  492. (should (equal "0 1" (f '("0" "1") t t t)))
  493. (should (equal "0 1" (f '("z" "1") t t t)))
  494. (should (equal "0 1" (f '("" "1") t t t)))
  495. (should (equal "0 0" (f '("" "" ) t t t)))
  496. ;; For Calc formula
  497. (should (equal "(0)" (f "0" t t nil)))
  498. (should (equal "(0)" (f "z" t t nil)))
  499. (should (equal "(0)" (f "" t t nil)))
  500. (should (equal "[0,1]" (f '("0" "1") t t nil)))
  501. (should (equal "[0,1]" (f '("z" "1") t t nil)))
  502. (should (equal "[0,1]" (f '("" "1") t t nil)))
  503. (should (equal "[0,0]" (f '("" "" ) t t nil)))
  504. ;; For Calc formula, special numbers
  505. (should (equal "(0)" (f "nan" t t nil)))
  506. (should (equal "(0)" (f "uinf" t t nil)))
  507. (should (equal "(0)" (f "-inf" t t nil)))
  508. (should (equal "(0)" (f "inf" t t nil)))
  509. (should (equal "[0,1]" (f '( "nan" "1") t t nil)))
  510. (should (equal "[0,1]" (f '("uinf" "1") t t nil)))
  511. (should (equal "[0,1]" (f '("-inf" "1") t t nil)))
  512. (should (equal "[0,1]" (f '( "inf" "1") t t nil))))
  513. (ert-deftest test-org-table/org-table-make-reference/format-specifier-L ()
  514. (fset 'f 'org-table-make-reference)
  515. ;; For Lisp formula only
  516. (should (equal "0" (f "0" nil nil 'literal)))
  517. (should (equal "z" (f "z" nil nil 'literal)))
  518. (should (equal "" (f "" nil nil 'literal)))
  519. (should (equal "0 1" (f '("0" "1") nil nil 'literal)))
  520. (should (equal "z 1" (f '("z" "1") nil nil 'literal)))
  521. (should (equal "1" (f '("" "1") nil nil 'literal)))
  522. ;; TODO: Should result in empty string like with field reference of
  523. ;; empty field.
  524. (should (equal "0" (f '("" "" ) nil nil 'literal))))
  525. (ert-deftest test-org-table/org-table-make-reference/format-specifier-none ()
  526. (fset 'f 'org-table-make-reference)
  527. ;; For Lisp formula
  528. (should (equal "\"0\"" (f "0" nil nil t)))
  529. (should (equal "\"z\"" (f "z" nil nil t)))
  530. (should (equal "\"\"" (f "" nil nil t)))
  531. (should (equal "\"0\" \"1\"" (f '("0" "1") nil nil t)))
  532. (should (equal "\"z\" \"1\"" (f '("z" "1") nil nil t)))
  533. (should (equal "\"1\"" (f '("" "1") nil nil t)))
  534. ;; TODO: Should result in empty string like with field reference of
  535. ;; empty field.
  536. (should (equal "\"0\"" (f '("" "" ) nil nil t)))
  537. ;; For Calc formula
  538. (should (equal "(0)" (f "0" nil nil nil)))
  539. (should (equal "(z)" (f "z" nil nil nil)))
  540. (should (equal "(0)" (f "" nil nil nil)))
  541. (should (equal "[0,1]" (f '("0" "1") nil nil nil)))
  542. (should (equal "[z,1]" (f '("z" "1") nil nil nil)))
  543. (should (equal "[1]" (f '("" "1") nil nil nil)))
  544. (should (equal "[0]" (f '("" "" ) nil nil nil)))
  545. ;; For Calc formula, special numbers
  546. (should (equal "(nan)" (f "nan" nil nil nil)))
  547. (should (equal "(uinf)" (f "uinf" nil nil nil)))
  548. (should (equal "(-inf)" (f "-inf" nil nil nil)))
  549. (should (equal "(inf)" (f "inf" nil nil nil)))
  550. (should (equal "[nan,1]" (f '( "nan" "1") nil nil nil)))
  551. (should (equal "[uinf,1]" (f '("uinf" "1") nil nil nil)))
  552. (should (equal "[-inf,1]" (f '("-inf" "1") nil nil nil)))
  553. (should (equal "[inf,1]" (f '( "inf" "1") nil nil nil))))
  554. (ert-deftest test-org-table/org-table-make-reference/format-specifier-N ()
  555. (fset 'f 'org-table-make-reference)
  556. ;; For Lisp formula
  557. (should (equal "0" (f "0" nil t t)))
  558. (should (equal "0" (f "z" nil t t)))
  559. (should (equal "0" (f "" nil t t)))
  560. (should (equal "0 1" (f '("0" "1") nil t t)))
  561. (should (equal "0 1" (f '("z" "1") nil t t)))
  562. (should (equal "1" (f '("" "1") nil t t)))
  563. (should (equal "0" (f '("" "" ) nil t t)))
  564. ;; For Calc formula
  565. (should (equal "(0)" (f "0" nil t nil)))
  566. (should (equal "(0)" (f "z" nil t nil)))
  567. (should (equal "(0)" (f "" nil t nil)))
  568. (should (equal "[0,1]" (f '("0" "1") nil t nil)))
  569. (should (equal "[0,1]" (f '("z" "1") nil t nil)))
  570. (should (equal "[1]" (f '("" "1") nil t nil)))
  571. (should (equal "[0]" (f '("" "" ) nil t nil)))
  572. ;; For Calc formula, special numbers
  573. (should (equal "(0)" (f "nan" nil t nil)))
  574. (should (equal "(0)" (f "uinf" nil t nil)))
  575. (should (equal "(0)" (f "-inf" nil t nil)))
  576. (should (equal "(0)" (f "inf" nil t nil)))
  577. (should (equal "[0,1]" (f '( "nan" "1") nil t nil)))
  578. (should (equal "[0,1]" (f '("uinf" "1") nil t nil)))
  579. (should (equal "[0,1]" (f '("-inf" "1") nil t nil)))
  580. (should (equal "[0,1]" (f '( "inf" "1") nil t nil))))
  581. (ert-deftest test-org-table/org-table-convert-refs-to-an/1 ()
  582. "Simple reference @1$1."
  583. (should
  584. (string= "A1" (org-table-convert-refs-to-an "@1$1"))))
  585. ;; TODO: Test broken
  586. ;; (ert-deftest test-org-table/org-table-convert-refs-to-an/2 ()
  587. ;; "Self reference @1$1."
  588. ;; (should
  589. ;; (string= "A1 = $0" (org-table-convert-refs-to-an "@1$1 = $0"))))
  590. (ert-deftest test-org-table/org-table-convert-refs-to-an/3 ()
  591. "Remote reference."
  592. (should
  593. (string= "C& = remote(FOO, @@#B&)" (org-table-convert-refs-to-an "$3 = remote(FOO, @@#$2)"))))
  594. (ert-deftest test-org-table/org-table-convert-refs-to-rc/1 ()
  595. "Simple reference @1$1."
  596. (should
  597. (string= "@1$1" (org-table-convert-refs-to-rc "A1"))))
  598. (ert-deftest test-org-table/org-table-convert-refs-to-rc/2 ()
  599. "Self reference $0."
  600. (should
  601. (string= "@1$1 = $0" (org-table-convert-refs-to-rc "A1 = $0"))))
  602. ;; TODO: Test Broken
  603. ;; (ert-deftest test-org-table/org-table-convert-refs-to-rc/3 ()
  604. ;; "Remote reference."
  605. ;; (should
  606. ;; (string= "$3 = remote(FOO, @@#$2)" (org-table-convert-refs-to-rc "C& = remote(FOO, @@#B&)"))))
  607. (provide 'test-org-table)
  608. ;;; test-org-table.el ends here