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