1 ;;; test-org-table.el --- tests for org-table.el
3 ;; Copyright (c) David Maus
4 ;; Authors: David Maus, Michael Brand
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/>.
23 ;; Template test file for Org-mode tests. Many tests are also a howto
24 ;; example collection as a user documentation, more or less all those
25 ;; using `org-test-table-target-expect'. See also the doc string of
26 ;; `org-test-table-target-expect'.
30 (require 'org-table
) ; `org-table-make-reference'
32 (ert-deftest test-org-table
/simple-formula
/no-grouping
/no-title-row
()
33 "Simple sum without grouping rows, without title row."
34 (org-test-table-target-expect
49 "#+TBLFM: @>$1 = vsum(@<..@>>)"
51 "#+TBLFM: @>$1 = '(+ @<..@>>); N"))
53 (ert-deftest test-org-table
/simple-formula
/no-grouping
/with-title-row
()
54 "Simple sum without grouping rows, with title row."
55 (org-test-table-target-expect
74 "#+TBLFM: @>$1 = vsum(@I..@>>)"
76 "#+TBLFM: @>$1 = '(+ @I..@>>); N"))
78 (ert-deftest test-org-table
/simple-formula
/with-grouping
/no-title-row
()
79 "Simple sum with grouping rows, how not to do."
80 ;; The first example has a problem, see the second example in this
82 (org-test-table-target-expect
99 "#+TBLFM: $1 = vsum(@<..@>>)"
101 "#+TBLFM: $1 = '(+ @<..@>>); N")
103 ;; The problem is that the first three rows with the summands are
104 ;; considered the header and therefore column formulas are not
105 ;; applied on them as shown below. Also export behaves unexpected.
106 ;; See next ert-deftest how to group rows right.
107 (org-test-table-target-expect
112 |---------+---------|
113 | replace | replace |
124 "#+TBLFM: @>$1 = vsum(@<..@>>) :: $2 = 2 * $1"
126 "#+TBLFM: @>$1 = '(+ @<..@>>); N :: $2 = '(* 2 $1); N"))
128 (ert-deftest test-org-table
/simple-formula
/with-grouping
/with-title-row
()
129 "Simple sum with grouping rows, how to do it right."
130 ;; Always add a top row with the column names separated by hline to
131 ;; get the desired header when you want to group rows.
132 (org-test-table-target-expect
135 |---------+---------|
139 |---------+---------|
140 | replace | replace |
153 "#+TBLFM: @>$1 = vsum(@I..@>>) :: $2 = 2 * $1"
155 "#+TBLFM: @>$1 = '(+ @I..@>>); N :: $2 = '(* 2 $1); N"))
157 (ert-deftest test-org-table
/align
()
158 "Align columns within Org buffer, depends on `org-table-number-regexp'."
159 (org-test-table-target-expect "
160 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
161 | ab | 12 | 12.2 | 2.4e-08 | 2x10^12 | 4.034+-0.02 | 2.7(10) | >3.5 |
162 | ab | ab | ab | ab | ab | ab | ab | ab |
164 (org-test-table-target-expect "
165 | 0 | 0 | 0 | 0 | 0 | 0 |
166 | <-0x0ab.cf | >-36#0vw.yz | nan | uinf | -inf | inf |
167 | ab | ab | ab | ab | ab | ab |
170 (defconst references
/target-normal
"
171 | 0 | 1 | replace | replace | replace | replace | replace | replace |
172 | z | 1 | replace | replace | replace | replace | replace | replace |
173 | | 1 | replace | replace | replace | replace | replace | replace |
174 | | | replace | replace | replace | replace | replace | replace |
176 "Normal numbers and non-numbers for Lisp and Calc formula.")
178 (defconst references
/target-special
"
179 | nan | 1 | replace | replace | replace | replace | replace | replace |
180 | uinf | 1 | replace | replace | replace | replace | replace | replace |
181 | -inf | 1 | replace | replace | replace | replace | replace | replace |
182 | inf | 1 | replace | replace | replace | replace | replace | replace |
184 "Special numbers for Calc formula.")
186 (ert-deftest test-org-table
/references
/mode-string-EL
()
187 "Basic: Assign field reference, sum of field references, sum
188 and len of simple range reference (no row) and complex range
189 reference (with row). Mode string EL."
190 ;; Empty fields are kept during parsing field but lost as list
191 ;; elements within Lisp formula syntactically when used literally
192 ;; and not enclosed with " within fields, see last columns with len.
193 (org-test-table-target-expect
194 references
/target-normal
195 ;; All the #ERROR show that for Lisp calculations N has to be used.
197 | 0 | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
198 | z | 1 | z | #ERROR | #ERROR | #ERROR | 2 | 2 |
199 | | 1 | | 1 | 1 | 1 | 1 | 1 |
200 | | | | 0 | 0 | 0 | 0 | 0 |
203 "#+TBLFM: $3 = '(identity \"$1\"); EL :: $4 = '(+ $1 $2); EL :: "
204 "$5 = '(+ $1..$2); EL :: $6 = '(+ @0$1..@0$2); EL :: "
205 "$7 = '(length '($1..$2)); EL :: $8 = '(length '(@0$1..@0$2)); EL"))
207 ;; Empty fields are kept during parsing field _and_ as list elements
208 ;; within Lisp formula syntactically even when used literally when
209 ;; enclosed with " within fields, see last columns with len.
210 (org-test-table-target-expect
212 | \"0\" | \"1\" | repl | repl | repl | repl | repl | repl |
213 | \"z\" | \"1\" | repl | repl | repl | repl | repl | repl |
214 | \"\" | \"1\" | repl | repl | repl | repl | repl | repl |
215 | \"\" | \"\" | repl | repl | repl | repl | repl | repl |
218 | \"0\" | \"1\" | \"0\" | 1 | #ERROR | #ERROR | 2 | 2 |
219 | \"z\" | \"1\" | \"z\" | 1 | #ERROR | #ERROR | 2 | 2 |
220 | \"\" | \"1\" | \"\" | 1 | #ERROR | #ERROR | 2 | 2 |
221 | \"\" | \"\" | \"\" | 0 | #ERROR | #ERROR | 2 | 2 |
224 "#+TBLFM: $3 = '(concat \"\\\"\" $1 \"\\\"\"); EL :: "
225 "$4 = '(+ (string-to-number $1) (string-to-number $2)); EL :: "
226 "$5 = '(+ $1..$2); EL :: $6 = '(+ @0$1..@0$2); EL :: "
227 "$7 = '(length '($1..$2)); EL :: $8 = '(length '(@0$1..@0$2)); EL")))
229 (ert-deftest test-org-table
/references
/mode-string-E
()
230 "Basic: Assign field reference, sum of field references, sum
231 and len of simple range reference (no row) and complex range
232 reference (with row). Mode string E."
235 "#+TBLFM: $3 = '(identity $1); E :: $4 = '(+ $1 $2); E :: "
236 "$5 = '(+ $1..$2); E :: $6 = '(+ @0$1..@0$2); E :: "
237 "$7 = '(length '($1..$2)); E :: $8 = '(length '(@0$1..@0$2)); E"))
240 "#+TBLFM: $3 = $1; E :: $4 = $1 + $2; E :: "
241 "$5 = vsum($1..$2); E :: $6 = vsum(@0$1..@0$2); E :: "
242 "$7 = vlen($1..$2); E :: $8 = vlen(@0$1..@0$2); E")))
243 (org-test-table-target-expect
244 references
/target-normal
245 ;; All the #ERROR show that for Lisp calculations N has to be used.
247 | 0 | 1 | 0 | #ERROR | #ERROR | #ERROR | 2 | 2 |
248 | z | 1 | z | #ERROR | #ERROR | #ERROR | 2 | 2 |
249 | | 1 | | #ERROR | #ERROR | #ERROR | 2 | 2 |
250 | | | | #ERROR | #ERROR | #ERROR | 2 | 2 |
253 (org-test-table-target-expect
254 references
/target-normal
256 | 0 | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
257 | z | 1 | z | z + 1 | z + 1 | z + 1 | 2 | 2 |
258 | | 1 | nan | nan | nan | nan | 2 | 2 |
259 | | | nan | nan | nan | nan | 2 | 2 |
262 (org-test-table-target-expect
263 references
/target-special
265 | nan | 1 | nan | nan | nan | nan | 2 | 2 |
266 | uinf | 1 | uinf | uinf | uinf | uinf | 2 | 2 |
267 | -inf | 1 | -inf | -inf | -inf | -inf | 2 | 2 |
268 | inf | 1 | inf | inf | inf | inf | 2 | 2 |
272 (ert-deftest test-org-table
/references
/mode-string-EN
()
273 "Basic: Assign field reference, sum of field references, sum
274 and len of simple range reference (no row) and complex range
275 reference (with row). Mode string EN."
277 "#+TBLFM: $3 = '(identity $1); EN :: $4 = '(+ $1 $2); EN :: "
278 "$5 = '(+ $1..$2); EN :: $6 = '(+ @0$1..@0$2); EN :: "
279 "$7 = '(length '($1..$2)); EN :: "
280 "$8 = '(length '(@0$1..@0$2)); EN"))
282 "#+TBLFM: $3 = $1; EN :: $4 = $1 + $2; EN :: "
283 "$5 = vsum($1..$2); EN :: $6 = vsum(@0$1..@0$2); EN :: "
284 "$7 = vlen($1..$2); EN :: $8 = vlen(@0$1..@0$2); EN")))
285 (org-test-table-target-expect
286 references
/target-normal
288 | 0 | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
289 | z | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
290 | | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
291 | | | 0 | 0 | 0 | 0 | 2 | 2 |
294 (org-test-table-target-expect
295 references
/target-special
297 | nan | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
298 | uinf | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
299 | -inf | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
300 | inf | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
304 (ert-deftest test-org-table
/references
/mode-string-L
()
305 "Basic: Assign field reference, sum of field references, sum
306 and len of simple range reference (no row) and complex range
307 reference (with row). Mode string L."
308 (org-test-table-target-expect
309 references
/target-normal
310 ;; All the #ERROR show that for Lisp calculations N has to be used.
312 | 0 | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
313 | z | 1 | z | #ERROR | #ERROR | #ERROR | 2 | 2 |
314 | | 1 | | 1 | 1 | 1 | 1 | 1 |
315 | | | | 0 | 0 | 0 | 0 | 0 |
318 "#+TBLFM: $3 = '(identity \"$1\"); L :: $4 = '(+ $1 $2); L :: "
319 "$5 = '(+ $1..$2); L :: $6 = '(+ @0$1..@0$2); L :: "
320 "$7 = '(length '($1..$2)); L :: $8 = '(length '(@0$1..@0$2)); L")))
322 (ert-deftest test-org-table
/references
/mode-string-none
()
323 "Basic: Assign field reference, sum of field references, sum
324 and len of simple range reference (no row) and complex range
325 reference (with row). No mode string."
327 "#+TBLFM: $3 = '(identity $1) :: $4 = '(+ $1 $2) :: "
328 "$5 = '(+ $1..$2) :: $6 = '(+ @0$1..@0$2) :: "
329 "$7 = '(length '($1..$2)) :: $8 = '(length '(@0$1..@0$2))"))
331 "#+TBLFM: $3 = $1 :: $4 = $1 + $2 :: "
332 "$5 = vsum($1..$2) :: $6 = vsum(@0$1..@0$2) :: "
333 "$7 = vlen($1..$2) :: $8 = vlen(@0$1..@0$2)")))
334 (org-test-table-target-expect
335 references
/target-normal
336 ;; All the #ERROR show that for Lisp calculations N has to be used.
338 | 0 | 1 | 0 | #ERROR | #ERROR | #ERROR | 2 | 2 |
339 | z | 1 | z | #ERROR | #ERROR | #ERROR | 2 | 2 |
340 | | 1 | | #ERROR | #ERROR | #ERROR | 1 | 1 |
341 | | | | #ERROR | 0 | 0 | 0 | 0 |
344 (org-test-table-target-expect
345 references
/target-normal
347 | 0 | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
348 | z | 1 | z | z + 1 | z + 1 | z + 1 | 2 | 2 |
349 | | 1 | 0 | 1 | 1 | 1 | 1 | 1 |
350 | | | 0 | 0 | 0 | 0 | 0 | 0 |
353 (org-test-table-target-expect
354 references
/target-special
356 | nan | 1 | nan | nan | nan | nan | 2 | 2 |
357 | uinf | 1 | uinf | uinf | uinf | uinf | 2 | 2 |
358 | -inf | 1 | -inf | -inf | -inf | -inf | 2 | 2 |
359 | inf | 1 | inf | inf | inf | inf | 2 | 2 |
363 (ert-deftest test-org-table
/references
/mode-string-N
()
364 "Basic: Assign field reference, sum of field references, sum
365 and len of simple range reference (no row) and complex range
366 reference (with row). Mode string N."
369 "#+TBLFM: $3 = '(identity $1); N :: $4 = '(+ $1 $2); N :: "
370 "$5 = '(+ $1..$2); N :: $6 = '(+ @0$1..@0$2); N :: "
371 "$7 = '(length '($1..$2)); N :: $8 = '(length '(@0$1..@0$2)); N"))
374 "#+TBLFM: $3 = $1; N :: $4 = $1 + $2; N :: "
375 "$5 = vsum($1..$2); N :: $6 = vsum(@0$1..@0$2); N :: "
376 "$7 = vlen($1..$2); N :: $8 = vlen(@0$1..@0$2); N")))
377 (org-test-table-target-expect
378 references
/target-normal
380 | 0 | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
381 | z | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
382 | | 1 | 0 | 1 | 1 | 1 | 1 | 1 |
383 | | | 0 | 0 | 0 | 0 | 0 | 0 |
386 (org-test-table-target-expect
387 references
/target-special
389 | nan | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
390 | uinf | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
391 | -inf | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
392 | inf | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
396 (ert-deftest test-org-table
/lisp-return-value
()
397 "Basic: Return value of Lisp formulas."
398 (org-test-table-target-expect
400 | | nil | (list) | '() |
401 |-------------------------+-------------+--------+-----|
402 | type-of, no L | replace (r) | r | r |
403 | type-of identity, no L | r | r | r |
404 | identity, no L | r | r | r |
405 |-------------------------+-------------+--------+-----|
406 | type-of \"@1\" | r | r | r |
407 | type-of (identity \"@1\") | r | r | r |
408 | identity \"@1\" | r | r | r |
409 |-------------------------+-------------+--------+-----|
410 | type-of @1 | r | r | r |
411 | type-of (identity @1) | r | r | r |
412 | identity @1 | r | r | r |
415 | | nil | (list) | '() |
416 |-------------------------+--------+--------+--------|
417 | type-of, no L | string | string | string |
418 | type-of identity, no L | string | string | string |
419 | identity, no L | nil | (list) | '() |
420 |-------------------------+--------+--------+--------|
421 | type-of \"@1\" | string | string | string |
422 | type-of (identity \"@1\") | string | string | string |
423 | identity \"@1\" | nil | (list) | '() |
424 |-------------------------+--------+--------+--------|
425 | type-of @1 | symbol | symbol | symbol |
426 | type-of (identity @1) | symbol | symbol | symbol |
427 | identity @1 | nil | nil | nil |
429 1 (concat "#+TBLFM: @2$<<..@2$> = '(type-of @1) :: "
430 "@3$<<..@3$> = '(type-of (identity @1)) :: "
431 "@4$<<..@4$> = '(identity @1) :: @5$<<..@>$> = '(@0$1); L")))
433 (ert-deftest test-org-table
/compare
()
434 "Basic: Compare field references in Calc."
435 (org-test-table-target-expect
437 | | 0 | z | | nan | uinf | -inf | inf |
438 |------+------+------+------+------+------+------+------|
439 | 0 | repl | repl | repl | repl | repl | repl | repl |
440 | z | repl | repl | repl | repl | repl | repl | repl |
441 | | repl | repl | repl | repl | repl | repl | repl |
442 | nan | repl | repl | repl | repl | repl | repl | repl |
443 | uinf | repl | repl | repl | repl | repl | repl | repl |
444 | -inf | repl | repl | repl | repl | repl | repl | repl |
445 | inf | repl | repl | repl | repl | repl | repl | repl |
448 | | 0 | z | | nan | uinf | -inf | inf |
449 |------+---+---+---+-----+------+------+-----|
450 | 0 | x | | | | | | |
451 | z | | x | | | | | |
453 | nan | | | | x | | | |
454 | uinf | | | | | x | | |
455 | -inf | | | | | | x | |
456 | inf | | | | | | | x |
459 ;; Compare field reference ($1) with field reference (@1)
460 "#+TBLFM: @<<$<<..@>$> = if(\"$1\" == \"@1\", x, string(\"\")); E"
461 ;; Compare field reference ($1) with absolute term
463 "$2 = if(\"$1\" == \"(0)\" , x, string(\"\")); E :: "
464 "$3 = if(\"$1\" == \"(z)\" , x, string(\"\")); E :: "
465 "$4 = if(\"$1\" == \"nan\" , x, string(\"\")); E :: "
466 "$5 = if(\"$1\" == \"(nan)\" , x, string(\"\")); E :: "
467 "$6 = if(\"$1\" == \"(uinf)\", x, string(\"\")); E :: "
468 "$7 = if(\"$1\" == \"(-inf)\", x, string(\"\")); E :: "
469 "$8 = if(\"$1\" == \"(inf)\" , x, string(\"\")); E"))
471 ;; Check field reference converted from an empty field: Despite this
472 ;; field reference will not end up in a result, Calc evaluates it.
473 ;; Make sure that also then there is no Calc error.
474 (org-test-table-target-expect
487 1 "#+TBLFM: $2 = if(\"$1\" == \"nan\", string(\"\"), $1 + 1); E"))
489 (ert-deftest test-org-table
/empty-field
()
490 "Examples how to deal with empty fields."
491 ;; Test if one field is empty, else do a calculation
492 (org-test-table-target-expect
505 "#+TBLFM: $2 = if(\"$1\" == \"nan\", string(\"\"), $1 + 1); E"
507 "#+TBLFM: $2 = '(if (eq \"$1\" \"\") \"\" (1+ $1)); L")
509 ;; Test if several fields are empty, else do a calculation
510 (org-test-table-target-expect
525 (concat "#+TBLFM: $3 = if(\"$1\" == \"nan\" || \"$2\" == \"nan\", "
526 "string(\"\"), $1 + $2); E")
528 (concat "#+TBLFM: $3 = '(if (or (eq \"$1\" \"\") (eq \"$2\" \"\")) "
529 "\"\" (+ $1 $2)); L"))
531 ;; $2: Use $1 + 0.5 if $1 available, else only reformat $2 if $2 available
532 (org-test-table-target-expect
547 (concat "#+TBLFM: $2 = if(\"$1\" == \"nan\", "
548 "if(\"$2\" == \"nan\", string(\"\"), $2 +.0), $1 + 0.5); E f-1")
549 ;; Lisp formula not implemented yet
552 ;; Empty fields in simple and complex range reference
553 (org-test-table-target-expect
555 | | | | | repl | repl | repl | repl | repl | repl |
556 | | | 5 | 7 | repl | repl | repl | repl | repl | repl |
557 | 1 | 3 | 5 | 7 | repl | repl | repl | repl | repl | repl |
560 | | | | | | | | | 0 | 0 |
561 | | | 5 | 7 | | | 6 | 6 | 3 | 3 |
562 | 1 | 3 | 5 | 7 | 4 | 4 | 4 | 4 | 4 | 4 |
568 "$5 = if(typeof(vmean($1..$4)) == 12, "
569 "string(\"\"), vmean($1..$4)); E :: "
570 "$6 = if(typeof(vmean(@0$1..@0$4)) == 12, "
571 "string(\"\"), vmean(@0$1..@0$4)); E :: "
572 "$7 = if(\"$1..$4\" == \"[]\", string(\"\"), vmean($1..$4)) :: "
573 "$8 = if(\"@0$1..@0$4\" == \"[]\", string(\"\"), vmean(@0$1..@0$4)) :: "
574 "$9 = vmean($1..$4); EN :: "
575 "$10 = vmean(@0$1..@0$4); EN")
579 "$5 = '(let ((l '($1..$4))) (if (member \"\" l) \"\" "
580 "(/ (apply '+ (mapcar 'string-to-number l)) (length l)))); E :: "
581 "$6 = '(let ((l '(@0$1..@0$4))) (if (member \"\" l) \"\" "
582 "(/ (apply '+ (mapcar 'string-to-number l)) (length l)))); E :: "
583 "$7 = '(let ((l '($1..$4))) "
584 "(if l (/ (apply '+ l) (length l)) \"\")); N :: "
585 "$8 = '(let ((l '(@0$1..@0$4))) "
586 "(if l (/ (apply '+ l) (length l)) \"\")); N :: "
587 "$9 = '(/ (+ $1..$4) (length '($1..$4))); EN :: "
588 "$10 = '(/ (+ @0$1..@0$4) (length '(@0$1..@0$4))); EN")
591 (ert-deftest test-org-table
/copy-field
()
592 "Experiments on how to copy one field into another field.
593 See also `test-org-table/remote-reference-access'."
599 | 2012-12 | replace |
600 | [2012-12-31 Mon] | replace |
602 ;; Lisp formula to copy literally
603 (org-test-table-target-expect
610 | 2012-12 | 2012-12 |
611 | [2012-12-31 Mon] | [2012-12-31 Mon] |
613 1 "#+TBLFM: $2 = '(identity $1)")
615 ;; Calc formula to copy quite literally
616 (org-test-table-target-expect
623 | 2012-12 | 2012-12 |
624 | [2012-12-31 Mon] | <2012-12-31 Mon> |
626 1 (concat "#+TBLFM: $2 = if(\"$1\" == \"nan\", "
627 "string(\"\"), string(subvec(\"$1\", 2, vlen(\"$1\")))); E"))
629 ;; Calc formula simple
630 (org-test-table-target-expect
638 | [2012-12-31 Mon] | <2012-12-31 Mon> |
640 1 "#+TBLFM: $2 = if(\"$1\" == \"nan\", string(\"\"), $1); E")))
642 (ert-deftest test-org-table
/sub-total
()
643 "Grouped rows with sub-total.
644 Begin range with \"@II\" to handle multiline header. Convert
645 integer to float with \"+.0\" for sub-total of items c1 and c2.
646 Sum empty fields as value zero but without ignoring them for
647 \"vlen\" with format specifier \"EN\". Format possibly empty
648 results with the Calc formatter \"f-1\" instead of the printf
650 (org-test-table-target-expect
652 |-------+---------+---------|
653 | Item | Item | Sub- |
654 | name | value | total |
655 |-------+---------+---------|
656 | a1 | 4.1 | replace |
657 | a2 | 8.2 | replace |
659 |-------+---------+---------|
660 | b1 | 16.0 | replace |
661 |-------+---------+---------|
662 | c1 | 32 | replace |
663 | c2 | 64 | replace |
664 |-------+---------+---------|
665 | Total | replace | replace |
666 |-------+---------+---------|
669 |-------+-------+-------|
670 | Item | Item | Sub- |
671 | name | value | total |
672 |-------+-------+-------|
676 |-------+-------+-------|
678 |-------+-------+-------|
681 |-------+-------+-------|
683 |-------+-------+-------|
685 1 (concat "#+TBLFM: @>$2 = vsum(@II..@>>) ::"
686 "$3 = if(vlen(@0..@+I) == 1, "
687 "vsum(@-I$2..@+I$2) +.0, string(\"\")); EN f-1 :: "
688 "@>$3 = string(\"\")")))
690 (ert-deftest test-org-table
/org-lookup-all
()
691 "Use `org-lookup-all' for several GROUP BY as in SQL and for ranking.
692 See also http://orgmode.org/worg/org-tutorials/org-lookups.html ."
695 | Purchase | Product | Shop | Rating |
696 |----------+---------+------+--------|
703 ;; Product rating and ranking by average purchase from "#+NAME: data"
704 (org-test-table-target-expect
706 | Product | Rating | Ranking |
707 |---------+---------+---------|
708 | p1 | replace | replace |
709 | p2 | replace | replace |
710 | p3 | replace | replace |
713 | Product | Rating | Ranking |
714 |---------+--------+---------|
720 "#+TBLFM: $2 = '(let ((all (org-lookup-all '$1 "
721 "'(remote(data, @I$2..@>$2)) '(remote(data, @I$4..@>$4))))) "
722 "(/ (apply '+ all) (length all) 1.0)); L :: "
723 "$3 = '(+ 1 (length (org-lookup-all $2 '(@I$2..@>$2) nil '<))); N"))
725 ;; Shop rating and ranking by average purchase from "#+NAME: data"
726 (org-test-table-target-expect
728 | Shop | Rating | Ranking |
729 |------+---------+---------|
730 | s1 | replace | replace |
731 | s2 | replace | replace |
734 | Shop | Rating | Ranking |
735 |------+--------+---------|
740 "#+TBLFM: $2 = '(let ((all (org-lookup-all '$1 "
741 "'(remote(data, @I$3..@>$3)) '(remote(data, @I$4..@>$4))))) "
742 "(/ (apply '+ all) (length all) 1.0)); L :: "
743 "$3 = '(+ 1 (length (org-lookup-all $2 '(@I$2..@>$2) nil '<))); N"))))
745 (ert-deftest test-org-table
/org-table-make-reference
/mode-string-EL
()
746 (fset 'f
'org-table-make-reference
)
747 ;; For Lisp formula only
748 (should (equal "0" (f "0" t nil
'literal
)))
749 (should (equal "z" (f "z" t nil
'literal
)))
750 (should (equal "" (f "" t nil
'literal
)))
751 (should (equal "0 1" (f '("0" "1") t nil
'literal
)))
752 (should (equal "z 1" (f '("z" "1") t nil
'literal
)))
753 (should (equal " 1" (f '("" "1") t nil
'literal
)))
754 (should (equal " " (f '("" "" ) t nil
'literal
))))
756 (ert-deftest test-org-table
/org-table-make-reference
/mode-string-E
()
757 (fset 'f
'org-table-make-reference
)
759 (should (equal "\"0\"" (f "0" t nil t
)))
760 (should (equal "\"z\"" (f "z" t nil t
)))
761 (should (equal "\"\"" (f "" t nil t
)))
762 (should (equal "\"0\" \"1\"" (f '("0" "1") t nil t
)))
763 (should (equal "\"z\" \"1\"" (f '("z" "1") t nil t
)))
764 (should (equal "\"\" \"1\"" (f '("" "1") t nil t
)))
765 (should (equal "\"\" \"\"" (f '("" "" ) t nil t
)))
767 (should (equal "(0)" (f "0" t nil nil
)))
768 (should (equal "(z)" (f "z" t nil nil
)))
769 (should (equal "nan" (f "" t nil nil
)))
770 (should (equal "[0,1]" (f '("0" "1") t nil nil
)))
771 (should (equal "[z,1]" (f '("z" "1") t nil nil
)))
772 (should (equal "[nan,1]" (f '("" "1") t nil nil
)))
773 (should (equal "[nan,nan]" (f '("" "" ) t nil nil
)))
774 ;; For Calc formula, special numbers
775 (should (equal "(nan)" (f "nan" t nil nil
)))
776 (should (equal "(uinf)" (f "uinf" t nil nil
)))
777 (should (equal "(-inf)" (f "-inf" t nil nil
)))
778 (should (equal "(inf)" (f "inf" t nil nil
)))
779 (should (equal "[nan,1]" (f '( "nan" "1") t nil nil
)))
780 (should (equal "[uinf,1]" (f '("uinf" "1") t nil nil
)))
781 (should (equal "[-inf,1]" (f '("-inf" "1") t nil nil
)))
782 (should (equal "[inf,1]" (f '( "inf" "1") t nil nil
))))
784 (ert-deftest test-org-table
/org-table-make-reference
/mode-string-EN
()
785 (fset 'f
'org-table-make-reference
)
787 (should (equal "0" (f "0" t t t
)))
788 (should (equal "0" (f "z" t t t
)))
789 (should (equal "0" (f "" t t t
)))
790 (should (equal "0 1" (f '("0" "1") t t t
)))
791 (should (equal "0 1" (f '("z" "1") t t t
)))
792 (should (equal "0 1" (f '("" "1") t t t
)))
793 (should (equal "0 0" (f '("" "" ) t t t
)))
795 (should (equal "(0)" (f "0" t t nil
)))
796 (should (equal "(0)" (f "z" t t nil
)))
797 (should (equal "(0)" (f "" t t nil
)))
798 (should (equal "[0,1]" (f '("0" "1") t t nil
)))
799 (should (equal "[0,1]" (f '("z" "1") t t nil
)))
800 (should (equal "[0,1]" (f '("" "1") t t nil
)))
801 (should (equal "[0,0]" (f '("" "" ) t t nil
)))
802 ;; For Calc formula, special numbers
803 (should (equal "(0)" (f "nan" t t nil
)))
804 (should (equal "(0)" (f "uinf" t t nil
)))
805 (should (equal "(0)" (f "-inf" t t nil
)))
806 (should (equal "(0)" (f "inf" t t nil
)))
807 (should (equal "[0,1]" (f '( "nan" "1") t t nil
)))
808 (should (equal "[0,1]" (f '("uinf" "1") t t nil
)))
809 (should (equal "[0,1]" (f '("-inf" "1") t t nil
)))
810 (should (equal "[0,1]" (f '( "inf" "1") t t nil
))))
812 (ert-deftest test-org-table
/org-table-make-reference
/mode-string-L
()
813 (fset 'f
'org-table-make-reference
)
814 ;; For Lisp formula only
815 (should (equal "0" (f "0" nil nil
'literal
)))
816 (should (equal "z" (f "z" nil nil
'literal
)))
817 (should (equal "" (f "" nil nil
'literal
)))
818 (should (equal "0 1" (f '("0" "1") nil nil
'literal
)))
819 (should (equal "z 1" (f '("z" "1") nil nil
'literal
)))
820 (should (equal "1" (f '("" "1") nil nil
'literal
)))
821 (should (equal "" (f '("" "" ) nil nil
'literal
))))
823 (ert-deftest test-org-table
/org-table-make-reference
/mode-string-none
()
824 (fset 'f
'org-table-make-reference
)
826 (should (equal "\"0\"" (f "0" nil nil t
)))
827 (should (equal "\"z\"" (f "z" nil nil t
)))
828 (should (equal "" (f "" nil nil t
)))
829 (should (equal "\"0\" \"1\"" (f '("0" "1") nil nil t
)))
830 (should (equal "\"z\" \"1\"" (f '("z" "1") nil nil t
)))
831 (should (equal "\"1\"" (f '("" "1") nil nil t
)))
832 (should (equal "" (f '("" "" ) nil nil t
)))
834 (should (equal "(0)" (f "0" nil nil nil
)))
835 (should (equal "(z)" (f "z" nil nil nil
)))
836 (should (equal "(0)" (f "" nil nil nil
)))
837 (should (equal "[0,1]" (f '("0" "1") nil nil nil
)))
838 (should (equal "[z,1]" (f '("z" "1") nil nil nil
)))
839 (should (equal "[1]" (f '("" "1") nil nil nil
)))
840 (should (equal "[]" (f '("" "" ) nil nil nil
)))
841 ;; For Calc formula, special numbers
842 (should (equal "(nan)" (f "nan" nil nil nil
)))
843 (should (equal "(uinf)" (f "uinf" nil nil nil
)))
844 (should (equal "(-inf)" (f "-inf" nil nil nil
)))
845 (should (equal "(inf)" (f "inf" nil nil nil
)))
846 (should (equal "[nan,1]" (f '( "nan" "1") nil nil nil
)))
847 (should (equal "[uinf,1]" (f '("uinf" "1") nil nil nil
)))
848 (should (equal "[-inf,1]" (f '("-inf" "1") nil nil nil
)))
849 (should (equal "[inf,1]" (f '( "inf" "1") nil nil nil
))))
851 (ert-deftest test-org-table
/org-table-make-reference
/mode-string-N
()
852 (fset 'f
'org-table-make-reference
)
854 (should (equal "0" (f "0" nil t t
)))
855 (should (equal "0" (f "z" nil t t
)))
856 (should (equal "" (f "" nil t t
)))
857 (should (equal "0 1" (f '("0" "1") nil t t
)))
858 (should (equal "0 1" (f '("z" "1") nil t t
)))
859 (should (equal "1" (f '("" "1") nil t t
)))
860 (should (equal "" (f '("" "" ) nil t t
)))
862 (should (equal "(0)" (f "0" nil t nil
)))
863 (should (equal "(0)" (f "z" nil t nil
)))
864 (should (equal "(0)" (f "" nil t nil
)))
865 (should (equal "[0,1]" (f '("0" "1") nil t nil
)))
866 (should (equal "[0,1]" (f '("z" "1") nil t nil
)))
867 (should (equal "[1]" (f '("" "1") nil t nil
)))
868 (should (equal "[]" (f '("" "" ) nil t nil
)))
869 ;; For Calc formula, special numbers
870 (should (equal "(0)" (f "nan" nil t nil
)))
871 (should (equal "(0)" (f "uinf" nil t nil
)))
872 (should (equal "(0)" (f "-inf" nil t nil
)))
873 (should (equal "(0)" (f "inf" nil t nil
)))
874 (should (equal "[0,1]" (f '( "nan" "1") nil t nil
)))
875 (should (equal "[0,1]" (f '("uinf" "1") nil t nil
)))
876 (should (equal "[0,1]" (f '("-inf" "1") nil t nil
)))
877 (should (equal "[0,1]" (f '( "inf" "1") nil t nil
))))
879 (ert-deftest test-org-table
/org-table-convert-refs-to-an
/1 ()
880 "Simple reference @1$1."
882 (string= "A1" (org-table-convert-refs-to-an "@1$1"))))
885 ;; (ert-deftest test-org-table/org-table-convert-refs-to-an/2 ()
886 ;; "Self reference @1$1."
888 ;; (string= "A1 = $0" (org-table-convert-refs-to-an "@1$1 = $0"))))
890 (ert-deftest test-org-table
/org-table-convert-refs-to-an
/3 ()
893 (string= "C& = remote(FOO, @@#B&)" (org-table-convert-refs-to-an "$3 = remote(FOO, @@#$2)"))))
895 (ert-deftest test-org-table
/org-table-convert-refs-to-rc
/1 ()
896 "Simple reference @1$1."
898 (string= "@1$1" (org-table-convert-refs-to-rc "A1"))))
900 (ert-deftest test-org-table
/org-table-convert-refs-to-rc
/2 ()
903 (string= "@1$1 = $0" (org-table-convert-refs-to-rc "A1 = $0"))))
906 ;; (ert-deftest test-org-table/org-table-convert-refs-to-rc/3 ()
907 ;; "Remote reference."
909 ;; (string= "$3 = remote(FOO, @@#$2)" (org-table-convert-refs-to-rc "C& = remote(FOO, @@#B&)"))))
911 (ert-deftest test-org-table
/remote-reference-access
()
912 "Access to remote reference.
913 See also `test-org-table/copy-field'."
914 (org-test-table-target-expect
919 | replace | replace |
927 1 (concat "#+TBLFM: "
928 ;; Copy text without calculation: Use Lisp formula
929 "$1 = '(identity remote(table, @1$2)) :: "
930 ;; Do a calculation: Use Calc (or Lisp ) formula
931 "$2 = 2 * remote(table, @1$2)")))
933 (ert-deftest test-org-table
/remote-reference-indirect
()
934 "Access to remote reference with indirection of name or ID."
935 (let ((source-tables "
943 #+TBLFM: @>$1 = vsum(@I..@II)
952 #+TBLFM: @>$1 = vsum(@I..@II)
955 ;; Read several remote references from same column
956 (org-test-table-target-expect
957 (concat source-tables
"
966 (concat source-tables
"
977 "#+TBLFM: @<<$2..@>>$2 = remote($<, @>$1) :: @>$2 = vsum(@I..@II)"
979 (concat "#+TBLFM: @<<$2..@>>$2 = '(identity remote($<, @>$1)); N :: "
980 "@>$2 = '(+ @I..@II); N"))
982 ;; Read several remote references from same row
983 (org-test-table-target-expect
984 (concat source-tables
"
986 | year | 2012 | 2013 | total |
987 |--------+---------+---------+---------|
988 | amount | replace | replace | replace |
990 (concat source-tables
"
992 | year | 2012 | 2013 | total |
993 |--------+------+------+-------|
994 | amount | 3 | 12 | 15 |
998 "#+TBLFM: @2$<<..@2$>> = remote(@<, @>$1) :: @2$> = vsum($<<..$>>)"
1000 (concat "#+TBLFM: @2$<<..@2$>> = '(identity remote(@<, @>$1)); N :: "
1001 "@2$> = '(+ $<<..$>>); N"))))
1003 (ert-deftest test-org-table
/org-at-TBLFM-p
()
1004 (org-test-with-temp-text-in-file
1011 (goto-char (point-min))
1013 (should (equal (org-at-TBLFM-p) nil
))
1015 (goto-char (point-min))
1017 (should (equal (org-at-TBLFM-p) t
))
1019 (goto-char (point-min))
1021 (should (equal (org-at-TBLFM-p) nil
))))
1023 (ert-deftest test-org-table
/org-table-TBLFM-begin
()
1024 (org-test-with-temp-text-in-file
1031 (goto-char (point-min))
1032 (should (equal (org-table-TBLFM-begin)
1035 (goto-char (point-min))
1037 (should (equal (org-table-TBLFM-begin)
1040 (goto-char (point-min))
1042 (should (= (org-table-TBLFM-begin)
1045 (goto-char (point-min))
1047 (should (= (org-table-TBLFM-begin)
1052 (ert-deftest test-org-table
/org-table-TBLFM-begin-for-multiple-TBLFM-lines
()
1053 "For multiple #+TBLFM lines."
1054 (org-test-with-temp-text-in-file
1062 (goto-char (point-min))
1063 (should (equal (org-table-TBLFM-begin)
1066 (goto-char (point-min))
1068 (should (equal (org-table-TBLFM-begin)
1071 (goto-char (point-min))
1073 (should (= (org-table-TBLFM-begin)
1076 (goto-char (point-min))
1078 (should (= (org-table-TBLFM-begin)
1081 (goto-char (point-min))
1083 (should (= (org-table-TBLFM-begin)
1088 (ert-deftest test-org-table
/org-table-TBLFM-begin-for-pultiple-TBLFM-lines-blocks
()
1089 (org-test-with-temp-text-in-file
1102 (goto-char (point-min))
1103 (should (equal (org-table-TBLFM-begin)
1106 (goto-char (point-min))
1108 (should (equal (org-table-TBLFM-begin)
1111 (goto-char (point-min))
1113 (should (= (org-table-TBLFM-begin)
1116 (goto-char (point-min))
1118 (should (= (org-table-TBLFM-begin)
1121 (goto-char (point-min))
1123 (should (= (org-table-TBLFM-begin)
1126 (goto-char (point-min))
1128 (should (= (org-table-TBLFM-begin)
1131 (goto-char (point-min))
1133 (should (= (org-table-TBLFM-begin)
1136 (goto-char (point-min))
1138 (should (= (org-table-TBLFM-begin)
1141 (goto-char (point-min))
1143 (should (= (org-table-TBLFM-begin)
1146 (ert-deftest test-org-table
/org-table-calc-current-TBLFM
()
1147 (org-test-with-temp-text-in-file
1155 (let ((got (progn (goto-char (point-min))
1157 (org-table-calc-current-TBLFM)
1166 (should (string= got
1169 (let ((got (progn (goto-char (point-min))
1171 (org-table-calc-current-TBLFM)
1180 (should (string= got
1183 (ert-deftest test-org-table
/org-table-calc-current-TBLFM-when-stop-because-of-error
()
1184 "org-table-calc-current-TBLFM should preserve the input as it was."
1185 (org-test-with-temp-text-in-file
1190 #+TBLFM: $2=$1*2::$2=$1*2
1197 #+TBLFM: $2=$1*2::$2=$1*2
1200 (goto-char (point-min))
1202 (should-error (org-table-calc-current-TBLFM))
1203 (setq got
(buffer-string))
1205 (should (string= got
1210 (ert-deftest test-org-table
/to-generic
()
1211 "Test `orgtbl-to-generic' specifications."
1212 ;; Test :hline parameter.
1215 (orgtbl-to-generic (org-table-to-lisp "| a |\n|---|\n| b |")
1219 (orgtbl-to-generic (org-table-to-lisp "| a |\n|---|\n| b |")
1221 ;; Test :sep parameter.
1225 (org-table-to-lisp "| a | b |\n|---+---|\n| c | d |")
1227 ;; Test :hsep parameter.
1231 (org-table-to-lisp "| a | b |\n|---+---|\n| c | d |")
1232 '(:sep
"?" :hsep
"!"))))
1233 ;; Test :tstart parameter.
1236 (orgtbl-to-generic (org-table-to-lisp "| a |") '(:tstart
"<begin>"))))
1239 (orgtbl-to-generic (org-table-to-lisp "| a |")
1240 '(:tstart
(lambda () "<begin>")))))
1243 (orgtbl-to-generic (org-table-to-lisp "| a |")
1244 '(:tstart
"<begin>" :splice t
))))
1245 ;; Test :tend parameter.
1248 (orgtbl-to-generic (org-table-to-lisp "| a |") '(:tend
"<end>"))))
1251 (orgtbl-to-generic (org-table-to-lisp "| a |")
1252 '(:tend
(lambda () "<end>")))))
1255 (orgtbl-to-generic (org-table-to-lisp "| a |")
1256 '(:tend
"<end>" :splice t
))))
1257 ;; Test :lstart parameter.
1261 (org-table-to-lisp "| a |") '(:lstart
"> "))))
1264 (orgtbl-to-generic (org-table-to-lisp "| a |")
1265 '(:lstart
(lambda () "> ")))))
1266 ;; Test :llstart parameter.
1269 (orgtbl-to-generic (org-table-to-lisp "| a |\n|---|\n| b |")
1270 '(:lstart
"> " :llstart
">> "))))
1271 ;; Test :hlstart parameter.
1274 (orgtbl-to-generic (org-table-to-lisp "| a |\n|---|\n| b |")
1275 '(:lstart
"> " :hlstart
"!> "))))
1276 ;; Test :hllstart parameter.
1278 (equal "!> a\n!!> b\n> c"
1279 (orgtbl-to-generic (org-table-to-lisp "| a |\n| b |\n|---|\n| c |")
1280 '(:lstart
"> " :hlstart
"!> " :hllstart
"!!> "))))
1281 ;; Test :lend parameter.
1284 (orgtbl-to-generic (org-table-to-lisp "| a |") '(:lend
" <"))))
1285 ;; Test :llend parameter.
1288 (orgtbl-to-generic (org-table-to-lisp "| a |\n|---|\n| b |")
1289 '(:lend
" <" :llend
" <<"))))
1290 ;; Test :hlend parameter.
1293 (orgtbl-to-generic (org-table-to-lisp "| a |\n|---|\n| b |")
1294 '(:lend
" <" :hlend
" <!"))))
1295 ;; Test :hllend parameter.
1297 (equal "a <!\nb <!!\nc <"
1298 (orgtbl-to-generic (org-table-to-lisp "| a |\n| b |\n|---|\n| c |")
1299 '(:lend
" <" :hlend
" <!" :hllend
" <!!"))))
1300 ;; Test :lfmt parameter.
1303 (orgtbl-to-generic (org-table-to-lisp "| a | b |")
1308 (org-table-to-lisp "| a | b |")
1309 '(:lfmt
(lambda (c) (concat (car c
) "+" (cadr c
)))))))
1312 (orgtbl-to-generic (org-table-to-lisp "| a | b |")
1313 '(:lfmt
"%s!%s" :lstart
">" :lend
"<" :sep
" "))))
1314 ;; Test :llfmt parameter.
1317 (orgtbl-to-generic (org-table-to-lisp "| a | b |")
1318 '(:llfmt
"%s!%s"))))
1322 (org-table-to-lisp "| a | b |\n| c | d |")
1323 '(:lfmt
"%s!%s" :llfmt
(lambda (c) (concat (car c
) "+" (cadr c
)))))))
1326 (orgtbl-to-generic (org-table-to-lisp "| a | b |")
1327 '(:llfmt
"%s!%s" :lstart
">" :lend
"<" :sep
" "))))
1328 ;; Test :hlfmt parameter.
1332 (org-table-to-lisp "| a | b |\n|---+---|\n| c | d |")
1333 '(:hlfmt
"%s!%s"))))
1337 (org-table-to-lisp "| a | b |\n|---+---|\n| c | d |")
1338 '(:hlfmt
(lambda (c) (concat (car c
) "+" (cadr c
)))))))
1342 (org-table-to-lisp "| a | b |\n|---+---|\n| c | d |")
1343 '(:hlfmt
"%s!%s" :lstart
">" :lend
"<" :sep
" "))))
1344 ;; Test :hllfmt parameter.
1348 (org-table-to-lisp "| a | b |\n|---+---|\n| c | d |")
1349 '(:hllfmt
"%s!%s"))))
1353 (org-table-to-lisp "| a | b |\n|---+---|\n| c | d |")
1354 '(:hllfmt
(lambda (c) (concat (car c
) "+" (cadr c
)))))))
1358 (org-table-to-lisp "| a | b |\n|---+---|\n| c | d |")
1359 '(:hllfmt
"%s!%s" :lstart
">" :lend
"<" :sep
" "))))
1360 ;; Test :fmt parameter.
1363 (orgtbl-to-generic (org-table-to-lisp "| a |\n|---|\n| b |")
1367 (orgtbl-to-generic (org-table-to-lisp "| a | b |")
1368 '(:fmt
(1 ">%s<" 2 (lambda (c) c
))))))
1371 (orgtbl-to-generic (org-table-to-lisp "| a | b |")
1372 '(:fmt
(2 " %s")))))
1375 (orgtbl-to-generic (org-table-to-lisp "| a |")
1376 '(:fmt
(lambda (c) (format ">%s<" c
))))))
1377 ;; Test :hfmt parameter.
1380 (orgtbl-to-generic (org-table-to-lisp "| a |\n|---|\n| b |")
1385 (org-table-to-lisp "| a | b |\n|---+---|\n| c | d |")
1386 '(:hfmt
(1 ">%s<" 2 identity
)))))
1390 (org-table-to-lisp "| a | b |\n|---+---|\n| c | d |")
1391 '(:hfmt
(2 " %s")))))
1394 (orgtbl-to-generic (org-table-to-lisp "| a |\n|---|\n| b |")
1395 '(:hfmt
(lambda (c) (format ">%s<" c
))))))
1396 ;; Test :efmt parameter.
1399 (orgtbl-to-generic (org-table-to-lisp "| 2e3 |")
1400 '(:efmt
"%sx10^%s"))))
1403 (orgtbl-to-generic (org-table-to-lisp "| 2e3 |")
1404 '(:efmt
(lambda (m e
) (concat m
"x10^" e
))))))
1407 (orgtbl-to-generic (org-table-to-lisp "| 2e3 |")
1408 '(:efmt
(1 "%sx10^%s")))))
1412 (org-table-to-lisp "| 2e3 |")
1413 '(:efmt
(1 (lambda (m e
) (format "%sx10^%s" m e
)))))))
1416 (orgtbl-to-generic (org-table-to-lisp "| 2e3 |") '(:efmt nil
))))
1417 ;; Test :skip parameter.
1421 (org-table-to-lisp "| \ | <c> |\n| a | b |\n|---+---|\n| c | d |")
1423 ;; Test :skipcols parameter.
1427 (org-table-to-lisp "| a | b |\n| c | d |") '(:skipcols
(2)))))
1432 "| / | <c> | <c> |\n| # | a | b |\n|---+---+---|\n| | c | d |")
1434 ;; Test :raw parameter.
1435 (when (featurep 'ox-latex
)
1439 (orgtbl-to-generic (org-table-to-lisp "| /a/ | b |")
1440 '(:backend latex
:raw t
))))))
1442 (ert-deftest test-org-table
/to-latex
()
1443 "Test `orgtbl-to-latex' specifications."
1445 (equal "\\begin{tabular}{l}\na\\\\\n\\end{tabular}"
1446 (orgtbl-to-latex (org-table-to-lisp "| a |") nil
)))
1447 ;; Test :environment parameter.
1449 (equal "\\begin{tabularx}{l}\na\\\\\n\\end{tabularx}"
1450 (orgtbl-to-latex (org-table-to-lisp "| a |")
1451 '(:environment
"tabularx"))))
1452 ;; Test :booktabs parameter.
1455 "\\toprule" (orgtbl-to-latex (org-table-to-lisp "| a |") '(:booktabs t
)))))
1457 (ert-deftest test-org-table
/to-html
()
1458 "Test `orgtbl-to-html' specifications."
1460 (equal (orgtbl-to-html (org-table-to-lisp "| a |") nil
)
1461 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">
1465 <col class=\"left\" />
1469 <td class=\"left\">a</td>
1473 ;; Test :attributes parameter.
1477 (orgtbl-to-html (org-table-to-lisp "| a |") '(:attributes nil
))))
1480 "<table border=\"2\">"
1481 (orgtbl-to-html (org-table-to-lisp "| a |") '(:attributes
(:border
"2"))))))
1483 (ert-deftest test-org-table
/to-texinfo
()
1484 "Test `orgtbl-to-texinfo' specifications."
1486 (equal "@multitable {a}\n@item a\n@end multitable"
1487 (orgtbl-to-texinfo (org-table-to-lisp "| a |") nil
)))
1488 ;; Test :columns parameter.
1490 (equal "@multitable @columnfractions .4 .6\n@item a\n@tab b\n@end multitable"
1491 (orgtbl-to-texinfo (org-table-to-lisp "| a | b |")
1492 '(:columns
".4 .6"))))
1494 (equal "@multitable @columnfractions .4 .6\n@item a\n@tab b\n@end multitable"
1495 (orgtbl-to-texinfo (org-table-to-lisp "| a | b |")
1496 '(:columns
"@columnfractions .4 .6"))))
1498 (equal "@multitable {xxx} {xx}\n@item a\n@tab b\n@end multitable"
1499 (orgtbl-to-texinfo (org-table-to-lisp "| a | b |")
1500 '(:columns
"{xxx} {xx}")))))
1502 (ert-deftest test-org-table
/to-orgtbl
()
1503 "Test `orgtbl-to-orgtbl' specifications."
1505 (equal "| a | b |\n|---+---|\n| c | d |"
1507 (org-table-to-lisp "| a | b |\n|---+---|\n| c | d |") nil
))))
1509 (ert-deftest test-org-table
/to-unicode
()
1510 "Test `orgtbl-to-unicode' specifications."
1512 (equal "━━━\n a \n━━━"
1513 (orgtbl-to-unicode (org-table-to-lisp "| a |") nil
)))
1514 ;; Test :narrow parameter.
1516 (equal "━━━━\n => \n━━━━"
1517 (orgtbl-to-unicode (org-table-to-lisp "| <2> |\n| xxx |")
1520 (ert-deftest test-org-table
/send-region
()
1521 "Test `orgtbl-send-table' specifications."
1522 ;; Error when not at a table.
1524 (org-test-with-temp-text "Paragraph"
1525 (orgtbl-send-table)))
1526 ;; Error when destination is missing.
1528 (org-test-with-temp-text "#+ORGTBL: SEND\n<point>| a |"
1529 (orgtbl-send-table)))
1530 ;; Error when transformation function is not specified.
1532 (org-test-with-temp-text "
1533 # BEGIN RECEIVE ORGTBL table
1534 # END RECEIVE ORGTBL table
1535 #+ORGTBL: SEND table
1537 (orgtbl-send-table)))
1540 (equal "| a |\n|---|\n| b |\n"
1541 (org-test-with-temp-text "
1542 # BEGIN RECEIVE ORGTBL table
1543 # END RECEIVE ORGTBL table
1544 #+ORGTBL: SEND table orgtbl-to-orgtbl :hlines nil
1545 <point>| a |\n|---|\n| b |"
1547 (goto-char (point-min))
1548 (buffer-substring-no-properties
1549 (search-forward "# BEGIN RECEIVE ORGTBL table\n")
1550 (progn (search-forward "# END RECEIVE ORGTBL table")
1551 (match-beginning 0)))))))
1554 (provide 'test-org-table
)
1556 ;;; test-org-table.el ends here