test-org-table.el 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074
  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. Many tests are also a howto
  17. ;; example collection as a user documentation, more or less all those
  18. ;; using `org-test-table-target-expect'. See also the doc string of
  19. ;; `org-test-table-target-expect'.
  20. ;;; Code:
  21. (require 'org-table) ; `org-table-make-reference'
  22. (ert-deftest test-org-table/simple-formula/no-grouping/no-title-row ()
  23. "Simple sum without grouping rows, without title row."
  24. (org-test-table-target-expect
  25. "
  26. | 2 |
  27. | 4 |
  28. | 8 |
  29. | replace |
  30. "
  31. "
  32. | 2 |
  33. | 4 |
  34. | 8 |
  35. | 14 |
  36. "
  37. 1
  38. ;; Calc formula
  39. "#+TBLFM: @>$1 = vsum(@<..@>>)"
  40. ;; Lisp formula
  41. "#+TBLFM: @>$1 = '(+ @<..@>>); N"))
  42. (ert-deftest test-org-table/simple-formula/no-grouping/with-title-row ()
  43. "Simple sum without grouping rows, with title row."
  44. (org-test-table-target-expect
  45. "
  46. | foo |
  47. |---------|
  48. | 2 |
  49. | 4 |
  50. | 8 |
  51. | replace |
  52. "
  53. "
  54. | foo |
  55. |-----|
  56. | 2 |
  57. | 4 |
  58. | 8 |
  59. | 14 |
  60. "
  61. 1
  62. ;; Calc formula
  63. "#+TBLFM: @>$1 = vsum(@I..@>>)"
  64. ;; Lisp formula
  65. "#+TBLFM: @>$1 = '(+ @I..@>>); N"))
  66. (ert-deftest test-org-table/simple-formula/with-grouping/no-title-row ()
  67. "Simple sum with grouping rows, how not to do."
  68. ;; The first example has a problem, see the second example in this
  69. ;; ert-deftest.
  70. (org-test-table-target-expect
  71. "
  72. | 2 |
  73. | 4 |
  74. | 8 |
  75. |---------|
  76. | replace |
  77. "
  78. "
  79. | 2 |
  80. | 4 |
  81. | 8 |
  82. |----|
  83. | 14 |
  84. "
  85. 1
  86. ;; Calc formula
  87. "#+TBLFM: $1 = vsum(@<..@>>)"
  88. ;; Lisp formula
  89. "#+TBLFM: $1 = '(+ @<..@>>); N")
  90. ;; The problem is that the first three rows with the summands are
  91. ;; considered the header and therefore column formulas are not
  92. ;; applied on them as shown below. Also export behaves unexpected.
  93. ;; See next ert-deftest how to group rows right.
  94. (org-test-table-target-expect
  95. "
  96. | 2 | replace |
  97. | 4 | replace |
  98. | 8 | replace |
  99. |---------+---------|
  100. | replace | replace |
  101. "
  102. "
  103. | 2 | replace |
  104. | 4 | replace |
  105. | 8 | replace |
  106. |----+---------|
  107. | 14 | 28 |
  108. "
  109. 2
  110. ;; Calc formula
  111. "#+TBLFM: @>$1 = vsum(@<..@>>) :: $2 = 2 * $1"
  112. ;; Lisp formula
  113. "#+TBLFM: @>$1 = '(+ @<..@>>); N :: $2 = '(* 2 $1); N"))
  114. (ert-deftest test-org-table/simple-formula/with-grouping/with-title-row ()
  115. "Simple sum with grouping rows, how to do it right."
  116. ;; Always add a top row with the column names separated by hline to
  117. ;; get the desired header when you want to group rows.
  118. (org-test-table-target-expect
  119. "
  120. | foo | bar |
  121. |---------+---------|
  122. | 2 | replace |
  123. | 4 | replace |
  124. | 8 | replace |
  125. |---------+---------|
  126. | replace | replace |
  127. "
  128. "
  129. | foo | bar |
  130. |-----+-----|
  131. | 2 | 4 |
  132. | 4 | 8 |
  133. | 8 | 16 |
  134. |-----+-----|
  135. | 14 | 28 |
  136. "
  137. 2
  138. ;; Calc formula
  139. "#+TBLFM: @>$1 = vsum(@I..@>>) :: $2 = 2 * $1"
  140. ;; Lisp formula
  141. "#+TBLFM: @>$1 = '(+ @I..@>>); N :: $2 = '(* 2 $1); N"))
  142. (ert-deftest test-org-table/align ()
  143. "Align columns within Org buffer, depends on `org-table-number-regexp'."
  144. (org-test-table-target-expect "
  145. | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
  146. | ab | 12 | 12.2 | 2.4e-08 | 2x10^12 | 4.034+-0.02 | 2.7(10) | >3.5 |
  147. | ab | ab | ab | ab | ab | ab | ab | ab |
  148. ")
  149. (org-test-table-target-expect "
  150. | 0 | 0 | 0 | 0 | 0 | 0 |
  151. | <-0x0ab.cf | >-36#0vw.yz | nan | uinf | -inf | inf |
  152. | ab | ab | ab | ab | ab | ab |
  153. "))
  154. (defconst references/target-normal "
  155. | 0 | 1 | replace | replace | replace | replace | replace | replace |
  156. | z | 1 | replace | replace | replace | replace | replace | replace |
  157. | | 1 | replace | replace | replace | replace | replace | replace |
  158. | | | replace | replace | replace | replace | replace | replace |
  159. "
  160. "Normal numbers and non-numbers for Lisp and Calc formula.")
  161. (defconst references/target-special "
  162. | nan | 1 | replace | replace | replace | replace | replace | replace |
  163. | uinf | 1 | replace | replace | replace | replace | replace | replace |
  164. | -inf | 1 | replace | replace | replace | replace | replace | replace |
  165. | inf | 1 | replace | replace | replace | replace | replace | replace |
  166. "
  167. "Special numbers for Calc formula.")
  168. (ert-deftest test-org-table/references/mode-string-EL ()
  169. "Basic: Assign field reference, sum of field references, sum
  170. and len of simple range reference (no row) and complex range
  171. reference (with row). Mode string EL."
  172. ;; Empty fields are kept during parsing field but lost as list
  173. ;; elements within Lisp formula syntactically when used literally
  174. ;; and not enclosed with " within fields, see last columns with len.
  175. (org-test-table-target-expect
  176. references/target-normal
  177. ;; All the #ERROR show that for Lisp calculations N has to be used.
  178. "
  179. | 0 | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
  180. | z | 1 | z | #ERROR | #ERROR | #ERROR | 2 | 2 |
  181. | | 1 | | 1 | 1 | 1 | 1 | 1 |
  182. | | | | 0 | 0 | 0 | 0 | 0 |
  183. "
  184. 1 (concat
  185. "#+TBLFM: $3 = '(identity \"$1\"); EL :: $4 = '(+ $1 $2); EL :: "
  186. "$5 = '(+ $1..$2); EL :: $6 = '(+ @0$1..@0$2); EL :: "
  187. "$7 = '(length '($1..$2)); EL :: $8 = '(length '(@0$1..@0$2)); EL"))
  188. ;; Empty fields are kept during parsing field _and_ as list elements
  189. ;; within Lisp formula syntactically even when used literally when
  190. ;; enclosed with " within fields, see last columns with len.
  191. (org-test-table-target-expect
  192. "
  193. | \"0\" | \"1\" | repl | repl | repl | repl | repl | repl |
  194. | \"z\" | \"1\" | repl | repl | repl | repl | repl | repl |
  195. | \"\" | \"1\" | repl | repl | repl | repl | repl | repl |
  196. | \"\" | \"\" | repl | repl | repl | repl | repl | repl |
  197. "
  198. "
  199. | \"0\" | \"1\" | \"0\" | 1 | #ERROR | #ERROR | 2 | 2 |
  200. | \"z\" | \"1\" | \"z\" | 1 | #ERROR | #ERROR | 2 | 2 |
  201. | \"\" | \"1\" | \"\" | 1 | #ERROR | #ERROR | 2 | 2 |
  202. | \"\" | \"\" | \"\" | 0 | #ERROR | #ERROR | 2 | 2 |
  203. "
  204. 1 (concat
  205. "#+TBLFM: $3 = '(concat \"\\\"\" $1 \"\\\"\"); EL :: "
  206. "$4 = '(+ (string-to-number $1) (string-to-number $2)); EL :: "
  207. "$5 = '(+ $1..$2); EL :: $6 = '(+ @0$1..@0$2); EL :: "
  208. "$7 = '(length '($1..$2)); EL :: $8 = '(length '(@0$1..@0$2)); EL")))
  209. (ert-deftest test-org-table/references/mode-string-E ()
  210. "Basic: Assign field reference, sum of field references, sum
  211. and len of simple range reference (no row) and complex range
  212. reference (with row). Mode string E."
  213. (let ((lisp
  214. (concat
  215. "#+TBLFM: $3 = '(identity $1); E :: $4 = '(+ $1 $2); E :: "
  216. "$5 = '(+ $1..$2); E :: $6 = '(+ @0$1..@0$2); E :: "
  217. "$7 = '(length '($1..$2)); E :: $8 = '(length '(@0$1..@0$2)); E"))
  218. (calc
  219. (concat
  220. "#+TBLFM: $3 = $1; E :: $4 = $1 + $2; E :: "
  221. "$5 = vsum($1..$2); E :: $6 = vsum(@0$1..@0$2); E :: "
  222. "$7 = vlen($1..$2); E :: $8 = vlen(@0$1..@0$2); E")))
  223. (org-test-table-target-expect
  224. references/target-normal
  225. ;; All the #ERROR show that for Lisp calculations N has to be used.
  226. "
  227. | 0 | 1 | 0 | #ERROR | #ERROR | #ERROR | 2 | 2 |
  228. | z | 1 | z | #ERROR | #ERROR | #ERROR | 2 | 2 |
  229. | | 1 | | #ERROR | #ERROR | #ERROR | 2 | 2 |
  230. | | | | #ERROR | #ERROR | #ERROR | 2 | 2 |
  231. "
  232. 1 lisp)
  233. (org-test-table-target-expect
  234. references/target-normal
  235. "
  236. | 0 | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
  237. | z | 1 | z | z + 1 | z + 1 | z + 1 | 2 | 2 |
  238. | | 1 | nan | nan | nan | nan | 2 | 2 |
  239. | | | nan | nan | nan | nan | 2 | 2 |
  240. "
  241. 1 calc)
  242. (org-test-table-target-expect
  243. references/target-special
  244. "
  245. | nan | 1 | nan | nan | nan | nan | 2 | 2 |
  246. | uinf | 1 | uinf | uinf | uinf | uinf | 2 | 2 |
  247. | -inf | 1 | -inf | -inf | -inf | -inf | 2 | 2 |
  248. | inf | 1 | inf | inf | inf | inf | 2 | 2 |
  249. "
  250. 1 calc)))
  251. (ert-deftest test-org-table/references/mode-string-EN ()
  252. "Basic: Assign field reference, sum of field references, sum
  253. and len of simple range reference (no row) and complex range
  254. reference (with row). Mode string EN."
  255. (let ((lisp (concat
  256. "#+TBLFM: $3 = '(identity $1); EN :: $4 = '(+ $1 $2); EN :: "
  257. "$5 = '(+ $1..$2); EN :: $6 = '(+ @0$1..@0$2); EN :: "
  258. "$7 = '(length '($1..$2)); EN :: "
  259. "$8 = '(length '(@0$1..@0$2)); EN"))
  260. (calc (concat
  261. "#+TBLFM: $3 = $1; EN :: $4 = $1 + $2; EN :: "
  262. "$5 = vsum($1..$2); EN :: $6 = vsum(@0$1..@0$2); EN :: "
  263. "$7 = vlen($1..$2); EN :: $8 = vlen(@0$1..@0$2); EN")))
  264. (org-test-table-target-expect
  265. references/target-normal
  266. "
  267. | 0 | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
  268. | z | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
  269. | | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
  270. | | | 0 | 0 | 0 | 0 | 2 | 2 |
  271. "
  272. 1 lisp calc)
  273. (org-test-table-target-expect
  274. references/target-special
  275. "
  276. | nan | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
  277. | uinf | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
  278. | -inf | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
  279. | inf | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
  280. "
  281. 1 calc)))
  282. (ert-deftest test-org-table/references/mode-string-L ()
  283. "Basic: Assign field reference, sum of field references, sum
  284. and len of simple range reference (no row) and complex range
  285. reference (with row). Mode string L."
  286. (org-test-table-target-expect
  287. references/target-normal
  288. ;; All the #ERROR show that for Lisp calculations N has to be used.
  289. "
  290. | 0 | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
  291. | z | 1 | z | #ERROR | #ERROR | #ERROR | 2 | 2 |
  292. | | 1 | | 1 | 1 | 1 | 1 | 1 |
  293. | | | | 0 | 0 | 0 | 0 | 0 |
  294. "
  295. 1 (concat
  296. "#+TBLFM: $3 = '(identity \"$1\"); L :: $4 = '(+ $1 $2); L :: "
  297. "$5 = '(+ $1..$2); L :: $6 = '(+ @0$1..@0$2); L :: "
  298. "$7 = '(length '($1..$2)); L :: $8 = '(length '(@0$1..@0$2)); L")))
  299. (ert-deftest test-org-table/references/mode-string-none ()
  300. "Basic: Assign field reference, sum of field references, sum
  301. and len of simple range reference (no row) and complex range
  302. reference (with row). No mode string."
  303. (let ((lisp (concat
  304. "#+TBLFM: $3 = '(identity $1) :: $4 = '(+ $1 $2) :: "
  305. "$5 = '(+ $1..$2) :: $6 = '(+ @0$1..@0$2) :: "
  306. "$7 = '(length '($1..$2)) :: $8 = '(length '(@0$1..@0$2))"))
  307. (calc (concat
  308. "#+TBLFM: $3 = $1 :: $4 = $1 + $2 :: "
  309. "$5 = vsum($1..$2) :: $6 = vsum(@0$1..@0$2) :: "
  310. "$7 = vlen($1..$2) :: $8 = vlen(@0$1..@0$2)")))
  311. (org-test-table-target-expect
  312. references/target-normal
  313. ;; All the #ERROR show that for Lisp calculations N has to be used.
  314. "
  315. | 0 | 1 | 0 | #ERROR | #ERROR | #ERROR | 2 | 2 |
  316. | z | 1 | z | #ERROR | #ERROR | #ERROR | 2 | 2 |
  317. | | 1 | | #ERROR | #ERROR | #ERROR | 1 | 1 |
  318. | | | | #ERROR | 0 | 0 | 0 | 0 |
  319. "
  320. 1 lisp)
  321. (org-test-table-target-expect
  322. references/target-normal
  323. "
  324. | 0 | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
  325. | z | 1 | z | z + 1 | z + 1 | z + 1 | 2 | 2 |
  326. | | 1 | 0 | 1 | 1 | 1 | 1 | 1 |
  327. | | | 0 | 0 | 0 | 0 | 0 | 0 |
  328. "
  329. 1 calc)
  330. (org-test-table-target-expect
  331. references/target-special
  332. "
  333. | nan | 1 | nan | nan | nan | nan | 2 | 2 |
  334. | uinf | 1 | uinf | uinf | uinf | uinf | 2 | 2 |
  335. | -inf | 1 | -inf | -inf | -inf | -inf | 2 | 2 |
  336. | inf | 1 | inf | inf | inf | inf | 2 | 2 |
  337. "
  338. 1 calc)))
  339. (ert-deftest test-org-table/references/mode-string-N ()
  340. "Basic: Assign field reference, sum of field references, sum
  341. and len of simple range reference (no row) and complex range
  342. reference (with row). Mode string N."
  343. (let ((lisp
  344. (concat
  345. "#+TBLFM: $3 = '(identity $1); N :: $4 = '(+ $1 $2); N :: "
  346. "$5 = '(+ $1..$2); N :: $6 = '(+ @0$1..@0$2); N :: "
  347. "$7 = '(length '($1..$2)); N :: $8 = '(length '(@0$1..@0$2)); N"))
  348. (calc
  349. (concat
  350. "#+TBLFM: $3 = $1; N :: $4 = $1 + $2; N :: "
  351. "$5 = vsum($1..$2); N :: $6 = vsum(@0$1..@0$2); N :: "
  352. "$7 = vlen($1..$2); N :: $8 = vlen(@0$1..@0$2); N")))
  353. (org-test-table-target-expect
  354. references/target-normal
  355. "
  356. | 0 | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
  357. | z | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
  358. | | 1 | 0 | 1 | 1 | 1 | 1 | 1 |
  359. | | | 0 | 0 | 0 | 0 | 0 | 0 |
  360. "
  361. 1 lisp calc)
  362. (org-test-table-target-expect
  363. references/target-special
  364. "
  365. | nan | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
  366. | uinf | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
  367. | -inf | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
  368. | inf | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
  369. "
  370. 1 calc)))
  371. (ert-deftest test-org-table/compare ()
  372. "Basic: Compare field references in Calc."
  373. (org-test-table-target-expect
  374. "
  375. | | 0 | z | | nan | uinf | -inf | inf |
  376. |------+------+------+------+------+------+------+------|
  377. | 0 | repl | repl | repl | repl | repl | repl | repl |
  378. | z | repl | repl | repl | repl | repl | repl | repl |
  379. | | repl | repl | repl | repl | repl | repl | repl |
  380. | nan | repl | repl | repl | repl | repl | repl | repl |
  381. | uinf | repl | repl | repl | repl | repl | repl | repl |
  382. | -inf | repl | repl | repl | repl | repl | repl | repl |
  383. | inf | repl | repl | repl | repl | repl | repl | repl |
  384. "
  385. "
  386. | | 0 | z | | nan | uinf | -inf | inf |
  387. |------+---+---+---+-----+------+------+-----|
  388. | 0 | x | | | | | | |
  389. | z | | x | | | | | |
  390. | | | | x | | | | |
  391. | nan | | | | x | | | |
  392. | uinf | | | | | x | | |
  393. | -inf | | | | | | x | |
  394. | inf | | | | | | | x |
  395. "
  396. 1
  397. ;; Compare field reference ($1) with field reference (@1)
  398. "#+TBLFM: @<<$<<..@>$> = if(\"$1\" == \"@1\", x, string(\"\")); E"
  399. ;; Compare field reference ($1) with absolute term
  400. (concat "#+TBLFM: "
  401. "$2 = if(\"$1\" == \"(0)\" , x, string(\"\")); E :: "
  402. "$3 = if(\"$1\" == \"(z)\" , x, string(\"\")); E :: "
  403. "$4 = if(\"$1\" == \"nan\" , x, string(\"\")); E :: "
  404. "$5 = if(\"$1\" == \"(nan)\" , x, string(\"\")); E :: "
  405. "$6 = if(\"$1\" == \"(uinf)\", x, string(\"\")); E :: "
  406. "$7 = if(\"$1\" == \"(-inf)\", x, string(\"\")); E :: "
  407. "$8 = if(\"$1\" == \"(inf)\" , x, string(\"\")); E"))
  408. ;; Check field reference converted from an empty field: Despite this
  409. ;; field reference will not end up in a result, Calc evaluates it.
  410. ;; Make sure that also then there is no Calc error.
  411. (org-test-table-target-expect
  412. "
  413. | 0 | replace |
  414. | z | replace |
  415. | | replace |
  416. | nan | replace |
  417. "
  418. "
  419. | 0 | 1 |
  420. | z | z + 1 |
  421. | | |
  422. | nan | nan |
  423. "
  424. 1 "#+TBLFM: $2 = if(\"$1\" == \"nan\", string(\"\"), $1 + 1); E"))
  425. (ert-deftest test-org-table/empty-field ()
  426. "Examples how to deal with empty fields."
  427. ;; Test if one field is empty, else do a calculation
  428. (org-test-table-target-expect
  429. "
  430. | -1 | replace |
  431. | 0 | replace |
  432. | | replace |
  433. "
  434. "
  435. | -1 | 0 |
  436. | 0 | 1 |
  437. | | |
  438. "
  439. 1
  440. ;; Calc formula
  441. "#+TBLFM: $2 = if(\"$1\" == \"nan\", string(\"\"), $1 + 1); E"
  442. ;; Lisp formula
  443. "#+TBLFM: $2 = '(if (eq \"$1\" \"\") \"\" (1+ $1)); L")
  444. ;; Test if several fields are empty, else do a calculation
  445. (org-test-table-target-expect
  446. "
  447. | 1 | 2 | replace |
  448. | 4 | | replace |
  449. | | 8 | replace |
  450. | | | replace |
  451. "
  452. "
  453. | 1 | 2 | 3 |
  454. | 4 | | |
  455. | | 8 | |
  456. | | | |
  457. "
  458. 1
  459. ;; Calc formula
  460. (concat "#+TBLFM: $3 = if(\"$1\" == \"nan\" || \"$2\" == \"nan\", "
  461. "string(\"\"), $1 + $2); E")
  462. ;; Lisp formula
  463. (concat "#+TBLFM: $3 = '(if (or (eq \"$1\" \"\") (eq \"$2\" \"\")) "
  464. "\"\" (+ $1 $2)); L"))
  465. ;; $2: Use $1 + 0.5 if $1 available, else only reformat $2 if $2 available
  466. (org-test-table-target-expect
  467. "
  468. | 1.5 | 0 |
  469. | 3.5 | |
  470. | | 5 |
  471. | | |
  472. "
  473. "
  474. | 1.5 | 2.0 |
  475. | 3.5 | 4.0 |
  476. | | 5.0 |
  477. | | |
  478. "
  479. 1
  480. ;; Calc formula
  481. (concat "#+TBLFM: $2 = if(\"$1\" == \"nan\", "
  482. "if(\"$2\" == \"nan\", string(\"\"), $2 +.0), $1 + 0.5); E f-1")
  483. ;; Lisp formula not implemented yet
  484. )
  485. ;; Empty fields in simple and complex range reference
  486. (org-test-table-target-expect
  487. "
  488. | | | | | repl | repl | repl | repl | repl | repl |
  489. | | | 5 | 7 | repl | repl | repl | repl | repl | repl |
  490. | 1 | 3 | 5 | 7 | repl | repl | repl | repl | repl | repl |
  491. "
  492. "
  493. | | | | | | | | | 0 | 0 |
  494. | | | 5 | 7 | | | 6 | 6 | 3 | 3 |
  495. | 1 | 3 | 5 | 7 | 4 | 4 | 4 | 4 | 4 | 4 |
  496. "
  497. 1
  498. ;; Calc formula
  499. (concat
  500. "#+TBLFM: "
  501. "$5 = if(typeof(vmean($1..$4)) == 12, "
  502. "string(\"\"), vmean($1..$4)); E :: "
  503. "$6 = if(typeof(vmean(@0$1..@0$4)) == 12, "
  504. "string(\"\"), vmean(@0$1..@0$4)); E :: "
  505. "$7 = if(\"$1..$4\" == \"[]\", string(\"\"), vmean($1..$4)) :: "
  506. "$8 = if(\"@0$1..@0$4\" == \"[]\", string(\"\"), vmean(@0$1..@0$4)) :: "
  507. "$9 = vmean($1..$4); EN :: "
  508. "$10 = vmean(@0$1..@0$4); EN")
  509. ;; Lisp formula
  510. (concat
  511. "#+TBLFM: "
  512. "$5 = '(let ((l '($1..$4))) (if (member \"\" l) \"\" "
  513. "(/ (apply '+ (mapcar 'string-to-number l)) (length l)))); E :: "
  514. "$6 = '(let ((l '(@0$1..@0$4))) (if (member \"\" l) \"\" "
  515. "(/ (apply '+ (mapcar 'string-to-number l)) (length l)))); E :: "
  516. "$7 = '(let ((l '($1..$4))) "
  517. "(if l (/ (apply '+ l) (length l)) \"\")); N :: "
  518. "$8 = '(let ((l '(@0$1..@0$4))) "
  519. "(if l (/ (apply '+ l) (length l)) \"\")); N :: "
  520. "$9 = '(/ (+ $1..$4) (length '($1..$4))); EN :: "
  521. "$10 = '(/ (+ @0$1..@0$4) (length '(@0$1..@0$4))); EN")
  522. ))
  523. (ert-deftest test-org-table/copy-field ()
  524. "Experiments on how to copy one field into another field.
  525. See also `test-org-table/remote-reference-access'."
  526. (let ((target
  527. "
  528. | 0 | replace |
  529. | a b | replace |
  530. | c d | replace |
  531. | | replace |
  532. | 2012-12 | replace |
  533. | [2012-12-31 Mon] | replace |
  534. "))
  535. ;; Lisp formula to copy literally
  536. (org-test-table-target-expect
  537. target
  538. "
  539. | 0 | 0 |
  540. | a b | a b |
  541. | c d | c d |
  542. | | |
  543. | 2012-12 | 2012-12 |
  544. | [2012-12-31 Mon] | [2012-12-31 Mon] |
  545. "
  546. 1 "#+TBLFM: $2 = '(identity $1)")
  547. ;; Calc formula to copy quite literally
  548. (org-test-table-target-expect
  549. target
  550. "
  551. | 0 | 0 |
  552. | a b | a b |
  553. | c d | c d |
  554. | | |
  555. | 2012-12 | 2012-12 |
  556. | [2012-12-31 Mon] | <2012-12-31 Mon> |
  557. "
  558. 1 (concat "#+TBLFM: $2 = if(\"$1\" == \"nan\", "
  559. "string(\"\"), string(subvec(\"$1\", 2, vlen(\"$1\")))); E"))
  560. ;; Calc formula simple
  561. (org-test-table-target-expect
  562. target
  563. "
  564. | 0 | 0 |
  565. | a b | a b |
  566. | c d | c d |
  567. | | |
  568. | 2012-12 | 2000 |
  569. | [2012-12-31 Mon] | <2012-12-31 Mon> |
  570. "
  571. 1 "#+TBLFM: $2 = if(\"$1\" == \"nan\", string(\"\"), $1); E")))
  572. ;; End of table examples and beginning of internal tests.
  573. (ert-deftest test-org-table/org-table-make-reference/mode-string-EL ()
  574. (fset 'f 'org-table-make-reference)
  575. ;; For Lisp formula only
  576. (should (equal "0" (f "0" t nil 'literal)))
  577. (should (equal "z" (f "z" t nil 'literal)))
  578. (should (equal "" (f "" t nil 'literal)))
  579. (should (equal "0 1" (f '("0" "1") t nil 'literal)))
  580. (should (equal "z 1" (f '("z" "1") t nil 'literal)))
  581. (should (equal " 1" (f '("" "1") t nil 'literal)))
  582. (should (equal " " (f '("" "" ) t nil 'literal))))
  583. (ert-deftest test-org-table/org-table-make-reference/mode-string-E ()
  584. (fset 'f 'org-table-make-reference)
  585. ;; For Lisp formula
  586. (should (equal "\"0\"" (f "0" t nil t)))
  587. (should (equal "\"z\"" (f "z" t nil t)))
  588. (should (equal "\"\"" (f "" t nil t)))
  589. (should (equal "\"0\" \"1\"" (f '("0" "1") t nil t)))
  590. (should (equal "\"z\" \"1\"" (f '("z" "1") t nil t)))
  591. (should (equal "\"\" \"1\"" (f '("" "1") t nil t)))
  592. (should (equal "\"\" \"\"" (f '("" "" ) t nil t)))
  593. ;; For Calc formula
  594. (should (equal "(0)" (f "0" t nil nil)))
  595. (should (equal "(z)" (f "z" t nil nil)))
  596. (should (equal "nan" (f "" t nil nil)))
  597. (should (equal "[0,1]" (f '("0" "1") t nil nil)))
  598. (should (equal "[z,1]" (f '("z" "1") t nil nil)))
  599. (should (equal "[nan,1]" (f '("" "1") t nil nil)))
  600. (should (equal "[nan,nan]" (f '("" "" ) t nil nil)))
  601. ;; For Calc formula, special numbers
  602. (should (equal "(nan)" (f "nan" t nil nil)))
  603. (should (equal "(uinf)" (f "uinf" t nil nil)))
  604. (should (equal "(-inf)" (f "-inf" t nil nil)))
  605. (should (equal "(inf)" (f "inf" t nil nil)))
  606. (should (equal "[nan,1]" (f '( "nan" "1") t nil nil)))
  607. (should (equal "[uinf,1]" (f '("uinf" "1") t nil nil)))
  608. (should (equal "[-inf,1]" (f '("-inf" "1") t nil nil)))
  609. (should (equal "[inf,1]" (f '( "inf" "1") t nil nil))))
  610. (ert-deftest test-org-table/org-table-make-reference/mode-string-EN ()
  611. (fset 'f 'org-table-make-reference)
  612. ;; For Lisp formula
  613. (should (equal "0" (f "0" t t t)))
  614. (should (equal "0" (f "z" t t t)))
  615. (should (equal "0" (f "" t t t)))
  616. (should (equal "0 1" (f '("0" "1") t t t)))
  617. (should (equal "0 1" (f '("z" "1") t t t)))
  618. (should (equal "0 1" (f '("" "1") t t t)))
  619. (should (equal "0 0" (f '("" "" ) t t t)))
  620. ;; For Calc formula
  621. (should (equal "(0)" (f "0" t t nil)))
  622. (should (equal "(0)" (f "z" t t nil)))
  623. (should (equal "(0)" (f "" t t nil)))
  624. (should (equal "[0,1]" (f '("0" "1") t t nil)))
  625. (should (equal "[0,1]" (f '("z" "1") t t nil)))
  626. (should (equal "[0,1]" (f '("" "1") t t nil)))
  627. (should (equal "[0,0]" (f '("" "" ) t t nil)))
  628. ;; For Calc formula, special numbers
  629. (should (equal "(0)" (f "nan" t t nil)))
  630. (should (equal "(0)" (f "uinf" t t nil)))
  631. (should (equal "(0)" (f "-inf" t t nil)))
  632. (should (equal "(0)" (f "inf" t t nil)))
  633. (should (equal "[0,1]" (f '( "nan" "1") t t nil)))
  634. (should (equal "[0,1]" (f '("uinf" "1") t t nil)))
  635. (should (equal "[0,1]" (f '("-inf" "1") t t nil)))
  636. (should (equal "[0,1]" (f '( "inf" "1") t t nil))))
  637. (ert-deftest test-org-table/org-table-make-reference/mode-string-L ()
  638. (fset 'f 'org-table-make-reference)
  639. ;; For Lisp formula only
  640. (should (equal "0" (f "0" nil nil 'literal)))
  641. (should (equal "z" (f "z" nil nil 'literal)))
  642. (should (equal "" (f "" nil nil 'literal)))
  643. (should (equal "0 1" (f '("0" "1") nil nil 'literal)))
  644. (should (equal "z 1" (f '("z" "1") nil nil 'literal)))
  645. (should (equal "1" (f '("" "1") nil nil 'literal)))
  646. (should (equal "" (f '("" "" ) nil nil 'literal))))
  647. (ert-deftest test-org-table/org-table-make-reference/mode-string-none ()
  648. (fset 'f 'org-table-make-reference)
  649. ;; For Lisp formula
  650. (should (equal "\"0\"" (f "0" nil nil t)))
  651. (should (equal "\"z\"" (f "z" nil nil t)))
  652. (should (equal "" (f "" nil nil t)))
  653. (should (equal "\"0\" \"1\"" (f '("0" "1") nil nil t)))
  654. (should (equal "\"z\" \"1\"" (f '("z" "1") nil nil t)))
  655. (should (equal "\"1\"" (f '("" "1") nil nil t)))
  656. (should (equal "" (f '("" "" ) nil nil t)))
  657. ;; For Calc formula
  658. (should (equal "(0)" (f "0" nil nil nil)))
  659. (should (equal "(z)" (f "z" nil nil nil)))
  660. (should (equal "(0)" (f "" nil nil nil)))
  661. (should (equal "[0,1]" (f '("0" "1") nil nil nil)))
  662. (should (equal "[z,1]" (f '("z" "1") nil nil nil)))
  663. (should (equal "[1]" (f '("" "1") nil nil nil)))
  664. (should (equal "[]" (f '("" "" ) nil nil nil)))
  665. ;; For Calc formula, special numbers
  666. (should (equal "(nan)" (f "nan" nil nil nil)))
  667. (should (equal "(uinf)" (f "uinf" nil nil nil)))
  668. (should (equal "(-inf)" (f "-inf" nil nil nil)))
  669. (should (equal "(inf)" (f "inf" nil nil nil)))
  670. (should (equal "[nan,1]" (f '( "nan" "1") nil nil nil)))
  671. (should (equal "[uinf,1]" (f '("uinf" "1") nil nil nil)))
  672. (should (equal "[-inf,1]" (f '("-inf" "1") nil nil nil)))
  673. (should (equal "[inf,1]" (f '( "inf" "1") nil nil nil))))
  674. (ert-deftest test-org-table/org-table-make-reference/mode-string-N ()
  675. (fset 'f 'org-table-make-reference)
  676. ;; For Lisp formula
  677. (should (equal "0" (f "0" nil t t)))
  678. (should (equal "0" (f "z" nil t t)))
  679. (should (equal "" (f "" nil t t)))
  680. (should (equal "0 1" (f '("0" "1") nil t t)))
  681. (should (equal "0 1" (f '("z" "1") nil t t)))
  682. (should (equal "1" (f '("" "1") nil t t)))
  683. (should (equal "" (f '("" "" ) nil t t)))
  684. ;; For Calc formula
  685. (should (equal "(0)" (f "0" nil t nil)))
  686. (should (equal "(0)" (f "z" nil t nil)))
  687. (should (equal "(0)" (f "" nil t nil)))
  688. (should (equal "[0,1]" (f '("0" "1") nil t nil)))
  689. (should (equal "[0,1]" (f '("z" "1") nil t nil)))
  690. (should (equal "[1]" (f '("" "1") nil t nil)))
  691. (should (equal "[]" (f '("" "" ) nil t nil)))
  692. ;; For Calc formula, special numbers
  693. (should (equal "(0)" (f "nan" nil t nil)))
  694. (should (equal "(0)" (f "uinf" nil t nil)))
  695. (should (equal "(0)" (f "-inf" nil t nil)))
  696. (should (equal "(0)" (f "inf" nil t nil)))
  697. (should (equal "[0,1]" (f '( "nan" "1") nil t nil)))
  698. (should (equal "[0,1]" (f '("uinf" "1") nil t nil)))
  699. (should (equal "[0,1]" (f '("-inf" "1") nil t nil)))
  700. (should (equal "[0,1]" (f '( "inf" "1") nil t nil))))
  701. (ert-deftest test-org-table/org-table-convert-refs-to-an/1 ()
  702. "Simple reference @1$1."
  703. (should
  704. (string= "A1" (org-table-convert-refs-to-an "@1$1"))))
  705. ;; TODO: Test broken
  706. ;; (ert-deftest test-org-table/org-table-convert-refs-to-an/2 ()
  707. ;; "Self reference @1$1."
  708. ;; (should
  709. ;; (string= "A1 = $0" (org-table-convert-refs-to-an "@1$1 = $0"))))
  710. (ert-deftest test-org-table/org-table-convert-refs-to-an/3 ()
  711. "Remote reference."
  712. (should
  713. (string= "C& = remote(FOO, @@#B&)" (org-table-convert-refs-to-an "$3 = remote(FOO, @@#$2)"))))
  714. (ert-deftest test-org-table/org-table-convert-refs-to-rc/1 ()
  715. "Simple reference @1$1."
  716. (should
  717. (string= "@1$1" (org-table-convert-refs-to-rc "A1"))))
  718. (ert-deftest test-org-table/org-table-convert-refs-to-rc/2 ()
  719. "Self reference $0."
  720. (should
  721. (string= "@1$1 = $0" (org-table-convert-refs-to-rc "A1 = $0"))))
  722. ;; TODO: Test Broken
  723. ;; (ert-deftest test-org-table/org-table-convert-refs-to-rc/3 ()
  724. ;; "Remote reference."
  725. ;; (should
  726. ;; (string= "$3 = remote(FOO, @@#$2)" (org-table-convert-refs-to-rc "C& = remote(FOO, @@#B&)"))))
  727. (ert-deftest test-org-table/remote-reference-access ()
  728. "Access to remote reference.
  729. See also `test-org-table/copy-field'."
  730. (org-test-table-target-expect
  731. "
  732. #+NAME: table
  733. | | x 42 | |
  734. | replace | replace |
  735. "
  736. "
  737. #+NAME: table
  738. | | x 42 | |
  739. | x 42 | 84 x |
  740. "
  741. 1 (concat "#+TBLFM: "
  742. ;; Copy text without calculation: Use Lisp formula
  743. "$1 = '(identity remote(table, @1$2)) :: "
  744. ;; Do a calculation: Use Calc (or Lisp ) formula
  745. "$2 = 2 * remote(table, @1$2)")))
  746. (ert-deftest test-org-table/remote-reference-indirect ()
  747. "Access to remote reference with indirection of name or ID."
  748. (let ((source-tables "
  749. #+NAME: 2012
  750. | amount |
  751. |--------|
  752. | 1 |
  753. | 2 |
  754. |--------|
  755. | 3 |
  756. #+TBLFM: @>$1 = vsum(@I..@II)
  757. #+NAME: 2013
  758. | amount |
  759. |--------|
  760. | 4 |
  761. | 8 |
  762. |--------|
  763. | 12 |
  764. #+TBLFM: @>$1 = vsum(@I..@II)
  765. "))
  766. ;; Read several remote references from same column
  767. (org-test-table-target-expect
  768. (concat source-tables "
  769. #+NAME: summary
  770. | year | amount |
  771. |-------+---------|
  772. | 2012 | replace |
  773. | 2013 | replace |
  774. |-------+---------|
  775. | total | replace |
  776. ")
  777. (concat source-tables "
  778. #+NAME: summary
  779. | year | amount |
  780. |-------+--------|
  781. | 2012 | 3 |
  782. | 2013 | 12 |
  783. |-------+--------|
  784. | total | 15 |
  785. ")
  786. 1
  787. ;; Calc formula
  788. "#+TBLFM: @<<$2..@>>$2 = remote($<, @>$1) :: @>$2 = vsum(@I..@II)"
  789. ;; Lisp formula
  790. (concat "#+TBLFM: @<<$2..@>>$2 = '(identity remote($<, @>$1)); N :: "
  791. "@>$2 = '(+ @I..@II); N"))
  792. ;; Read several remote references from same row
  793. (org-test-table-target-expect
  794. (concat source-tables "
  795. #+NAME: summary
  796. | year | 2012 | 2013 | total |
  797. |--------+---------+---------+---------|
  798. | amount | replace | replace | replace |
  799. ")
  800. (concat source-tables "
  801. #+NAME: summary
  802. | year | 2012 | 2013 | total |
  803. |--------+------+------+-------|
  804. | amount | 3 | 12 | 15 |
  805. ")
  806. 1
  807. ;; Calc formula
  808. "#+TBLFM: @2$<<..@2$>> = remote(@<, @>$1) :: @2$> = vsum($<<..$>>)"
  809. ;; Lisp formula
  810. (concat "#+TBLFM: @2$<<..@2$>> = '(identity remote(@<, @>$1)); N :: "
  811. "@2$> = '(+ $<<..$>>); N"))))
  812. (ert-deftest test-org-table/org-at-TBLFM-p ()
  813. (org-test-with-temp-text-in-file
  814. "
  815. | 1 |
  816. | 2 |
  817. #+TBLFM: $2=$1*2
  818. "
  819. (goto-char (point-min))
  820. (forward-line 2)
  821. (should (equal (org-at-TBLFM-p) nil))
  822. (goto-char (point-min))
  823. (forward-line 3)
  824. (should (equal (org-at-TBLFM-p) t))
  825. (goto-char (point-min))
  826. (forward-line 4)
  827. (should (equal (org-at-TBLFM-p) nil))))
  828. (ert-deftest test-org-table/org-table-TBLFM-begin ()
  829. (org-test-with-temp-text-in-file
  830. "
  831. | 1 |
  832. | 2 |
  833. #+TBLFM: $2=$1*2
  834. "
  835. (goto-char (point-min))
  836. (should (equal (org-table-TBLFM-begin)
  837. nil))
  838. (goto-char (point-min))
  839. (forward-line 1)
  840. (should (equal (org-table-TBLFM-begin)
  841. nil))
  842. (goto-char (point-min))
  843. (forward-line 3)
  844. (should (= (org-table-TBLFM-begin)
  845. 14))
  846. (goto-char (point-min))
  847. (forward-line 4)
  848. (should (= (org-table-TBLFM-begin)
  849. 14))
  850. ))
  851. (ert-deftest test-org-table/org-table-TBLFM-begin-for-multiple-TBLFM-lines ()
  852. "For multiple #+TBLFM lines."
  853. (org-test-with-temp-text-in-file
  854. "
  855. | 1 |
  856. | 2 |
  857. #+TBLFM: $2=$1*1
  858. #+TBLFM: $2=$1*2
  859. "
  860. (goto-char (point-min))
  861. (should (equal (org-table-TBLFM-begin)
  862. nil))
  863. (goto-char (point-min))
  864. (forward-line 1)
  865. (should (equal (org-table-TBLFM-begin)
  866. nil))
  867. (goto-char (point-min))
  868. (forward-line 3)
  869. (should (= (org-table-TBLFM-begin)
  870. 14))
  871. (goto-char (point-min))
  872. (forward-line 4)
  873. (should (= (org-table-TBLFM-begin)
  874. 14))
  875. (goto-char (point-min))
  876. (forward-line 5)
  877. (should (= (org-table-TBLFM-begin)
  878. 14))
  879. ))
  880. (ert-deftest test-org-table/org-table-TBLFM-begin-for-pultiple-TBLFM-lines-blocks ()
  881. (org-test-with-temp-text-in-file
  882. "
  883. | 1 |
  884. | 2 |
  885. #+TBLFM: $2=$1*1
  886. #+TBLFM: $2=$1*2
  887. | 6 |
  888. | 7 |
  889. #+TBLFM: $2=$1*1
  890. #+TBLFM: $2=$1*2
  891. "
  892. (goto-char (point-min))
  893. (should (equal (org-table-TBLFM-begin)
  894. nil))
  895. (goto-char (point-min))
  896. (forward-line 1)
  897. (should (equal (org-table-TBLFM-begin)
  898. nil))
  899. (goto-char (point-min))
  900. (forward-line 3)
  901. (should (= (org-table-TBLFM-begin)
  902. 14))
  903. (goto-char (point-min))
  904. (forward-line 4)
  905. (should (= (org-table-TBLFM-begin)
  906. 14))
  907. (goto-char (point-min))
  908. (forward-line 5)
  909. (should (= (org-table-TBLFM-begin)
  910. 14))
  911. (goto-char (point-min))
  912. (forward-line 6)
  913. (should (= (org-table-TBLFM-begin)
  914. 14))
  915. (goto-char (point-min))
  916. (forward-line 8)
  917. (should (= (org-table-TBLFM-begin)
  918. 61))
  919. (goto-char (point-min))
  920. (forward-line 9)
  921. (should (= (org-table-TBLFM-begin)
  922. 61))
  923. (goto-char (point-min))
  924. (forward-line 10)
  925. (should (= (org-table-TBLFM-begin)
  926. 61))))
  927. (ert-deftest test-org-table/org-table-calc-current-TBLFM ()
  928. (org-test-with-temp-text-in-file
  929. "
  930. | 1 | |
  931. | 2 | |
  932. #+TBLFM: $2=$1*1
  933. #+TBLFM: $2=$1*2
  934. #+TBLFM: $2=$1*3
  935. "
  936. (let ((got (progn (goto-char (point-min))
  937. (forward-line 3)
  938. (org-table-calc-current-TBLFM)
  939. (buffer-string)))
  940. (expect "
  941. | 1 | 1 |
  942. | 2 | 2 |
  943. #+TBLFM: $2=$1*1
  944. #+TBLFM: $2=$1*2
  945. #+TBLFM: $2=$1*3
  946. "))
  947. (should (string= got
  948. expect)))
  949. (let ((got (progn (goto-char (point-min))
  950. (forward-line 4)
  951. (org-table-calc-current-TBLFM)
  952. (buffer-string)))
  953. (expect "
  954. | 1 | 2 |
  955. | 2 | 4 |
  956. #+TBLFM: $2=$1*1
  957. #+TBLFM: $2=$1*2
  958. #+TBLFM: $2=$1*3
  959. "))
  960. (should (string= got
  961. expect)))))
  962. (ert-deftest test-org-table/org-table-calc-current-TBLFM-when-stop-because-of-error ()
  963. "org-table-calc-current-TBLFM should preserve the input as it was."
  964. (org-test-with-temp-text-in-file
  965. "
  966. | 1 | 1 |
  967. | 2 | 2 |
  968. #+TBLFM: $2=$1*1
  969. #+TBLFM: $2=$1*2::$2=$1*2
  970. #+TBLFM: $2=$1*3
  971. "
  972. (let ((expect "
  973. | 1 | 1 |
  974. | 2 | 2 |
  975. #+TBLFM: $2=$1*1
  976. #+TBLFM: $2=$1*2::$2=$1*2
  977. #+TBLFM: $2=$1*3
  978. "))
  979. (goto-char (point-min))
  980. (forward-line 4)
  981. (should-error (org-table-calc-current-TBLFM))
  982. (setq got (buffer-string))
  983. (message "%s" got)
  984. (should (string= got
  985. expect)))))
  986. (provide 'test-org-table)
  987. ;;; test-org-table.el ends here