Use nan for empty fields in Calc formulas
[org-mode.git] / testing / lisp / test-org-table.el
blob4c09239c5346794221284eeb98d54ac861c2a9ab
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 | nan | nan | nan | nan | 2 | 2 |
260 | | | nan | nan | nan | nan | 2 | 2 |
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 | repl |
404 | z | repl | repl | repl | repl | repl | repl | repl |
405 | | repl | repl | repl | repl | repl | repl | repl |
406 | nan | repl | repl | repl | repl | repl | repl | repl |
407 | uinf | repl | repl | repl | repl | repl | repl | repl |
408 | -inf | repl | repl | repl | repl | repl | repl | repl |
409 | inf | repl | repl | repl | repl | repl | repl | repl |
412 | | 0 | z | | nan | uinf | -inf | inf |
413 |------+---+---+---+-----+------+------+-----|
414 | 0 | x | | | | | | |
415 | z | | x | | | | | |
416 | | | | x | | | | |
417 | nan | | | | x | | | |
418 | uinf | | | | | x | | |
419 | -inf | | | | | | x | |
420 | inf | | | | | | | x |
423 ;; Compare field reference ($1) with field reference (@1)
424 "#+TBLFM: @I$<<..@>$> = if(\"$1\" = \"@1\", x, string(\"\")); E"
425 ;; Compare field reference ($1) with absolute term
426 (concat "#+TBLFM: "
427 "$2 = if(\"$1\" = \"(0)\" , x, string(\"\")); E :: "
428 "$3 = if(\"$1\" = \"(z)\" , x, string(\"\")); E :: "
429 "$4 = if(\"$1\" = \"nan\" , x, string(\"\")); E :: "
430 "$5 = if(\"$1\" = \"(nan)\" , x, string(\"\")); E :: "
431 "$6 = if(\"$1\" = \"(uinf)\", x, string(\"\")); E :: "
432 "$7 = if(\"$1\" = \"(-inf)\", x, string(\"\")); E :: "
433 "$8 = if(\"$1\" = \"(inf)\" , x, string(\"\")); E"))
435 ;; Check field reference converted from an empty field: Despite this
436 ;; field reference will not end up in a result, Calc evaluates it.
437 ;; Make sure that also then there is no Calc error.
438 (org-test-table-target-expect
440 | 0 | replace |
441 | z | replace |
442 | | replace |
443 | nan | replace |
446 | 0 | 1 |
447 | z | z + 1 |
448 | | |
449 | nan | nan |
451 1 "#+TBLFM: $2 = if(\"$1\" = \"nan\", string(\"\"), $1 + 1); E"))
453 (ert-deftest test-org-table/empty-field ()
454 "Examples how to deal with empty fields."
455 ;; Empty fields in simple and complex range reference: Suppress them
456 ;; ($5 and $6) or keep them and use 0 ($7 and $8)
458 (org-test-table-target-expect
459 "\n| | | 5 | 7 | replace | replace | replace | replace |\n"
460 "\n| | | 5 | 7 | 6 | 6 | 3 | 3 |\n"
462 ;; Calc formula
463 (concat "#+TBLFM: "
464 "$5 = vmean($1..$4) :: $6 = vmean(@0$1..@0$4) :: "
465 "$7 = vmean($1..$4); EN :: $8 = vmean(@0$1..@0$4); EN")
466 ;; Lisp formula
467 (concat "#+TBLFM: "
468 "$5 = '(/ (+ $1..$4 ) (length '( $1..$4 ))); N :: "
469 "$6 = '(/ (+ @0$1..@0$4) (length '(@0$1..@0$4))); N :: "
470 "$7 = '(/ (+ $1..$4 ) (length '( $1..$4 ))); EN :: "
471 "$8 = '(/ (+ @0$1..@0$4) (length '(@0$1..@0$4))); EN"))
473 ;; Test if one field is empty, else do a calculation
474 (org-test-table-target-expect
476 | -1 | replace |
477 | 0 | replace |
478 | | replace |
481 | -1 | 0 |
482 | 0 | 1 |
483 | | |
486 ;; Calc formula
487 "#+TBLFM: $2 = if(\"$1\" = \"nan\", string(\"\"), $1 + 1); E"
488 ;; Lisp formula
489 "#+TBLFM: $2 = '(if (eq \"$1\" \"\") \"\" (1+ $1)); L")
491 ;; Test if several fields are empty, else do a calculation
492 (org-test-table-target-expect
494 | 1 | 2 | replace |
495 | 4 | | replace |
496 | | 8 | replace |
497 | | | replace |
500 | 1 | 2 | 3 |
501 | 4 | | |
502 | | 8 | |
503 | | | |
506 ;; Calc formula
507 (concat "#+TBLFM: $3 = if(\"$1\" = \"nan\" || \"$2\" = \"nan\", "
508 "string(\"\"), $1 + $2); E")
509 ;; Lisp formula
510 (concat "#+TBLFM: $3 = '(if (or (eq \"$1\" \"\") (eq \"$2\" \"\")) "
511 "\"\" (+ $1 $2)); L"))
513 ;; $2: Use $1 + 0.5 if $1 available, else only reformat $2 if $2 available
514 (org-test-table-target-expect
516 | 1.5 | 0 |
517 | 3.5 | |
518 | | 5 |
519 | | |
522 | 1.5 | 2.0 |
523 | 3.5 | 4.0 |
524 | | 5.0 |
525 | | |
528 ;; Calc formula
529 (concat "#+TBLFM: $2 = if(\"$1\" = \"nan\", "
530 "if(\"$2\" = \"nan\", string(\"\"), $2 +.0), $1 + 0.5); E f-1")
531 ;; Lisp formula not implemented yet
534 (ert-deftest test-org-table/copy-field ()
535 "Experiments on how to copy one field into another field."
536 (let ((target
538 | 0 | replace |
539 | a b | replace |
540 | c d | replace |
541 | | replace |
542 | 2012-12 | replace |
543 | [2012-12-31 Mon] | replace |
545 ;; Lisp formula to copy literally
546 (org-test-table-target-expect
547 target
549 | 0 | 0 |
550 | a b | a b |
551 | c d | c d |
552 | | |
553 | 2012-12 | 2012-12 |
554 | [2012-12-31 Mon] | [2012-12-31 Mon] |
556 1 "#+TBLFM: $2 = '(identity $1)")
558 ;; Calc formula to copy quite literally
559 (org-test-table-target-expect
560 target
562 | 0 | 0 |
563 | a b | a b |
564 | c d | c d |
565 | | |
566 | 2012-12 | 2012-12 |
567 | [2012-12-31 Mon] | <2012-12-31 Mon> |
569 1 (concat "#+TBLFM: $2 = if(\"$1\" = \"nan\", "
570 "string(\"\"), string(subvec(\"$1\", 2, vlen(\"$1\")))); E"))
572 ;; Calc formula simple
573 (org-test-table-target-expect
574 target
576 | 0 | 0 |
577 | a b | a b |
578 | c d | c d |
579 | | |
580 | 2012-12 | 2000 |
581 | [2012-12-31 Mon] | <2012-12-31 Mon> |
583 1 "#+TBLFM: $2 = if(\"$1\" = \"nan\", string(\"\"), $1); E")))
585 ;; End of table examples and beginning of internal tests.
587 (ert-deftest test-org-table/org-table-make-reference/format-specifier-EL ()
588 (fset 'f 'org-table-make-reference)
589 ;; For Lisp formula only
590 (should (equal "0" (f "0" t nil 'literal)))
591 (should (equal "z" (f "z" t nil 'literal)))
592 (should (equal "" (f "" t nil 'literal)))
593 (should (equal "0 1" (f '("0" "1") t nil 'literal)))
594 (should (equal "z 1" (f '("z" "1") t nil 'literal)))
595 (should (equal " 1" (f '("" "1") t nil 'literal)))
596 (should (equal " " (f '("" "" ) t nil 'literal))))
598 (ert-deftest test-org-table/org-table-make-reference/format-specifier-E ()
599 (fset 'f 'org-table-make-reference)
600 ;; For Lisp formula
601 (should (equal "\"0\"" (f "0" t nil t)))
602 (should (equal "\"z\"" (f "z" t nil t)))
603 (should (equal "\"\"" (f "" t nil t)))
604 (should (equal "\"0\" \"1\"" (f '("0" "1") t nil t)))
605 (should (equal "\"z\" \"1\"" (f '("z" "1") t nil t)))
606 (should (equal "\"\" \"1\"" (f '("" "1") t nil t)))
607 (should (equal "\"\" \"\"" (f '("" "" ) t nil t)))
608 ;; For Calc formula
609 (should (equal "(0)" (f "0" t nil nil)))
610 (should (equal "(z)" (f "z" t nil nil)))
611 (should (equal "nan" (f "" t nil nil)))
612 (should (equal "[0,1]" (f '("0" "1") t nil nil)))
613 (should (equal "[z,1]" (f '("z" "1") t nil nil)))
614 (should (equal "[nan,1]" (f '("" "1") t nil nil)))
615 (should (equal "[nan,nan]" (f '("" "" ) t nil nil)))
616 ;; For Calc formula, special numbers
617 (should (equal "(nan)" (f "nan" t nil nil)))
618 (should (equal "(uinf)" (f "uinf" t nil nil)))
619 (should (equal "(-inf)" (f "-inf" t nil nil)))
620 (should (equal "(inf)" (f "inf" t nil nil)))
621 (should (equal "[nan,1]" (f '( "nan" "1") t nil nil)))
622 (should (equal "[uinf,1]" (f '("uinf" "1") t nil nil)))
623 (should (equal "[-inf,1]" (f '("-inf" "1") t nil nil)))
624 (should (equal "[inf,1]" (f '( "inf" "1") t nil nil))))
626 (ert-deftest test-org-table/org-table-make-reference/format-specifier-EN ()
627 (fset 'f 'org-table-make-reference)
628 ;; For Lisp formula
629 (should (equal "0" (f "0" t t t)))
630 (should (equal "0" (f "z" t t t)))
631 (should (equal "0" (f "" t t t)))
632 (should (equal "0 1" (f '("0" "1") t t t)))
633 (should (equal "0 1" (f '("z" "1") t t t)))
634 (should (equal "0 1" (f '("" "1") t t t)))
635 (should (equal "0 0" (f '("" "" ) t t t)))
636 ;; For Calc formula
637 (should (equal "(0)" (f "0" t t nil)))
638 (should (equal "(0)" (f "z" t t nil)))
639 (should (equal "(0)" (f "" t t nil)))
640 (should (equal "[0,1]" (f '("0" "1") t t nil)))
641 (should (equal "[0,1]" (f '("z" "1") t t nil)))
642 (should (equal "[0,1]" (f '("" "1") t t nil)))
643 (should (equal "[0,0]" (f '("" "" ) t t nil)))
644 ;; For Calc formula, special numbers
645 (should (equal "(0)" (f "nan" t t nil)))
646 (should (equal "(0)" (f "uinf" t t nil)))
647 (should (equal "(0)" (f "-inf" t t nil)))
648 (should (equal "(0)" (f "inf" t t nil)))
649 (should (equal "[0,1]" (f '( "nan" "1") t t nil)))
650 (should (equal "[0,1]" (f '("uinf" "1") t t nil)))
651 (should (equal "[0,1]" (f '("-inf" "1") t t nil)))
652 (should (equal "[0,1]" (f '( "inf" "1") t t nil))))
654 (ert-deftest test-org-table/org-table-make-reference/format-specifier-L ()
655 (fset 'f 'org-table-make-reference)
656 ;; For Lisp formula only
657 (should (equal "0" (f "0" nil nil 'literal)))
658 (should (equal "z" (f "z" nil nil 'literal)))
659 (should (equal "" (f "" nil nil 'literal)))
660 (should (equal "0 1" (f '("0" "1") nil nil 'literal)))
661 (should (equal "z 1" (f '("z" "1") nil nil 'literal)))
662 (should (equal "1" (f '("" "1") nil nil 'literal)))
663 (should (equal "" (f '("" "" ) nil nil 'literal))))
665 (ert-deftest test-org-table/org-table-make-reference/format-specifier-none ()
666 (fset 'f 'org-table-make-reference)
667 ;; For Lisp formula
668 (should (equal "\"0\"" (f "0" nil nil t)))
669 (should (equal "\"z\"" (f "z" nil nil t)))
670 (should (equal "\"\"" (f "" nil nil t)))
671 (should (equal "\"0\" \"1\"" (f '("0" "1") nil nil t)))
672 (should (equal "\"z\" \"1\"" (f '("z" "1") nil nil t)))
673 (should (equal "\"1\"" (f '("" "1") nil nil t)))
674 (should (equal "\"\"" (f '("" "" ) nil nil t)))
675 ;; For Calc formula
676 (should (equal "(0)" (f "0" nil nil nil)))
677 (should (equal "(z)" (f "z" nil nil nil)))
678 (should (equal "(0)" (f "" nil nil nil)))
679 (should (equal "[0,1]" (f '("0" "1") nil nil nil)))
680 (should (equal "[z,1]" (f '("z" "1") nil nil nil)))
681 (should (equal "[1]" (f '("" "1") nil nil nil)))
682 (should (equal "[0]" (f '("" "" ) nil nil nil)))
683 ;; For Calc formula, special numbers
684 (should (equal "(nan)" (f "nan" nil nil nil)))
685 (should (equal "(uinf)" (f "uinf" nil nil nil)))
686 (should (equal "(-inf)" (f "-inf" nil nil nil)))
687 (should (equal "(inf)" (f "inf" nil nil nil)))
688 (should (equal "[nan,1]" (f '( "nan" "1") nil nil nil)))
689 (should (equal "[uinf,1]" (f '("uinf" "1") nil nil nil)))
690 (should (equal "[-inf,1]" (f '("-inf" "1") nil nil nil)))
691 (should (equal "[inf,1]" (f '( "inf" "1") nil nil nil))))
693 (ert-deftest test-org-table/org-table-make-reference/format-specifier-N ()
694 (fset 'f 'org-table-make-reference)
695 ;; For Lisp formula
696 (should (equal "0" (f "0" nil t t)))
697 (should (equal "0" (f "z" nil t t)))
698 (should (equal "0" (f "" nil t t)))
699 (should (equal "0 1" (f '("0" "1") nil t t)))
700 (should (equal "0 1" (f '("z" "1") nil t t)))
701 (should (equal "1" (f '("" "1") nil t t)))
702 (should (equal "0" (f '("" "" ) nil t t)))
703 ;; For Calc formula
704 (should (equal "(0)" (f "0" nil t nil)))
705 (should (equal "(0)" (f "z" nil t nil)))
706 (should (equal "(0)" (f "" nil t nil)))
707 (should (equal "[0,1]" (f '("0" "1") nil t nil)))
708 (should (equal "[0,1]" (f '("z" "1") nil t nil)))
709 (should (equal "[1]" (f '("" "1") nil t nil)))
710 (should (equal "[0]" (f '("" "" ) nil t nil)))
711 ;; For Calc formula, special numbers
712 (should (equal "(0)" (f "nan" nil t nil)))
713 (should (equal "(0)" (f "uinf" nil t nil)))
714 (should (equal "(0)" (f "-inf" nil t nil)))
715 (should (equal "(0)" (f "inf" nil t nil)))
716 (should (equal "[0,1]" (f '( "nan" "1") nil t nil)))
717 (should (equal "[0,1]" (f '("uinf" "1") nil t nil)))
718 (should (equal "[0,1]" (f '("-inf" "1") nil t nil)))
719 (should (equal "[0,1]" (f '( "inf" "1") nil t nil))))
721 (ert-deftest test-org-table/org-table-convert-refs-to-an/1 ()
722 "Simple reference @1$1."
723 (should
724 (string= "A1" (org-table-convert-refs-to-an "@1$1"))))
726 ;; TODO: Test broken
727 ;; (ert-deftest test-org-table/org-table-convert-refs-to-an/2 ()
728 ;; "Self reference @1$1."
729 ;; (should
730 ;; (string= "A1 = $0" (org-table-convert-refs-to-an "@1$1 = $0"))))
732 (ert-deftest test-org-table/org-table-convert-refs-to-an/3 ()
733 "Remote reference."
734 (should
735 (string= "C& = remote(FOO, @@#B&)" (org-table-convert-refs-to-an "$3 = remote(FOO, @@#$2)"))))
737 (ert-deftest test-org-table/org-table-convert-refs-to-rc/1 ()
738 "Simple reference @1$1."
739 (should
740 (string= "@1$1" (org-table-convert-refs-to-rc "A1"))))
742 (ert-deftest test-org-table/org-table-convert-refs-to-rc/2 ()
743 "Self reference $0."
744 (should
745 (string= "@1$1 = $0" (org-table-convert-refs-to-rc "A1 = $0"))))
747 ;; TODO: Test Broken
748 ;; (ert-deftest test-org-table/org-table-convert-refs-to-rc/3 ()
749 ;; "Remote reference."
750 ;; (should
751 ;; (string= "$3 = remote(FOO, @@#$2)" (org-table-convert-refs-to-rc "C& = remote(FOO, @@#B&)"))))
753 (provide 'test-org-table)
755 ;;; test-org-table.el ends here