* lisp/imenu.el (imenu-generic-skip-comments-and-strings):
[emacs.git] / lisp / emacs-lisp / tcover-ses.el
blob02023b957a5b0cc835a5427316dab8036f1e8824
1 ;;;; testcover-ses.el -- Example use of `testcover' to test "SES"
3 ;; Copyright (C) 2002-2013 Free Software Foundation, Inc.
5 ;; Author: Jonathan Yavner <jyavner@engineer.com>
6 ;; Maintainer: Jonathan Yavner <jyavner@engineer.com>
7 ;; Keywords: spreadsheet lisp utility
8 ;; Package: testcover
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 (require 'testcover)
25 (defvar ses-initial-global-parameters)
26 (defvar ses-mode-map)
28 (declare-function ses-set-curcell "ses")
29 (declare-function ses-update-cells "ses")
30 (declare-function ses-load "ses")
31 (declare-function ses-vector-delete "ses")
32 (declare-function ses-create-header-string "ses")
33 (declare-function ses-read-cell "ses")
34 (declare-function ses-read-symbol "ses")
35 (declare-function ses-command-hook "ses")
36 (declare-function ses-jump "ses")
39 ;;;Here are some macros that exercise SES. Set `pause' to t if you want the
40 ;;;macros to pause after each step.
41 (let* ((pause nil)
42 (x (if pause "\x18q" ""))
43 (y "\x18\x06ses-test.ses\r\e<"))
44 ;;Fiddle with the existing spreadsheet
45 (fset 'ses-exercise-example
46 (concat "\x18\x06" data-directory "ses-example.ses\r\e<"
47 x "\x1510\x0e"
48 x "\v"
49 x "\x1f"
50 x "\x10\x10\x06pses-center\r"
51 x "\x06p\r"
52 x "\x15\x10\t\t"
53 x "\r\x02 A9 B9\r"
54 x "\x15\x0e\x02\x02\x02"
55 x "\r\x01\v2\r"
56 x "\x0e\x0e\x06"
57 x "50\r"
58 x "\x154\x1f"
59 x "\x03\e\f"
60 x "\x1f"
61 x "(+ \x18o\x0e\x0e\x06\0\x06\x06"
62 x "\x15-1\x18o\x03\x12 \x03\x13\r\x02"
63 x "\x1f"
64 x))
65 ;;Create a new spreadsheet
66 (fset 'ses-exercise-new
67 (concat y
68 x "\x03\x10\"%.8g\"\r"
69 x "2\r"
70 x "\x0f"
71 x "\x10"
72 x "\x152\x0f"
73 x "\"Header\r"
74 x "(sqrt 1\r\x02"
75 x "pses-center\r\x06"
76 x "\t"
77 x "\x10(+ A2 A3\r"
78 x "\x06(* B2 A3\r"
79 x "\x152\x03\e\b"
80 x "\r\x7f\x7f\x7fB3\r"
81 x "\x18\x13"
82 x))
83 ;;Basic cell display
84 (fset 'ses-exercise-display
85 (concat y "\e:(revert-buffer t t)\r"
86 x "\x05"
87 x "\"Very long\r\x02"
88 x "w3\r"
89 x "w3\r"
90 x "(/ 1 0\r\x02"
91 x "234567\r\x02"
92 x "\x155w"
93 x "\t1\r\x02"
94 x "\x02\x03\x03"
95 x "\x06234567\r\x02"
96 x "\t\x04\x02"
97 x "\x02\x03\x03"
98 x "345678\r\x02"
99 x "\x153w"
100 x "\0\e>"
101 x "\x03\x03"
102 x "\x18\x18"
103 x "\x05"
104 x "\x18\x18\x01"
105 x "\x05"
106 x "\x06\x05"
107 x "\x03\x03"
108 x "1\r\x02"
109 x "\x03\x03\x06"
110 x "\x05"
111 x "\x02\x02\x02\"1234567-1234567-1234567\r\x02"
112 x "123\r\x02"
113 x "\x152\x0f"
114 x "\x0e\"1234567-1234567-1234567\r\x02"
115 x "123\r\x02"
116 x "\x06\x06w8\r"
117 x "\x02\x02\"1234567\r"
118 x "\x0e\x02w5\r"
120 ;;Cell formulas
121 (fset 'ses-exercise-formulas
122 (concat y "\e:(revert-buffer t t)\r"
123 x "\t\t"
124 x "\t"
125 x "(* B1 B2 D1\r\x02"
126 x "(* B2 B3\r\x02"
127 x "\x0e(apply '+ (ses-range B1 B3)\r\x02"
128 x "(apply 'ses+ (ses-range B1 B3)\r\x02"
129 x "\x0e(apply 'ses+ (ses-range A2 A3)\r\x02"
130 x "\x0e(mapconcat'number-to-string(ses-range B2 B4) \"-\"\r\x02"
131 x "\x02(apply 'concat (reverse (ses-range A3 D3))\r\x02"
132 x "\x02(* (+ A2 A3) (ses+ B2 B3)\r\x02"
133 x "\x0e"
134 x "\x152\x0f"
135 x "\x155\t"
136 x "\x10(apply 'ses+ (ses-range E1 E2)\r\x02"
137 x "\x10(apply 'ses+ (ses-range A5 B5)\r\x02"
138 x "\x10(apply 'ses+ (ses-range E1 F1)\r\x02"
139 x "\x10(apply 'ses+ (ses-range D1 E1)\r\x02"
140 x "\t"
141 x "(ses-average (ses-range A2 A5)\r\x02"
142 x "\x0e(apply 'ses+ (ses-range A5 A6)\r\x02"
143 x "\x02\x02\ek"
144 x "\x0e\x0e\v"
145 x "\x10\x10\x10\x0f"
146 x "\x0e\x152\x0f"
147 x "\x10\x153\v"
148 x "\x02\x02\x02\eo"
149 x "\x06\x152\eo"
150 x "\x02\x153\ek"
151 x "\x06(ses-average (ses-range B3 E3)\r\x02"
152 x "\x02\ek"
153 x "\x0e\x1012345678\r\x02"
155 ;;Recalculating and reconstructing
156 (fset 'ses-exercise-recalc
157 (concat y "\e:(revert-buffer t t)\r"
158 x "\x03\e\f"
159 x "\t\t"
160 x "\x03\x03"
161 x "(/ 1 0\r\x02"
162 x "\x03\x03"
163 x "\n"
164 x "\x03\x03"
165 x "\x03\x10\"%.6g\"\r"
166 x "\x03\e\f"
167 x "\e>\x18nw\x06\x06\x06"
168 x "\0\e>\exdelete-region\r"
169 x "\x03\e\f"
170 x "\x158\x0e"
171 x "\0\e>\exdelete-region\r"
172 x "\x03\e\f"
173 x "\x03\x0e"
174 x "\x0e\v\x02\ek"
175 x "\x03\f"
176 x "\x02\"Very long\r"
177 x "\x10\x03\x14"
178 x "\x02\r\r"
179 x "\x0e\x03\x14"
180 x "\x06\eo"
181 x "\x06\x03\x14"
182 x "\x02\x02\"Very long2\r"
183 x "\x02\eo\x06"
184 x "\x03\x14"
185 x "\r\x7f\x7f\x7fC3\r"
186 x "\x0e\r\x7f\x7f\x7fC2\r"
187 x "\x10\0\x0e\x06\x03\x03"
188 x "\r\x7f\x7fC4\r"
189 x "\x0e\x0e\r\x7f\x7f\x7fC2\r"
190 x "\x06\0\x02\x10\x10"
191 x "\x03\x03"
192 x "\exses-mode\r"
193 x "\e<\x0f"
194 x "\x152\ek"
196 ;;Header line
197 (fset 'ses-exercise-header-row
198 (concat y "\e:(revert-buffer t t)\r"
199 x "\x18<"
200 x "\x18>"
201 x "\x156\x18<"
202 x "\x18>"
203 x "\x157\x18<"
204 x "\x18>"
205 x "\x158\x18<"
206 x "\x152\x18<"
207 x "\x18>"
208 x "\x06\x153w\x02"
209 x "\x1510\x18<"
210 x "\x18>"
211 x "\x152\v"
213 ;;Detecting unsafe formulas and printers
214 (fset 'ses-exercise-unsafe
215 (concat y "\e:(revert-buffer t t)\r"
216 x "p(lambda (x) (delete-file x))\rn"
217 x "p(lambda (x) (delete-file \"ses-nothing\"))\ry"
218 x "\0\x06\x17\x19n"
219 x "\x0e(delete-file \"x\"\rn"
220 x "(delete-file \"ses-nothing\"\ry\x02"
221 x "\0\x06\x17\x19n"
222 x "(open-network-stream \"x\" nil \"localhost\" \"smtp\"\ry\x02"
223 x "\0\x06\x17\x19n"
225 ;;Inserting and deleting rows
226 (fset 'ses-exercise-rows
227 (concat y "\e:(revert-buffer t t)\r"
228 x "\x0e\x06"
229 x "\x03\x10\"%s=\"\r"
230 x "\x1520\x0f"
231 x "\ep\"%s+\"\r"
232 x "\x0e\x0f"
233 x "123456789\r\x02"
234 x "\0\x1521\x0e\x06"
235 x "\x03\x03"
236 x "\e\f"
237 x "\x10\x10(not B25\r\x02"
238 x "\x0e\ek"
239 x "jA3\r"
240 x "\x1519\v"
241 x "\x10\x06\v"
242 x "\x15100\x0f" ;Make this approx your CPU speed in MHz
244 ;;Inserting and deleting columns
245 (fset 'ses-exercise-columns
246 (concat y "\e:(revert-buffer t t)\r"
247 x "\x03\x10\"%s@\"\r"
248 x "\eo"
249 x "\x0f"
250 x "\eo"
251 x "\v"
252 x "\ek"
253 x "w8\r"
254 x "\ep\"%.7s*\"\r"
255 x "\eo"
256 x "\x06"
257 x "\x152\eo"
258 x "\x153\ek"
259 x "\x03\x10\"%.6g\"\r"
260 x "\x1526\eo"
261 x "\0\x1526\t"
262 x "\x1526\eo"
263 x "\x03\e\b0\r"
264 x "\x1526\t"
265 x "\x15400\x02"
266 x "\x1550\ek"
267 x "\0\x0e\x0e\x06\x06\x03\e\x13D"
269 (fset 'ses-exercise-editing
270 (concat y "\e:(revert-buffer t t)\r"
271 x "\x0e\x0e\x0e1\r\x02"
272 x "\x06(\x02'\x06x\r\x02"
273 x "\x02\x10\x10\x10\x0f"
274 x "\x1f"
275 x "\r\r"
276 x "w9\r"
277 x "\x0e\r\x02.5\r"
278 x "\x0e\x06\r\x02 10\r"
279 x "w12\r"
280 x "\r\x01'\r"
281 x "\r\x01\x04\r"
282 x "jA4\r"
283 x "(+ A2 100\r\x02"
284 x "\x10\x103\r\x02"
285 x "jB1\r"
286 x "(not A1\r\x02"
287 x "\x02\"Very long\r\x02"
288 x "\x03\x03"
289 x "\eh"
290 x "\eH"
291 x "\x03\x03"
292 x "\e>\t"
293 x "\x10\x10\x04"
294 x "\x10\x04"
295 x "\x06\x06\x152\x7f"
296 x "\x10\x7f"
297 x "\eo"
298 x "\eh"
299 x "\0\x0f\x06"
300 x "\"Also very long\r\x02"
301 x "\x0e\x06\eH"
302 x "\0'\r\x02"
303 x "'Trial\r\x02"
304 x "\x0e\x02'qwerty\r\x02"
305 x "\x06(concat \x18o\e<\0\x0e\x0e"
306 x "\x15-1\x18o\x03\x12\r\x02"
307 x "(apply '+ \x18o\e<\0\x0e\x06\x15-1\x18o\x03\x13\r\x02"
308 x "\x10\x152\x7f"
309 x "\x15-2\x7f"
310 x "\x15-2\x04"
311 x "\x152\x04"
312 x "\x02\x10\x10\v"
313 x "\x0e\x06\eH"
314 x "\x02\x10\0\x0f"
315 x "\"Another long one\r\x02"
316 x "\x0e\x0e\x06\eH"
317 x "\x01\x10\x05"
318 x "\x03\x03\e<"
319 x "\x0e\x05"
320 x "\e>\x10\x0f"
321 x "\0\x05\x06\x05"
323 ;;Sorting of columns
324 (fset 'ses-exercise-sort-column
325 (concat y "\e:(revert-buffer t t)\r"
326 x "\"Very long\r"
327 x "\x0699\r"
328 x "\x06\eo13\r"
329 x "(+ A3 B3\r"
330 x "7\r8\r(* A4 B4\r"
331 x "\0\x10\x10\x10\x03\e\x13A\r"
332 x "\x0e\0\x10\x10\x10\x03\e\x13B\r"
333 x "\x10\x10\x06\0\x0e\x0e\x06\x06\x03\e\x13C\r"
334 x "\x06\eo\x10\x0f"
335 x "\x02\0\x0e\x0e\x0e\x15\x03\e\x13C\r"
337 ;;Simple cell printers
338 (fset 'ses-exercise-cell-printers
339 (concat y "\e:(revert-buffer t t)\r"
340 x "\x06\"4\x11\t76\r\x02"
341 x "\"4\x11\n7\r\x02"
342 x "p\"{%S}\"\r"
343 x "p(\"[%s]\")\r"
344 x "p(\"<%s>\")\r"
345 x "\x02\0\x06\x06"
346 x "p\r"
347 x "pnil\r"
348 x "pses-dashfill\r"
349 x "48\r\x02"
350 x "\t"
351 x "\x02\0\x06p\r"
352 x "\x06p\r"
353 x "pses-dashfill\r"
354 x "\x02\0\x06\x06pnil\r"
355 x "5\r\x02"
356 x "pses-center\r"
357 x "\x03\x10\"%s\"\r"
358 x "w8\r"
359 x "\ep\r"
360 x "\ep\"%.7g@\"\r"
361 x "\x03\x10\r"
362 x "\x03\x10\"%.6g#\"\r"
363 x "\x03\x10\"%.6g.\"\r"
364 x "\x03\x10\"%.6g.\"\r"
365 x "\epidentity\r"
366 x "6\r\x02"
367 x "\x0e\"UPCASE\r\x02"
368 x "\epdowncase\r"
369 x "(* 3 4\r\x02"
370 x "p(lambda\x11 (x)\x11 '(\"Hi\"))\r"
371 x "p(lambda\x11 (x)\x11 '(\"Bye\"))\r"
373 ;;Spanning cell printers
374 (fset 'ses-exercise-spanning-printers
375 (concat y "\e:(revert-buffer t t)\r"
376 x "\ep\"%.6g*\"\r"
377 x "pses-dashfill-span\r"
378 x "5\r\x02"
379 x "pses-tildefill-span\r"
380 x "\"4\r\x02"
381 x "\ep\"$%s\"\r"
382 x "\ep(\"$%s\")\r"
383 x "8\r\x02"
384 x "\ep(\"!%s!\")\r"
385 x "\t\"12345678\r\x02"
386 x "pses-dashfill-span\r"
387 x "\"23456789\r\x02"
388 x "\t"
389 x "(not t\r\x02"
390 x "\x02w6\r"
391 x "\"5\r\x02"
392 x "\x0e\x06\eo"
393 x "\ek"
394 x "\ek"
395 x "\t"
396 x "\x02\x10\x03\x03"
397 x "\eo"
398 x "\x0e\x152\ek"
399 x "\x02\x02\ek"
401 ;;Cut/copy/paste - within same buffer
402 (fset 'ses-exercise-paste-1buf
403 (concat y "\e:(revert-buffer t t)\r"
404 x "\x0e\0\x06\ew"
405 x "\x03\x03\x10\x06\x19"
406 x "\x0e\eo"
407 x "\"middle\r\x02"
408 x "\0\x06\x0e\x06"
409 x "\ew"
410 x "\x10\0\x06"
411 x "\ew"
412 x "\x03\x03\x06\x0e"
413 x "\x19"
414 x "\x152\x19y"
415 x "\x06\x15\x19y"
416 x "\x10\x10\x06\x15\x19y"
417 x "\e>"
418 x "\x19y"
419 x "\e>\x19y"
420 x "\e<"
421 x "p\"<%s>\"\r"
422 x "\x06pses-dashfill\r"
423 x "\x02\0\x06\x06\x06\x0e\x0e\x0e"
424 x "\x17"
425 x "\x1f"
426 x "\x15\x19y"
427 x "\r\0\x02\x02\x02\ew"
428 x "\r\x06\x19"
429 x "\x153\x10(+ G2 H1\r"
430 x "\0\x02\ew"
431 x "\x03\x03\e>\x02"
432 x "\x19"
433 x "\x02\x158\x10(ses-average (ses-range G2 H2)\r\x02"
434 x "\0\x06\x17\ek"
435 x "\x157\x0e"
436 x "\x19"
437 x "\x10\x02(ses-average (ses-range E7 E9)\r\x02"
438 x "\0\x06\x17\v"
439 x "\x0e\x19"
440 x "\x02\x02\x10(ses-average (ses-range E7 F7)\r\x02"
441 x "\0\x06\x17\ek"
442 x "\x06\x19"
443 x "\x02\x02\x10(ses-average (ses-range D6 E6)\r\x02"
444 x "\0\x06\x17\ek"
445 x "\x06\x19"
446 x "\x01\x152\x0f"
447 x "\"Line A\r\x02"
448 x "pses-tildefill-span\r"
449 x "\x0e\x06\"Subline A(1)\r\x02"
450 x "pses-dashfill-span\r"
451 x "\x02\x10\0\x0e\x0e\x0e\ew\x03\x03"
452 x "\x01\x10\x10\x10\x10\x10\x10"
453 x "\x19"
454 x "\0\x0e\x06\x06\ew\x03\x03"
455 x "\x06\x19"
457 ;;Cut/copy/paste - between two buffers
458 (fset 'ses-exercise-paste-2buf
459 (concat y "\e:(revert-buffer t t)\r"
460 x "\x06\x0e\eo\"middle\r\x02\0\x06\x0e\x06"
461 x "\x17"
462 x "\x184bses-test.txt\r"
463 x " \x01\x19"
464 x "\x05\"xxx\0\x02\x02\x02\x02"
465 x "\ew\x18o"
466 x "\x1f"
467 x "\x19"
468 x "\x18o\x05\"\0\x02\x02\x02\x02\x02"
469 x "\ew\x18o\x19"
470 x "\x18o123.45\0\x02\x02\x02\x02\x02\x02"
471 x "\x17\x18o\x19"
472 x "\x18o1 \x02\x02\0\x06\x06\x06\x06\x06\x06\x06"
473 x "\x17\x18o\x19"
474 x "\e>\x19y"
475 x "\x06\x18o symb\0\x02\x02\x02\x02"
476 x "\x17\x18o\x15\x19\ey\x152\ey"
477 x "\x18o1\t\0\x02\x02"
478 x "\x17\x18o\x02\x19"
479 x "w9\n\ep\"<%s>\"\n"
480 x "\x18o\n2\t\"3\nxxx\t5\n\0\x10\x10"
481 x "\x17\x18o\x19y"
483 ;;Export text, import it back
484 (fset 'ses-exercise-import-export
485 (concat y "\e:(revert-buffer t t)\r"
486 x "\x0e\x0e\x06\0\x06xt"
487 x "\x184bses-test.txt\r"
488 x "\n\x19\x15-1\x18o"
489 x "xT\x18o\x19\x15-1\x18o"
490 x "\x03\x03\x06'crunch\r\x02"
491 x "\x10\x10\x10pses-center-span\r"
492 x "\0\x0e\x0e\x0e\x0exT"
493 x "\x18o\n\x19\x15-1\x18o"
494 x "\0\x19y"
495 x "\x06\0\x02\x10\x10xt"
496 x "\x0e\x0e\0\x15\x19y"
497 x "12345678\r\x02"
498 x "\x06\x06'bunch\r"
499 x "\0\x10\x10xtxT"
500 x)))
502 (defun ses-exercise-macros ()
503 "Executes all SES coverage-test macros."
504 (dolist (x '(ses-exercise-example
505 ses-exercise-new
506 ses-exercise-display
507 ses-exercise-formulas
508 ses-exercise-recalc
509 ses-exercise-header-row
510 ses-exercise-unsafe
511 ses-exercise-rows
512 ses-exercise-columns
513 ses-exercise-editing
514 ses-exercise-sort-column
515 ses-exercise-cell-printers
516 ses-exercise-spanning-printers
517 ses-exercise-paste-1buf
518 ses-exercise-paste-2buf
519 ses-exercise-import-export))
520 (message "<Testing %s>" x)
521 (execute-kbd-macro x)))
523 (defun ses-exercise-signals ()
524 "Exercise code paths that lead to error signals, other than those for
525 spreadsheet files with invalid formatting."
526 (message "<Checking for expected errors>")
527 (switch-to-buffer "ses-test.ses")
528 (deactivate-mark)
529 (ses-jump 'A1)
530 (ses-set-curcell)
531 (dolist (x '((ses-column-widths 14)
532 (ses-column-printers "%s")
533 (ses-column-printers ["%s" "%s" "%s"]) ;Should be two
534 (ses-column-widths [14])
535 (ses-delete-column -99)
536 (ses-delete-column 2)
537 (ses-delete-row -1)
538 (ses-goto-data 'hogwash)
539 (ses-header-row -56)
540 (ses-header-row 99)
541 (ses-insert-column -14)
542 (ses-insert-row 0)
543 (ses-jump 'B8) ;Covered by preceding cell
544 (ses-printer-validate '("%s" t))
545 (ses-printer-validate '([47]))
546 (ses-read-header-row -1)
547 (ses-read-header-row 32767)
548 (ses-relocate-all 0 0 -1 1)
549 (ses-relocate-all 0 0 1 -1)
550 (ses-select (ses-range A1 A2) 'x (ses-range B1 B1))
551 (ses-set-cell 0 0 'hogwash nil)
552 (ses-set-column-width 0 0)
553 (ses-yank-cells #("a\nb"
554 0 1 (ses (A1 nil nil))
555 2 3 (ses (A3 nil nil)))
556 nil)
557 (ses-yank-cells #("ab"
558 0 1 (ses (A1 nil nil))
559 1 2 (ses (A2 nil nil)))
560 nil)
561 (ses-yank-pop nil)
562 (ses-yank-tsf "1\t2\n3" nil)
563 (let ((curcell nil)) (ses-check-curcell))
564 (let ((curcell 'A1)) (ses-check-curcell 'needrange))
565 (let ((curcell '(A1 . A2))) (ses-check-curcell 'end))
566 (let ((curcell '(A1 . A2))) (ses-sort-column "B"))
567 (let ((curcell '(C1 . D2))) (ses-sort-column "B"))
568 (execute-kbd-macro "jB10\n\x152\x04")
569 (execute-kbd-macro [?j ?B ?9 ?\n ?\C-@ ?\C-f ?\C-f cut])
570 (progn (kill-new "x") (execute-kbd-macro "\e>\x19n"))
571 (execute-kbd-macro "\x02\0\ew")))
572 (condition-case nil
573 (progn
574 (eval x)
575 (signal 'singularity-error nil)) ;Shouldn't get here
576 (singularity-error (error "No error from %s?" x))
577 (error nil)))
578 ;;Test quit-handling in ses-update-cells. Cant' use `eval' here.
579 (let ((inhibit-quit t))
580 (setq quit-flag t)
581 (condition-case nil
582 (progn
583 (ses-update-cells '(A1))
584 (signal 'singularity-error nil))
585 (singularity-error (error "Quit failure in ses-update-cells"))
586 (error nil))
587 (setq quit-flag nil)))
589 (defun ses-exercise-invalid-spreadsheets ()
590 "Execute code paths that detect invalid spreadsheet files."
591 ;;Detect invalid spreadsheets
592 (let ((p&d "\n\n\f\n(ses-cell A1 nil nil nil nil)\n\n")
593 (cw "(ses-column-widths [7])\n")
594 (cp "(ses-column-printers [ses-center])\n")
595 (dp "(ses-default-printer \"%.7g\")\n")
596 (hr "(ses-header-row 0)\n")
597 (p11 "(2 1 1)")
598 (igp ses-initial-global-parameters))
599 (dolist (x (list "(1)"
600 "(x 2 3)"
601 "(1 x 3)"
602 "(1 -1 0)"
603 "(1 2 x)"
604 "(1 2 -1)"
605 "(3 1 1)"
606 "\n\n\f(2 1 1)"
607 "\n\n\f\n(ses-cell)(2 1 1)"
608 "\n\n\f\n(x)\n(2 1 1)"
609 "\n\n\n\f\n(ses-cell A2)\n(2 2 2)"
610 "\n\n\n\f\n(ses-cell B1)\n(2 2 2)"
611 "\n\n\f\n(ses-cell A1 nil nil nil nil)\n(2 1 1)"
612 (concat p&d "(x)\n(x)\n(x)\n(x)\n" p11)
613 (concat p&d "(ses-column-widths)(x)\n(x)\n(x)\n" p11)
614 (concat p&d cw "(x)\n(x)\n(x)\n(2 1 1)")
615 (concat p&d cw "(ses-column-printers)(x)\n(x)\n" p11)
616 (concat p&d cw cp "(x)\n(x)\n" p11)
617 (concat p&d cw cp "(ses-default-printer)(x)\n" p11)
618 (concat p&d cw cp dp "(x)\n" p11)
619 (concat p&d cw cp dp "(ses-header-row)" p11)
620 (concat p&d cw cp dp hr p11)
621 (concat p&d cw cp dp "\n" hr igp)))
622 (condition-case nil
623 (with-temp-buffer
624 (insert x)
625 (ses-load)
626 (signal 'singularity-error nil)) ;Shouldn't get here
627 (singularity-error (error "%S is an invalid spreadsheet!" x))
628 (error nil)))))
630 (defun ses-exercise-startup ()
631 "Prepare for coverage tests"
632 ;;Clean up from any previous runs
633 (condition-case nil (kill-buffer "ses-example.ses") (error nil))
634 (condition-case nil (kill-buffer "ses-test.ses") (error nil))
635 (condition-case nil (delete-file "ses-test.ses") (file-error nil))
636 (delete-other-windows) ;Needed for "\C-xo" in ses-exercise-editing
637 (setq ses-mode-map nil) ;Force rebuild
638 (testcover-unmark-all "ses.el")
639 ;;Enable
640 (let ((testcover-1value-functions
641 ;;forward-line always returns 0, for us.
642 ;;remove-text-properties always returns t for us.
643 ;;ses-recalculate-cell returns the same " " any time curcell is a cons
644 ;;Macros ses-dorange and ses-dotimes-msg generate code that always
645 ;; returns nil
646 (append '(forward-line remove-text-properties ses-recalculate-cell
647 ses-dorange ses-dotimes-msg)
648 testcover-1value-functions))
649 (testcover-constants
650 ;;These maps get initialized, then never changed again
651 (append '(ses-mode-map ses-mode-print-map ses-mode-edit-map)
652 testcover-constants)))
653 (testcover-start "ses.el" t))
654 (require 'unsafep)) ;In case user has safe-functions = t!
657 ;;;#########################################################################
658 (defun ses-exercise ()
659 "Executes all SES coverage tests and displays the results."
660 (interactive)
661 (ses-exercise-startup)
662 ;;Run the keyboard-macro tests
663 (let ((safe-functions nil)
664 (ses-initial-size '(1 . 1))
665 (ses-initial-column-width 7)
666 (ses-initial-default-printer "%.7g")
667 (ses-after-entry-functions '(forward-char))
668 (ses-mode-hook nil))
669 (ses-exercise-macros)
670 (ses-exercise-signals)
671 (ses-exercise-invalid-spreadsheets)
672 ;;Upgrade of old-style spreadsheet
673 (with-temp-buffer
674 (insert " \n\n\f\n(ses-cell A1 nil nil nil nil)\n\n(ses-column-widths [7])\n(ses-column-printers [nil])\n(ses-default-printer \"%.7g\")\n\n( ;Global parameters (these are read first)\n 1 ;SES file-format\n 1 ;numrows\n 1 ;numcols\n)\n\n")
675 (ses-load))
676 ;;ses-vector-delete is always called from buffer-undo-list with the same
677 ;;symbol as argument. We'll give it a different one here.
678 (let ((x [1 2 3]))
679 (ses-vector-delete 'x 0 0))
680 ;;ses-create-header-string behaves differently in a non-window environment
681 ;;but we always test under windows.
682 (let ((window-system (not window-system)))
683 (scroll-left 7)
684 (ses-create-header-string))
685 ;;Test for nonstandard after-entry functions
686 (let ((ses-after-entry-functions '(forward-line))
687 ses-mode-hook)
688 (ses-read-cell 0 0 1)
689 (ses-read-symbol 0 0 t)))
690 ;;Tests with unsafep disabled
691 (let ((safe-functions t)
692 ses-mode-hook)
693 (message "<Checking safe-functions = t>")
694 (kill-buffer "ses-example.ses")
695 (find-file "ses-example.ses"))
696 ;;Checks for nonstandard default values for new spreadsheets
697 (let (ses-mode-hook)
698 (dolist (x '(("%.6g" 8 (2 . 2))
699 ("%.8g" 6 (3 . 3))))
700 (let ((ses-initial-size (nth 2 x))
701 (ses-initial-column-width (nth 1 x))
702 (ses-initial-default-printer (nth 0 x)))
703 (with-temp-buffer
704 (set-buffer-modified-p t)
705 (ses-mode)))))
706 ;;Test error-handling in command hook, outside a macro.
707 ;;This will ring the bell.
708 (let (curcell-overlay)
709 (ses-command-hook))
710 ;;Due to use of run-with-timer, ses-command-hook sometimes gets called
711 ;;after we switch to another buffer.
712 (switch-to-buffer "*scratch*")
713 (ses-command-hook)
714 ;;Print results
715 (message "<Marking source code>")
716 (testcover-mark-all "ses.el")
717 (testcover-next-mark)
718 ;;Cleanup
719 (delete-other-windows)
720 (kill-buffer "ses-test.txt")
721 ;;Could do this here: (testcover-end "ses.el")
722 (message "Done"))
724 ;; testcover-ses.el ends here.