Compiler option to always bind certain symbols lexically.
[bpt/guile.git] / test-suite / tests / elisp-compiler.test
1 ;;;; elisp-compiler.test --- Test the compiler for Elisp.
2 ;;;;
3 ;;;; Copyright (C) 2009 Free Software Foundation, Inc.
4 ;;;; Daniel Kraft
5 ;;;;
6 ;;;; This library is free software; you can redistribute it and/or
7 ;;;; modify it under the terms of the GNU Lesser General Public
8 ;;;; License as published by the Free Software Foundation; either
9 ;;;; version 3 of the License, or (at your option) any later version.
10 ;;;;
11 ;;;; This library is distributed in the hope that it will be useful,
12 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ;;;; Lesser General Public License for more details.
15 ;;;;
16 ;;;; You should have received a copy of the GNU Lesser General Public
17 ;;;; License along with this library; if not, write to the Free Software
18 ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
20 (define-module (test-elisp-compiler)
21 :use-module (test-suite lib)
22 :use-module (system base compile)
23 :use-module (language elisp runtime))
24
25
26 ; Macros to handle the compilation conveniently.
27
28 (define-syntax compile-test
29 (syntax-rules (pass-if pass-if-exception)
30 ((_ (pass-if test-name exp))
31 (pass-if test-name (compile 'exp #:from 'elisp #:to 'value)))
32 ((_ (pass-if test-name exp #:opts opts))
33 (pass-if test-name (compile 'exp #:from 'elisp #:to 'value #:opts opts)))
34 ((_ (pass-if-equal test-name result exp))
35 (pass-if test-name (equal? result
36 (compile 'exp #:from 'elisp #:to 'value))))
37 ((_ (pass-if-exception test-name exc exp))
38 (pass-if-exception test-name exc
39 (compile 'exp #:from 'elisp #:to 'value)))))
40
41 (define-syntax with-test-prefix/compile
42 (syntax-rules ()
43 ((_ section-name exp ...)
44 (with-test-prefix section-name (compile-test exp) ...))))
45
46
47 ; Test control structures.
48 ; ========================
49
50 (with-test-prefix/compile "Sequencing"
51
52 (pass-if-equal "progn" 1
53 (progn (setq a 0)
54 (setq a (1+ a))
55 a))
56
57 (pass-if "prog1"
58 (progn (setq a 0)
59 (setq b (prog1 a (setq a (1+ a))))
60 (and (= a 1) (= b 0))))
61
62 (pass-if "prog2"
63 (progn (setq a 0)
64 (setq b (prog2 (setq a (1+ a))
65 (setq a (1+ a))
66 (setq a (1+ a))))
67 (and (= a 3) (= b 2)))))
68
69 (with-test-prefix/compile "Conditionals"
70
71 (pass-if-equal "succeeding if" 1
72 (if t 1 2))
73 (pass-if "failing if"
74 (and (= (if nil
75 1
76 (setq a 2) (setq a (1+ a)) a)
77 3)
78 (equal (if nil 1) nil)))
79
80 (pass-if-equal "failing when" nil-value
81 (when nil 1 2 3))
82 (pass-if-equal "succeeding when" 42
83 (progn (setq a 0)
84 (when t (setq a 42) a)))
85
86 (pass-if-equal "failing unless" nil-value
87 (unless t 1 2 3))
88 (pass-if-equal "succeeding unless" 42
89 (progn (setq a 0)
90 (unless nil (setq a 42) a)))
91
92 (pass-if-equal "empty cond" nil-value
93 (cond))
94 (pass-if-equal "all failing cond" nil-value
95 (cond (nil) (nil)))
96 (pass-if-equal "only condition" 5
97 (cond (nil) (5)))
98 (pass-if-equal "succeeding cond value" 42
99 (cond (nil) (t 42) (t 0)))
100 (pass-if-equal "succeeding cond side-effect" 42
101 (progn (setq a 0)
102 (cond (nil) (t (setq a 42) 1) (t (setq a 0)))
103 a)))
104
105 (with-test-prefix/compile "Combining Conditions"
106
107 (pass-if-equal "empty and" t-value (and))
108 (pass-if-equal "failing and" nil-value (and 1 2 nil 3))
109 (pass-if-equal "succeeding and" 3 (and 1 2 3))
110
111 (pass-if-equal "empty or" nil-value (or))
112 (pass-if-equal "failing or" nil-value (or nil nil nil))
113 (pass-if-equal "succeeding or" 1 (or nil 1 nil 2 nil 3))
114
115 (pass-if-equal "not true" nil-value (not 1))
116 (pass-if-equal "not false" t-value (not nil)))
117
118 (with-test-prefix/compile "Iteration"
119
120 (pass-if-equal "failing while" 0
121 (progn (setq a 0)
122 (while nil (setq a 1))
123 a))
124 (pass-if-equal "running while" 120
125 (progn (setq prod 1
126 i 1)
127 (while (<= i 5)
128 (setq prod (* i prod))
129 (setq i (1+ i)))
130 prod))
131
132 (pass-if "dotimes"
133 (progn (setq a 0)
134 (setq count 100)
135 (setq b (dotimes (i count)
136 (setq j (1+ i))
137 (setq a (+ a j))))
138 (setq c (dotimes (i 10 42) nil))
139 (and (= a 5050) (equal b nil) (= c 42))))
140
141 (pass-if "dolist"
142 (let ((mylist '(7 2 5)))
143 (setq sum 0)
144 (setq a (dolist (i mylist)
145 (setq sum (+ sum i))))
146 (setq b (dolist (i mylist 5) 0))
147 (and (= sum (+ 7 2 5))
148 (equal a nil)
149 (equal mylist '(7 2 5))
150 (equal b 5)))))
151
152 (with-test-prefix/compile "Exceptions"
153
154 (pass-if "catch without exception"
155 (and (setq a 0)
156 (= (catch 'foobar
157 (setq a (1+ a))
158 (setq a (1+ a))
159 a)
160 2)
161 (= (catch (+ 1 2) a) 2)))
162
163 ; FIXME: Figure out how to do this...
164 ;(pass-if-exception "uncaught exception" 'elisp-exception
165 ; (throw 'abc 1))
166
167 (pass-if "catch and throw"
168 (and (setq mylist '(1 2))
169 (= (catch 'abc (throw 'abc 2) 1) 2)
170 (= (catch 'abc (catch 'def (throw 'abc (1+ 0)) 2) 3) 1)
171 (= (catch 'abc (catch 'def (throw 'def 1) 2) 3) 3)
172 (= (catch mylist (catch '(1 2) (throw mylist 1) 2) 3) 1)))
173
174 (pass-if "unwind-protect"
175 (progn (setq a 0 b 1 c 1)
176 (catch 'exc
177 (unwind-protect (progn (setq a 1)
178 (throw 'exc 0))
179 (setq a 0)
180 (setq b 0)))
181 (unwind-protect nil (setq c 0))
182 (and (= a 0) (= b 0) (= c 0)
183 (= (unwind-protect 42 1 2 3) 42)))))
184
185 (with-test-prefix/compile "Eval"
186
187 (pass-if-equal "basic eval" 3
188 (progn (setq code '(+ 1 2))
189 (eval code)))
190
191 (pass-if "real dynamic code"
192 (and (setq a 1 b 1 c 1)
193 (defun set-code (var val)
194 (list 'setq var val))
195 (= a 1) (= b 1) (= c 1)
196 (eval (set-code 'a '(+ 2 3)))
197 (eval (set-code 'c 42))
198 (= a 5) (= b 1) (= c 42)))
199
200 ; Build code that recursively again and again calls eval. What we want is
201 ; something like:
202 ; (eval '(1+ (eval '(1+ (eval 1)))))
203 (pass-if "recursive eval"
204 (progn (setq depth 10 i depth)
205 (setq code '(eval 0))
206 (while (not (zerop i))
207 (setq code (\` (eval (quote (1+ (\, code))))))
208 (setq i (1- i)))
209 (= (eval code) depth))))
210
211
212 ; Test handling of variables.
213 ; ===========================
214
215 (with-test-prefix/compile "Variable Setting/Referencing"
216
217 ; TODO: Check for variable-void error
218
219 (pass-if-equal "setq and reference" 6
220 (progn (setq a 1 b 2 c 3)
221 (+ a b c)))
222 (pass-if-equal "setq evaluation order" 1
223 (progn (setq a 0 b 0)
224 (setq a 1 b a)))
225 (pass-if-equal "setq value" 2
226 (progn (setq a 1 b 2)))
227
228 (pass-if "set and symbol-value"
229 (progn (setq myvar 'a)
230 (and (= (set myvar 42) 42)
231 (= a 42)
232 (= (symbol-value myvar) 42))))
233 (pass-if "void variables"
234 (progn (setq a 1 b 2)
235 (and (eq (makunbound 'b) 'b)
236 (boundp 'a)
237 (not (boundp 'b)))))
238
239 (pass-if "disabled void check (all)"
240 (progn (makunbound 'a) a t)
241 #:opts '(#:disable-void-check all))
242 (pass-if "disabled void check (symbol list)"
243 (progn (makunbound 'a) a t)
244 #:opts '(#:disable-void-check (x y a b)))
245 (pass-if "without-void-checks"
246 (progn (makunbound 'a)
247 (= (without-void-checks (a) a 5) 5))))
248
249 (with-test-prefix/compile "Let and Let*"
250
251 (pass-if-equal "let without value" nil-value
252 (let (a (b 5)) a))
253 (pass-if-equal "basic let" 0
254 (progn (setq a 0)
255 (let ((a 1)
256 (b a))
257 b)))
258
259 (pass-if "let*"
260 (progn (setq a 0)
261 (and (let* ((a 1)
262 (b a))
263 (= b 1))
264 (let* (a b)
265 (setq a 1 b 2)
266 (and (= a 1) (= b 2)))
267 (= a 0)
268 (not (boundp 'b)))))
269
270 (pass-if "local scope"
271 (progn (setq a 0)
272 (setq b (let (a)
273 (setq a 1)
274 a))
275 (and (= a 0)
276 (= b 1)))))
277
278 (with-test-prefix/compile "Lexical Scoping"
279
280 (pass-if "basic let semantics"
281 (and (setq a 1)
282 (lexical-let ((a 2) (b a))
283 (and (= a 2) (= b 1)))
284 (lexical-let* ((a 2) (b a))
285 (and (= a 2) (= b 2) (setq a 42) (= a 42)))
286 (= a 1)))
287
288 (pass-if "lexical scope with lexical-let's"
289 (and (setq a 1)
290 (defun dyna () a)
291 (lexical-let (a)
292 (setq a 2)
293 (and (= a 2) (= (dyna) 1)))
294 (= a 1)
295 (lexical-let* (a)
296 (setq a 2)
297 (and (= a 2) (= (dyna) 1)))
298 (= a 1)))
299
300 (pass-if "lexical scoping vs. symbol-value / set"
301 (and (setq a 1)
302 (lexical-let ((a 2))
303 (and (= a 2)
304 (= (symbol-value 'a) 1)
305 (set 'a 3)
306 (= a 2)
307 (= (symbol-value 'a) 3)))
308 (= a 3)))
309
310 (pass-if "let inside lexical-let"
311 (and (setq a 1 b 1)
312 (defun dynvals () (cons a b))
313 (lexical-let ((a 2))
314 (and (= a 2) (equal (dynvals) '(1 . 1))
315 (let ((a 3) (b a))
316 (and (= a 3) (= b 2)
317 (equal (dynvals) '(1 . 2))))
318 (let* ((a 4) (b a))
319 (and (= a 4) (= b 4)
320 (equal (dynvals) '(1 . 4))))
321 (= a 2)))
322 (= a 1)))
323
324 (pass-if "lambda args inside lexical-let"
325 (and (setq a 1)
326 (defun dyna () a)
327 (lexical-let ((a 2) (b 42))
328 (and (= a 2) (= (dyna) 1)
329 ((lambda (a) (and (= a 3) (= b 42) (= (dyna) 3))) 3)
330 (= a 2) (= (dyna) 1)))
331 (= a 1)))
332
333 (pass-if "closures"
334 (and (defun make-counter ()
335 (lexical-let ((cnt 0))
336 (lambda ()
337 (setq cnt (1+ cnt)))))
338 (setq c1 (make-counter) c2 (make-counter))
339 (= (funcall c1) 1)
340 (= (funcall c1) 2)
341 (= (funcall c1) 3)
342 (= (funcall c2) 1)
343 (= (funcall c2) 2)
344 (= (funcall c1) 4)
345 (= (funcall c2) 3)))
346
347 (pass-if "always lexical option (all)"
348 (progn (setq a 0)
349 (defun dyna () a)
350 (let ((a 1))
351 (and (= a 1) (= (dyna) 0))))
352 #:opts '(#:always-lexical all))
353 (pass-if "always lexical option (list)"
354 (progn (setq a 0 b 0)
355 (defun dyna () a)
356 (defun dynb () b)
357 (let ((a 1)
358 (b 1))
359 (and (= a 1) (= (dyna) 0)
360 (= b 1) (= (dynb) 1))))
361 #:opts '(#:always-lexical (a)))
362 (pass-if "with-always-lexical"
363 (progn (setq a 0)
364 (defun dyna () a)
365 (with-always-lexical (a)
366 (let ((a 1))
367 (and (= a 1) (= (dyna) 0)))))))
368
369 (with-test-prefix/compile "defconst and defvar"
370
371 (pass-if-equal "defconst without docstring" 3.141
372 (progn (setq pi 3)
373 (defconst pi 3.141)
374 pi))
375 (pass-if-equal "defconst value" 'pi
376 (defconst pi 3.141 "Pi"))
377
378 (pass-if-equal "defvar without value" 42
379 (progn (setq a 42)
380 (defvar a)
381 a))
382 (pass-if-equal "defvar on already defined variable" 42
383 (progn (setq a 42)
384 (defvar a 1 "Some docstring is also ok")
385 a))
386 (pass-if-equal "defvar on undefined variable" 1
387 (progn (makunbound 'a)
388 (defvar a 1)
389 a))
390 (pass-if-equal "defvar value" 'a
391 (defvar a)))
392
393
394 ; Functions and lambda expressions.
395 ; =================================
396
397 (with-test-prefix/compile "Lambda Expressions"
398
399 (pass-if-equal "required arguments" 3
400 ((lambda (a b c) c) 1 2 3))
401
402 (pass-if-equal "optional argument" 3
403 ((function (lambda (a &optional b c) c)) 1 2 3))
404 (pass-if-equal "optional missing" nil-value
405 ((lambda (&optional a) a)))
406
407 (pass-if-equal "rest argument" '(3 4 5)
408 ((lambda (a b &rest c) c) 1 2 3 4 5))
409 (pass-if-equal "rest missing" nil-value
410 ((lambda (a b &rest c) c) 1 2)))
411
412 (with-test-prefix/compile "Function Definitions"
413
414 (pass-if-equal "defun" 3
415 (progn (defun test (a b) (+ a b))
416 (test 1 2)))
417 (pass-if-equal "defun value" 'test
418 (defun test (a b) (+ a b)))
419
420 (pass-if "fset and symbol-function"
421 (progn (setq myfunc 'x x 5)
422 (and (= (fset myfunc 42) 42)
423 (= (symbol-function myfunc) 42)
424 (= x 5))))
425 (pass-if "void function values"
426 (progn (setq a 1)
427 (defun test (a b) (+ a b))
428 (fmakunbound 'a)
429 (fset 'b 5)
430 (and (fboundp 'b) (fboundp 'test)
431 (not (fboundp 'a))
432 (= a 1))))
433
434 (pass-if "flet and flet*"
435 (progn (defun foobar () 42)
436 (defun test () (foobar))
437 (and (= (test) 42)
438 (flet ((foobar (lambda () 0))
439 (myfoo (symbol-function 'foobar)))
440 (and (= (myfoo) 42)
441 (= (test) 0)))
442 (flet* ((foobar (lambda () 0))
443 (myfoo (symbol-function 'foobar)))
444 (= (myfoo) 0))
445 (flet (foobar)
446 (defun foobar () 0)
447 (= (test) 0))
448 (= (test) 42)))))
449
450 (with-test-prefix/compile "Calling Functions"
451
452 (pass-if-equal "recursion" 120
453 (progn (defun factorial (n prod)
454 (if (zerop n)
455 prod
456 (factorial (1- n) (* prod n))))
457 (factorial 5 1)))
458
459 (pass-if "dynamic scoping"
460 (progn (setq a 0)
461 (defun foo ()
462 (setq a (1+ a))
463 a)
464 (defun bar (a)
465 (foo))
466 (and (= 43 (bar 42))
467 (zerop a))))
468
469 (pass-if "funcall and apply argument handling"
470 (and (defun allid (&rest args) args)
471 (setq allid-var (symbol-function 'allid))
472 (equal (funcall allid-var 1 2 3) '(1 2 3))
473 (equal (funcall allid-var) nil)
474 (equal (funcall allid-var 1 2 '(3 4)) '(1 2 (3 4)))
475 (equal (funcall allid-var '()) '(()))
476 (equal (apply allid-var 1 2 '(3 4)) '(1 2 3 4))
477 (equal (apply allid-var '(1 2)) '(1 2))
478 (equal (apply allid-var '()) nil)))
479
480 (pass-if "raw functions with funcall"
481 (and (= (funcall '+ 1 2) 3)
482 (= (funcall (lambda (a b) (+ a b)) 1 2) 3)
483 (= (funcall '(lambda (a b) (+ a b)) 1 2) 3))))
484
485
486 ; Quoting and Backquotation.
487 ; ==========================
488
489 (with-test-prefix/compile "Quotation"
490
491 (pass-if "quote"
492 (and (equal '42 42) (equal '"abc" "abc")
493 (equal '(1 2 (3 (4) x)) '(1 2 (3 (4) x)))
494 (not (equal '(1 2 (3 4 (x))) '(1 2 3 4 x)))
495 (equal '(1 2 . 3) '(1 2 . 3))))
496
497 (pass-if "simple backquote"
498 (and (equal (\` 42) 42)
499 (equal (\` (1 (a))) '(1 (a)))
500 (equal (\` (1 . 2)) '(1 . 2))))
501 (pass-if "unquote"
502 (progn (setq a 42 l '(18 12))
503 (and (equal (\` (\, a)) 42)
504 (equal (\` (1 a ((\, l)) . (\, a))) '(1 a ((18 12)) . 42)))))
505 (pass-if "unquote splicing"
506 (progn (setq l '(18 12) empty '())
507 (and (equal (\` (\,@ l)) '(18 12))
508 (equal (\` (l 2 (3 (\,@ l)) ((\,@ l)) (\,@ l)))
509 '(l 2 (3 18 12) (18 12) 18 12))
510 (equal (\` (1 2 (\,@ empty) 3)) '(1 2 3))))))
511
512
513
514 ; Macros.
515 ; =======
516
517 (with-test-prefix/compile "Macros"
518
519 (pass-if-equal "defmacro value" 'magic-number
520 (defmacro magic-number () 42))
521
522 (pass-if-equal "macro expansion" 1
523 (progn (defmacro take-first (a b) a)
524 (take-first 1 (/ 1 0)))))
525
526
527 ; Test the built-ins.
528 ; ===================
529
530 (with-test-prefix/compile "Equivalence Predicates"
531
532 (pass-if "equal"
533 (and (equal 2 2) (not (equal 1 2))
534 (equal "abc" "abc") (not (equal "abc" "ABC"))
535 (equal 'abc 'abc) (not (equal 'abc 'def))
536 (equal '(1 2 (3 4) 5) '(1 2 (3 4) 5))
537 (not (equal '(1 2 3 4 5) '(1 2 (3 4) 5)))))
538
539 (pass-if "eq"
540 (progn (setq some-list '(1 2))
541 (setq some-string "abc")
542 (and (eq 2 2) (not (eq 1 2))
543 (eq 'abc 'abc) (not (eq 'abc 'def))
544 (eq some-string some-string) (not (eq some-string "abc"))
545 (eq some-list some-list) (not (eq some-list '(1 2)))))))
546
547 (with-test-prefix/compile "Number Built-Ins"
548
549 (pass-if "floatp"
550 (and (floatp 1.0) (not (floatp 1)) (not (floatp 'a))))
551 (pass-if "integerp"
552 (and (integerp 42) (integerp -2) (not (integerp 1.0))))
553 (pass-if "numberp"
554 (and (numberp 1.0) (numberp -2) (not (numberp 'a))))
555 (pass-if "wholenump"
556 (and (wholenump 0) (not (wholenump -2)) (not (wholenump 1.0))))
557 (pass-if "zerop"
558 (and (zerop 0) (zerop 0.0) (not (zerop 1))))
559
560 (pass-if "comparisons"
561 (and (= 1 1.0) (/= 0 1)
562 (< 1 2) (> 2 1) (>= 1 1) (<= 1 1)
563 (not (< 1 1)) (not (<= 2 1))))
564
565 (pass-if "max and min"
566 (and (= (max -5 2 4.0 1) 4.0) (= (min -5 2 4.0 1) -5)
567 (= (max 1) 1) (= (min 1) 1)))
568 (pass-if "abs"
569 (and (= (abs 1.0) 1.0) (= (abs -5) 5)))
570
571 (pass-if "float"
572 (and (= (float 1) 1) (= (float 5.5) 5.5)
573 (floatp (float 1))))
574
575 (pass-if-equal "basic arithmetic operators" -8.5
576 (+ (1+ 0) (1- 0) (- 5.5) (* 2 -2) (- 2 1)))
577 (pass-if "modulo"
578 (= (% 5 3) 2))
579
580 (pass-if "floating point rounding"
581 (and (= (ffloor 1.7) 1.0) (= (ffloor -1.2) -2.0) (= (ffloor 1.0) 1.0)
582 (= (fceiling 1.2) 2.0) (= (fceiling -1.7) -1.0) (= (fceiling 1.0) 1.0)
583 (= (ftruncate 1.6) 1.0) (= (ftruncate -1.7) -1.0)
584 (= (fround 1.2) 1.0) (= (fround 1.7) 2.0) (= (fround -1.7) -2.0))))
585
586 (with-test-prefix/compile "List Built-Ins"
587
588 (pass-if "consp and atomp"
589 (and (consp '(1 2 3)) (consp '(1 2 . 3)) (consp '(a . b))
590 (not (consp '())) (not (consp 1)) (not (consp "abc"))
591 (atomp 'a) (atomp '()) (atomp -1.5) (atomp "abc")
592 (not (atomp '(1 . 2))) (not (atomp '(1)))))
593 (pass-if "listp and nlistp"
594 (and (listp '(1 2 3)) (listp '(1)) (listp '()) (listp '(1 . 2))
595 (not (listp 'a)) (not (listp 42)) (nlistp 42)
596 (not (nlistp '())) (not (nlistp '(1 2 3))) (not (nlistp '(1 . 2)))))
597 (pass-if "null"
598 (and (null '()) (not (null 1)) (not (null '(1 2))) (not (null '(1 . 2)))))
599
600 (pass-if "car and cdr"
601 (and (equal (car '(1 2 3)) 1) (equal (cdr '(1 2 3)) '(2 3))
602 (equal (car '()) nil) (equal (cdr '()) nil)
603 (equal (car '(1 . 2)) 1) (equal (cdr '(1 . 2)) 2)
604 (null (cdr '(1)))))
605 (pass-if "car-safe and cdr-safe"
606 (and (equal (car-safe '(1 2)) 1) (equal (cdr-safe '(1 2)) '(2))
607 (equal (car-safe 5) nil) (equal (cdr-safe 5) nil)))
608
609 (pass-if "pop"
610 (progn (setq mylist '(a b c))
611 (setq value (pop mylist))
612 (and (equal value 'a)
613 (equal mylist '(b c)))))
614 (pass-if-equal "push" '(a b c)
615 (progn (setq mylist '(b c))
616 (push 'a mylist)))
617
618 (pass-if "nth and nthcdr"
619 (and (equal (nth -5 '(1 2 3)) 1) (equal (nth 3 '(1 2 3)) nil)
620 (equal (nth 0 '(1 2 3)) 1) (equal (nth 2 '(1 2 3)) 3)
621 (equal (nthcdr -5 '(1 2 3)) '(1 2 3))
622 (equal (nthcdr 4 '(1 2 3)) nil)
623 (equal (nthcdr 1 '(1 2 3)) '(2 3))
624 (equal (nthcdr 2 '(1 2 3)) '(3))))
625
626 (pass-if "length"
627 (and (= (length '()) 0)
628 (= (length '(1 2 3 4 5)) 5)
629 (= (length '(1 2 (3 4 (5)) 6)) 4)))
630
631 (pass-if "cons, list and make-list"
632 (and (equal (cons 1 2) '(1 . 2)) (equal (cons 1 '(2 3)) '(1 2 3))
633 (equal (cons 1 '()) '(1))
634 (equal (list 'a) '(a)) (equal (list) '()) (equal (list 1 2) '(1 2))
635 (equal (make-list 3 42) '(42 42 42))
636 (equal (make-list 0 1) '())))
637 (pass-if "append"
638 (and (equal (append '(1 2) '(3 4) '(5)) '(1 2 3 4 5))
639 (equal (append '(1 2) 3) '(1 2 . 3))))
640 (pass-if "reverse"
641 (and (equal (reverse '(5 4 3 2 1)) '(1 2 3 4 5))
642 (equal (reverse '()) '())))
643 (pass-if "copy-tree"
644 (progn (setq mylist '(1 2 (3 4)))
645 (and (not (eq mylist (copy-tree mylist)))
646 (equal mylist (copy-tree mylist)))))
647
648 (pass-if "number-sequence"
649 (and (equal (number-sequence 5) '(5))
650 (equal (number-sequence 5 9) '(5 6 7 8 9))
651 (equal (number-sequence 5 9 3) '(5 8))
652 (equal (number-sequence 5 1 -2) '(5 3 1))
653 (equal (number-sequence 5 8 -1) '())
654 (equal (number-sequence 5 1) '())
655 (equal (number-sequence 5 5 0) '(5))))
656
657 (pass-if "setcar and setcdr"
658 (progn (setq pair '(1 . 2))
659 (setq copy pair)
660 (setq a (setcar copy 3))
661 (setq b (setcdr copy 4))
662 (and (= a 3) (= b 4)
663 (equal pair '(3 . 4))))))