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