68949d9e8fe2e92ef776268da4abf59c87be6994
[org-mode.git] / testing / lisp / test-org-table.el
blob68949d9e8fe2e92ef776268da4abf59c87be6994
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.
312 ;; TODO: Len for range reference with only empty fields should be 0.
314 | 0 | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
315 | z | 1 | z | #ERROR | #ERROR | #ERROR | 2 | 2 |
316 | | 1 | | 1 | 1 | 1 | 1 | 1 |
317 | | | | 0 | 0 | 0 | 1 | 1 |
319 1 (concat
320 "#+TBLFM: $3 = '(identity \"$1\"); L :: $4 = '(+ $1 $2); L :: "
321 "$5 = '(+ $1..$2); L :: $6 = '(+ @0$1..@0$2); L :: "
322 "$7 = '(length '($1..$2)); L :: $8 = '(length '(@0$1..@0$2)); L")))
324 (ert-deftest test-org-table/references/format-specifier-none ()
325 "Basic: Assign field reference, sum of field references, sum
326 and len of simple range reference (no row) and complex range
327 reference (with row). No format specifier."
328 (let ((lisp (concat
329 "#+TBLFM: $3 = '(identity $1) :: $4 = '(+ $1 $2) :: "
330 "$5 = '(+ $1..$2) :: $6 = '(+ @0$1..@0$2) :: "
331 "$7 = '(length '($1..$2)) :: $8 = '(length '(@0$1..@0$2))"))
332 (calc (concat
333 "#+TBLFM: $3 = $1 :: $4 = $1 + $2 :: "
334 "$5 = vsum($1..$2) :: $6 = vsum(@0$1..@0$2) :: "
335 "$7 = vlen($1..$2) :: $8 = vlen(@0$1..@0$2)")))
336 (org-test-table-target-expect
337 references/target-normal
338 ;; All the #ERROR show that for Lisp calculations N has to be used.
340 | 0 | 1 | 0 | #ERROR | #ERROR | #ERROR | 2 | 2 |
341 | z | 1 | z | #ERROR | #ERROR | #ERROR | 2 | 2 |
342 | | 1 | | #ERROR | #ERROR | #ERROR | 1 | 1 |
343 | | | | #ERROR | #ERROR | #ERROR | 1 | 1 |
345 1 lisp)
346 (org-test-table-target-expect
347 references/target-normal
349 | 0 | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
350 | z | 1 | z | z + 1 | z + 1 | z + 1 | 2 | 2 |
351 | | 1 | 0 | 1 | 1 | 1 | 1 | 1 |
352 | | | 0 | 0 | 0 | 0 | 1 | 1 |
354 1 calc)
355 (org-test-table-target-expect
356 references/target-special
358 | nan | 1 | nan | nan | nan | nan | 2 | 2 |
359 | uinf | 1 | uinf | uinf | uinf | uinf | 2 | 2 |
360 | -inf | 1 | -inf | -inf | -inf | -inf | 2 | 2 |
361 | inf | 1 | inf | inf | inf | inf | 2 | 2 |
363 1 calc)))
365 (ert-deftest test-org-table/references/format-specifier-N ()
366 "Basic: Assign field reference, sum of field references, sum
367 and len of simple range reference (no row) and complex range
368 reference (with row). Format specifier N."
369 (let ((lisp
370 (concat
371 "#+TBLFM: $3 = '(identity $1); N :: $4 = '(+ $1 $2); N :: "
372 "$5 = '(+ $1..$2); N :: $6 = '(+ @0$1..@0$2); N :: "
373 "$7 = '(length '($1..$2)); N :: $8 = '(length '(@0$1..@0$2)); N"))
374 (calc
375 (concat
376 "#+TBLFM: $3 = $1; N :: $4 = $1 + $2; N :: "
377 "$5 = vsum($1..$2); N :: $6 = vsum(@0$1..@0$2); N :: "
378 "$7 = vlen($1..$2); N :: $8 = vlen(@0$1..@0$2); N")))
379 (org-test-table-target-expect
380 references/target-normal
381 ;; TODO: Len for simple range reference with empty field should
382 ;; also be 1
384 | 0 | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
385 | z | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
386 | | 1 | 0 | 1 | 1 | 1 | 2 | 1 |
387 | | | 0 | 0 | 0 | 0 | 2 | 1 |
389 1 lisp calc)
390 (org-test-table-target-expect
391 references/target-special
393 | nan | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
394 | uinf | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
395 | -inf | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
396 | inf | 1 | 0 | 1 | 1 | 1 | 2 | 2 |
398 1 calc)))
400 (ert-deftest test-org-table/compare ()
401 "Basic: Compare field references in Calc."
402 (org-test-table-target-expect
404 | | 0 | z | nan | uinf | -inf | inf |
405 |------+------+------+------+------+------+------|
406 | 0 | repl | repl | repl | repl | repl | repl |
407 | z | repl | repl | repl | repl | repl | repl |
408 | nan | repl | repl | repl | repl | repl | repl |
409 | uinf | repl | repl | repl | repl | repl | repl |
410 | -inf | repl | repl | repl | repl | repl | repl |
411 | inf | repl | repl | repl | repl | repl | repl |
414 | | 0 | z | nan | uinf | -inf | inf |
415 |------+---+---+-----+------+------+-----|
416 | 0 | x | | | | | |
417 | z | | x | | | | |
418 | nan | | | x | | | |
419 | uinf | | | | x | | |
420 | -inf | | | | | x | |
421 | inf | | | | | | x |
424 ;; Compare field reference ($1) with field reference (@1)
425 "#+TBLFM: @I$<<..@>$> = if(\"$1\" = \"@1\", x, string(\"\")); E"
426 ;; Compare field reference ($1) with absolute term
427 (concat "#+TBLFM: "
428 "$2 = if(\"$1\" = \"(0)\" , x, string(\"\")); E :: "
429 "$3 = if(\"$1\" = \"(z)\" , x, string(\"\")); E :: "
430 "$4 = if(\"$1\" = \"(nan)\" , x, string(\"\")); E :: "
431 "$5 = if(\"$1\" = \"(uinf)\", x, string(\"\")); E :: "
432 "$6 = if(\"$1\" = \"(-inf)\", x, string(\"\")); E :: "
433 "$7 = 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 | nan | replace |
445 | 0 | 1 |
446 | z | z + 1 |
447 | nan | nan |
449 1 "#+TBLFM: $2 = if(\"$1\" = \"nan\", string(\"\"), $1 + 1); E"))
451 (ert-deftest test-org-table/empty-field ()
452 "Examples how to deal with empty fields."
453 ;; Empty fields in simple and complex range reference: Suppress them
454 ;; ($5 and $6) or keep them and use 0 ($7 and $8)
456 ;; Calc formula
457 (org-test-table-target-expect
458 "\n| | | 5 | 7 | replace | replace | replace | replace |\n"
459 "\n| | | 5 | 7 | 6 | 6 | 3 | 3 |\n"
461 (concat "#+TBLFM: "
462 "$5 = vmean($1..$4) :: $6 = vmean(@0$1..@0$4) :: "
463 "$7 = vmean($1..$4); EN :: $8 = vmean(@0$1..@0$4); EN"))
465 ;; Lisp formula
466 ;; TODO: Len for simple range reference with empty field should also
467 ;; be 6
468 (org-test-table-target-expect
469 "\n| | | 5 | 7 | replace | replace | replace | replace |\n"
470 "\n| | | 5 | 7 | 3 | 6 | 3 | 3 |\n"
472 (concat "#+TBLFM: "
473 "$5 = '(/ (+ $1..$4 ) (length '( $1..$4 ))); N :: "
474 "$6 = '(/ (+ @0$1..@0$4) (length '(@0$1..@0$4))); N :: "
475 "$7 = '(/ (+ $1..$4 ) (length '( $1..$4 ))); EN :: "
476 "$8 = '(/ (+ @0$1..@0$4) (length '(@0$1..@0$4))); EN")))
478 ;; End of table examples and beginning of internal tests.
480 (ert-deftest test-org-table/org-table-make-reference/format-specifier-EL ()
481 (fset 'f 'org-table-make-reference)
482 ;; For Lisp formula only
483 (should (equal "0" (f "0" t nil 'literal)))
484 (should (equal "z" (f "z" t nil 'literal)))
485 (should (equal "" (f "" t nil 'literal)))
486 (should (equal "0 1" (f '("0" "1") t nil 'literal)))
487 (should (equal "z 1" (f '("z" "1") t nil 'literal)))
488 (should (equal " 1" (f '("" "1") t nil 'literal)))
489 (should (equal " " (f '("" "" ) t nil 'literal))))
491 (ert-deftest test-org-table/org-table-make-reference/format-specifier-E ()
492 (fset 'f 'org-table-make-reference)
493 ;; For Lisp formula
494 (should (equal "\"0\"" (f "0" t nil t)))
495 (should (equal "\"z\"" (f "z" t nil t)))
496 (should (equal "\"\"" (f "" t nil t)))
497 (should (equal "\"0\" \"1\"" (f '("0" "1") t nil t)))
498 (should (equal "\"z\" \"1\"" (f '("z" "1") t nil t)))
499 (should (equal "\"\" \"1\"" (f '("" "1") t nil t)))
500 (should (equal "\"\" \"\"" (f '("" "" ) t nil t)))
501 ;; For Calc formula
502 (should (equal "(0)" (f "0" t nil nil)))
503 (should (equal "(z)" (f "z" t nil nil)))
504 (should (equal "(0)" (f "" t nil nil)))
505 (should (equal "[0,1]" (f '("0" "1") t nil nil)))
506 (should (equal "[z,1]" (f '("z" "1") t nil nil)))
507 (should (equal "[,1]" (f '("" "1") t nil nil)))
508 (should (equal "[,]" (f '("" "" ) t nil nil)))
509 ;; For Calc formula, special numbers
510 (should (equal "(nan)" (f "nan" t nil nil)))
511 (should (equal "(uinf)" (f "uinf" t nil nil)))
512 (should (equal "(-inf)" (f "-inf" t nil nil)))
513 (should (equal "(inf)" (f "inf" t nil nil)))
514 (should (equal "[nan,1]" (f '( "nan" "1") t nil nil)))
515 (should (equal "[uinf,1]" (f '("uinf" "1") t nil nil)))
516 (should (equal "[-inf,1]" (f '("-inf" "1") t nil nil)))
517 (should (equal "[inf,1]" (f '( "inf" "1") t nil nil))))
519 (ert-deftest test-org-table/org-table-make-reference/format-specifier-EN ()
520 (fset 'f 'org-table-make-reference)
521 ;; For Lisp formula
522 (should (equal "0" (f "0" t t t)))
523 (should (equal "0" (f "z" t t t)))
524 (should (equal "0" (f "" t t t)))
525 (should (equal "0 1" (f '("0" "1") t t t)))
526 (should (equal "0 1" (f '("z" "1") t t t)))
527 (should (equal "0 1" (f '("" "1") t t t)))
528 (should (equal "0 0" (f '("" "" ) t t t)))
529 ;; For Calc formula
530 (should (equal "(0)" (f "0" t t nil)))
531 (should (equal "(0)" (f "z" t t nil)))
532 (should (equal "(0)" (f "" t t nil)))
533 (should (equal "[0,1]" (f '("0" "1") t t nil)))
534 (should (equal "[0,1]" (f '("z" "1") t t nil)))
535 (should (equal "[0,1]" (f '("" "1") t t nil)))
536 (should (equal "[0,0]" (f '("" "" ) t t nil)))
537 ;; For Calc formula, special numbers
538 (should (equal "(0)" (f "nan" t t nil)))
539 (should (equal "(0)" (f "uinf" t t nil)))
540 (should (equal "(0)" (f "-inf" t t nil)))
541 (should (equal "(0)" (f "inf" t t nil)))
542 (should (equal "[0,1]" (f '( "nan" "1") t t nil)))
543 (should (equal "[0,1]" (f '("uinf" "1") t t nil)))
544 (should (equal "[0,1]" (f '("-inf" "1") t t nil)))
545 (should (equal "[0,1]" (f '( "inf" "1") t t nil))))
547 (ert-deftest test-org-table/org-table-make-reference/format-specifier-L ()
548 (fset 'f 'org-table-make-reference)
549 ;; For Lisp formula only
550 (should (equal "0" (f "0" nil nil 'literal)))
551 (should (equal "z" (f "z" nil nil 'literal)))
552 (should (equal "" (f "" nil nil 'literal)))
553 (should (equal "0 1" (f '("0" "1") nil nil 'literal)))
554 (should (equal "z 1" (f '("z" "1") nil nil 'literal)))
555 (should (equal "1" (f '("" "1") nil nil 'literal)))
556 ;; TODO: Should result in empty string like with field reference of
557 ;; empty field.
558 (should (equal "0" (f '("" "" ) nil nil 'literal))))
560 (ert-deftest test-org-table/org-table-make-reference/format-specifier-none ()
561 (fset 'f 'org-table-make-reference)
562 ;; For Lisp formula
563 (should (equal "\"0\"" (f "0" nil nil t)))
564 (should (equal "\"z\"" (f "z" nil nil t)))
565 (should (equal "\"\"" (f "" nil nil t)))
566 (should (equal "\"0\" \"1\"" (f '("0" "1") nil nil t)))
567 (should (equal "\"z\" \"1\"" (f '("z" "1") nil nil t)))
568 (should (equal "\"1\"" (f '("" "1") nil nil t)))
569 ;; TODO: Should result in empty string like with field reference of
570 ;; empty field.
571 (should (equal "\"0\"" (f '("" "" ) nil nil t)))
572 ;; For Calc formula
573 (should (equal "(0)" (f "0" nil nil nil)))
574 (should (equal "(z)" (f "z" nil nil nil)))
575 (should (equal "(0)" (f "" nil nil nil)))
576 (should (equal "[0,1]" (f '("0" "1") nil nil nil)))
577 (should (equal "[z,1]" (f '("z" "1") nil nil nil)))
578 (should (equal "[1]" (f '("" "1") nil nil nil)))
579 (should (equal "[0]" (f '("" "" ) nil nil nil)))
580 ;; For Calc formula, special numbers
581 (should (equal "(nan)" (f "nan" nil nil nil)))
582 (should (equal "(uinf)" (f "uinf" nil nil nil)))
583 (should (equal "(-inf)" (f "-inf" nil nil nil)))
584 (should (equal "(inf)" (f "inf" nil nil nil)))
585 (should (equal "[nan,1]" (f '( "nan" "1") nil nil nil)))
586 (should (equal "[uinf,1]" (f '("uinf" "1") nil nil nil)))
587 (should (equal "[-inf,1]" (f '("-inf" "1") nil nil nil)))
588 (should (equal "[inf,1]" (f '( "inf" "1") nil nil nil))))
590 (ert-deftest test-org-table/org-table-make-reference/format-specifier-N ()
591 (fset 'f 'org-table-make-reference)
592 ;; For Lisp formula
593 (should (equal "0" (f "0" nil t t)))
594 (should (equal "0" (f "z" nil t t)))
595 (should (equal "0" (f "" nil t t)))
596 (should (equal "0 1" (f '("0" "1") nil t t)))
597 (should (equal "0 1" (f '("z" "1") nil t t)))
598 (should (equal "1" (f '("" "1") nil t t)))
599 (should (equal "0" (f '("" "" ) nil t t)))
600 ;; For Calc formula
601 (should (equal "(0)" (f "0" nil t nil)))
602 (should (equal "(0)" (f "z" nil t nil)))
603 (should (equal "(0)" (f "" nil t nil)))
604 (should (equal "[0,1]" (f '("0" "1") nil t nil)))
605 (should (equal "[0,1]" (f '("z" "1") nil t nil)))
606 (should (equal "[1]" (f '("" "1") nil t nil)))
607 (should (equal "[0]" (f '("" "" ) nil t nil)))
608 ;; For Calc formula, special numbers
609 (should (equal "(0)" (f "nan" nil t nil)))
610 (should (equal "(0)" (f "uinf" nil t nil)))
611 (should (equal "(0)" (f "-inf" nil t nil)))
612 (should (equal "(0)" (f "inf" nil t nil)))
613 (should (equal "[0,1]" (f '( "nan" "1") nil t nil)))
614 (should (equal "[0,1]" (f '("uinf" "1") nil t nil)))
615 (should (equal "[0,1]" (f '("-inf" "1") nil t nil)))
616 (should (equal "[0,1]" (f '( "inf" "1") nil t nil))))
618 (ert-deftest test-org-table/org-table-convert-refs-to-an/1 ()
619 "Simple reference @1$1."
620 (should
621 (string= "A1" (org-table-convert-refs-to-an "@1$1"))))
623 ;; TODO: Test broken
624 ;; (ert-deftest test-org-table/org-table-convert-refs-to-an/2 ()
625 ;; "Self reference @1$1."
626 ;; (should
627 ;; (string= "A1 = $0" (org-table-convert-refs-to-an "@1$1 = $0"))))
629 (ert-deftest test-org-table/org-table-convert-refs-to-an/3 ()
630 "Remote reference."
631 (should
632 (string= "C& = remote(FOO, @@#B&)" (org-table-convert-refs-to-an "$3 = remote(FOO, @@#$2)"))))
634 (ert-deftest test-org-table/org-table-convert-refs-to-rc/1 ()
635 "Simple reference @1$1."
636 (should
637 (string= "@1$1" (org-table-convert-refs-to-rc "A1"))))
639 (ert-deftest test-org-table/org-table-convert-refs-to-rc/2 ()
640 "Self reference $0."
641 (should
642 (string= "@1$1 = $0" (org-table-convert-refs-to-rc "A1 = $0"))))
644 ;; TODO: Test Broken
645 ;; (ert-deftest test-org-table/org-table-convert-refs-to-rc/3 ()
646 ;; "Remote reference."
647 ;; (should
648 ;; (string= "$3 = remote(FOO, @@#$2)" (org-table-convert-refs-to-rc "C& = remote(FOO, @@#B&)"))))
650 (provide 'test-org-table)
652 ;;; test-org-table.el ends here