summaryrefslogtreecommitdiff
path: root/test-suite/tests/elisp-compiler.test
blob: 0d3a8b4b49c58a6825f418cc0708cf3dd13e7e32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
;;;; elisp-compiler.test --- Test the compiler for Elisp.  -*- scheme -*-
;;;;
;;;; Copyright (C) 2009, 2010 Free Software Foundation, Inc.
;;;; Daniel Kraft
;;;;
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
;;;; License as published by the Free Software Foundation; either
;;;; version 3 of the License, or (at your option) any later version.
;;;; 
;;;; This library is distributed in the hope that it will be useful,
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;;;; Lesser General Public License for more details.
;;;; 
;;;; You should have received a copy of the GNU Lesser General Public
;;;; License along with this library; if not, write to the Free Software
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

(define-module (test-elisp-compiler)
  :use-module (test-suite lib)
  :use-module (system base compile)
  :use-module (language elisp runtime))


; Macros to handle the compilation conveniently.

(define-syntax compile-test
  (syntax-rules (pass-if pass-if-equal pass-if-exception)
    ((_ (pass-if test-name exp))
     (pass-if test-name (compile 'exp #:from 'elisp #:to 'value)))
    ((_ (pass-if test-name exp #:opts opts))
     (pass-if test-name (compile 'exp #:from 'elisp #:to 'value #:opts opts)))
    ((_ (pass-if-equal test-name result exp))
     (pass-if test-name (equal? result
                                (compile 'exp #:from 'elisp #:to 'value))))
    ((_ (pass-if-exception test-name exc exp))
     (pass-if-exception test-name exc
                        (compile 'exp #:from 'elisp #:to 'value)))))

(define-syntax with-test-prefix/compile
  (syntax-rules ()
    ((_ section-name exp ...)
     (with-test-prefix section-name (compile-test exp) ...))))


; Test control structures.
; ========================

(with-test-prefix/compile "Sequencing"
  
  (pass-if-equal "progn" 1
    (progn (setq a 0)
           (setq a (1+ a))
           a))

  (pass-if "prog1"
    (progn (setq a 0)
           (setq b (prog1 a (setq a (1+ a))))
           (and (= a 1) (= b 0))))

  (pass-if "prog2"
    (progn (setq a 0)
           (setq b (prog2 (setq a (1+ a))
                          (setq a (1+ a))
                          (setq a (1+ a))))
           (and (= a 3) (= b 2)))))

(with-test-prefix/compile "Conditionals"

  (pass-if-equal "succeeding if" 1
    (if t 1 2))
  (pass-if "failing if"
    (and (= (if nil
              1
              (setq a 2) (setq a (1+ a)) a)
            3)
         (equal (if nil 1) nil)))

  (pass-if-equal "failing when" nil-value
    (when nil 1 2 3))
  (pass-if-equal "succeeding when" 42
    (progn (setq a 0)
           (when t (setq a 42) a)))

  (pass-if-equal "failing unless" nil-value
    (unless t 1 2 3))
  (pass-if-equal "succeeding unless" 42
    (progn (setq a 0)
           (unless nil (setq a 42) a)))

  (pass-if-equal "empty cond" nil-value
    (cond))
  (pass-if-equal "all failing cond" nil-value
    (cond (nil) (nil)))
  (pass-if-equal "only condition" 5
    (cond (nil) (5)))
  (pass-if-equal "succeeding cond value" 42
    (cond (nil) (t 42) (t 0)))
  (pass-if-equal "succeeding cond side-effect" 42
    (progn (setq a 0)
           (cond (nil) (t (setq a 42) 1) (t (setq a 0)))
           a)))

(with-test-prefix/compile "Combining Conditions"

  (pass-if-equal "empty and" t-value (and))
  (pass-if-equal "failing and" nil-value (and 1 2 nil 3))
  (pass-if-equal "succeeding and" 3 (and 1 2 3))

  (pass-if-equal "empty or" nil-value (or))
  (pass-if-equal "failing or" nil-value (or nil nil nil))
  (pass-if-equal "succeeding or" 1 (or nil 1 nil 2 nil 3))

  (pass-if-equal "not true" nil-value (not 1))
  (pass-if-equal "not false" t-value (not nil)))

(with-test-prefix/compile "Iteration"

  (pass-if-equal "failing while" 0
    (progn (setq a 0)
           (while nil (setq a 1))
           a))
  (pass-if-equal "running while" 120
    (progn (setq prod 1
                 i 1)
           (while (<= i 5)
             (setq prod (* i prod))
             (setq i (1+ i)))
           prod))

  (pass-if "dotimes"
    (progn (setq a 0)
           (setq count 100)
           (setq b (dotimes (i count)
                     (setq j (1+ i))
                     (setq a (+ a j))))
           (setq c (dotimes (i 10 42) nil))
           (and (= a 5050) (equal b nil) (= c 42))))

  (pass-if "dolist"
    (let ((mylist '(7 2 5)))
      (setq sum 0)
      (setq a (dolist (i mylist)
                (setq sum (+ sum i))))
      (setq b (dolist (i mylist 5) 0))
      (and (= sum (+ 7 2 5))
           (equal a nil)
           (equal mylist '(7 2 5))
           (equal b 5)))))

(with-test-prefix/compile "Exceptions"

  (pass-if "catch without exception"
    (and (setq a 0)
         (= (catch 'foobar
                   (setq a (1+ a))
                   (setq a (1+ a))
                   a)
            2)
         (= (catch (+ 1 2) a) 2)))

  ; FIXME: Figure out how to do this...
  ;(pass-if-exception "uncaught exception" 'elisp-exception
  ;  (throw 'abc 1))

  (pass-if "catch and throw"
    (and (setq mylist '(1 2))
         (= (catch 'abc (throw 'abc 2) 1) 2)
         (= (catch 'abc (catch 'def (throw 'abc (1+ 0)) 2) 3) 1)
         (= (catch 'abc (catch 'def (throw 'def 1) 2) 3) 3)
         (= (catch mylist (catch '(1 2) (throw mylist 1) 2) 3) 1)))

  (pass-if "unwind-protect"
    (progn (setq a 0 b 1 c 1)
           (catch 'exc
                  (unwind-protect (progn (setq a 1)
                                         (throw 'exc 0))
                                  (setq a 0)
                                  (setq b 0)))
           (unwind-protect nil (setq c 0))
           (and (= a 0) (= b 0) (= c 0)
                (= (unwind-protect 42 1 2 3) 42)))))

(with-test-prefix/compile "Eval"

  (pass-if-equal "basic eval" 3
    (progn (setq code '(+ 1 2))
           (eval code)))

  (pass-if "real dynamic code"
    (and (setq a 1 b 1 c 1)
         (defun set-code (var val)
           (list 'setq var val))
         (= a 1) (= b 1) (= c 1)
         (eval (set-code 'a '(+ 2 3)))
         (eval (set-code 'c 42))
         (= a 5) (= b 1) (= c 42)))

  ; Build code that recursively again and again calls eval.  What we want is
  ; something like:
  ; (eval '(1+ (eval '(1+ (eval 1)))))
  (pass-if "recursive eval"
    (progn (setq depth 10 i depth)
           (setq code '(eval 0))
           (while (not (zerop i))
             (setq code (#{`}# (eval (quote (1+ (#{,}# code))))))
             (setq i (1- i)))
           (= (eval code) depth))))


; Test handling of variables.
; ===========================

(with-test-prefix/compile "Variable Setting/Referencing"

  ; TODO: Check for variable-void error

  (pass-if-equal "setq and reference" 6
    (progn (setq a 1 b 2 c 3)
           (+ a b c)))
  (pass-if-equal "setq evaluation order" 1
    (progn (setq a 0 b 0)
           (setq a 1 b a)))
  (pass-if-equal "setq value" 2
    (progn (setq a 1 b 2)))

  (pass-if "set and symbol-value"
    (progn (setq myvar 'a)
           (and (= (set myvar 42) 42)
                (= a 42)
                (= (symbol-value myvar) 42))))
  (pass-if "void variables"
    (progn (setq a 1 b 2)
           (and (eq (makunbound 'b) 'b)
                (boundp 'a)
                (not (boundp 'b))))))

(with-test-prefix/compile "Let and Let*"

  (pass-if-equal "let without value" nil-value
    (let (a (b 5)) a))
  (pass-if-equal "basic let" 0
    (progn (setq a 0)
           (let ((a 1)
                 (b a))
             b)))

  (pass-if "let*"
    (progn (setq a 0)
           (and (let* ((a 1)
                       (b a))
                  (= b 1))
                (let* (a b)
                  (setq a 1 b 2)
                  (and (= a 1) (= b 2)))
                (= a 0)
                (not (boundp 'b)))))

  (pass-if "local scope"
    (progn (setq a 0)
           (setq b (let (a)
                     (setq a 1)
                     a))
           (and (= a 0)
                (= b 1)))))

(with-test-prefix/compile "Lexical Scoping"

  (pass-if "basic let semantics"
    (and (setq a 1)
         (lexical-let ((a 2) (b a))
           (and (= a 2) (= b 1)))
         (lexical-let* ((a 2) (b a))
           (and (= a 2) (= b 2) (setq a 42) (= a 42)))
         (= a 1)))

  (pass-if "lexical scope with lexical-let's"
    (and (setq a 1)
         (defun dyna () a)
         (lexical-let (a)
           (setq a 2)
           (and (= a 2) (= (dyna) 1)))
         (= a 1)
         (lexical-let* (a)
           (setq a 2)
           (and (= a 2) (= (dyna) 1)))
         (= a 1)))

  (pass-if "lexical scoping vs. symbol-value / set"
    (and (setq a 1)
         (lexical-let ((a 2))
           (and (= a 2)
                (= (symbol-value 'a) 1)
                (set 'a 3)
                (= a 2)
                (= (symbol-value 'a) 3)))
         (= a 3)))

  (pass-if "let inside lexical-let"
    (and (setq a 1 b 1)
         (defun dynvals () (cons a b))
         (lexical-let ((a 2))
           (and (= a 2) (equal (dynvals) '(1 . 1))
                (let ((a 3) (b a))
                  (and (= a 3) (= b 2)
                       (equal (dynvals) '(1 . 2))))
                (let* ((a 4) (b a))
                  (and (= a 4) (= b 4)
                       (equal (dynvals) '(1 . 4))))
                (= a 2)))
         (= a 1)))

  (pass-if "lambda args inside lexical-let"
    (and (setq a 1)
         (defun dyna () a)
         (lexical-let ((a 2) (b 42))
           (and (= a 2) (= (dyna) 1)
                ((lambda (a) (and (= a 3) (= b 42) (= (dyna) 3))) 3)
                ((lambda () (let ((a 3))
                              (and (= a 3) (= (dyna) 1)))))
                (= a 2) (= (dyna) 1)))
         (= a 1)))

  (pass-if "closures"
    (and (defun make-counter ()
           (lexical-let ((cnt 0))
             (lambda ()
               (setq cnt (1+ cnt)))))
         (setq c1 (make-counter) c2 (make-counter))
         (= (funcall c1) 1)
         (= (funcall c1) 2)
         (= (funcall c1) 3)
         (= (funcall c2) 1)
         (= (funcall c2) 2)
         (= (funcall c1) 4)
         (= (funcall c2) 3)))

  (pass-if "always lexical option (all)"
    (progn (setq a 0)
           (defun dyna () a)
           (let ((a 1))
             (and (= a 1) (= (dyna) 0))))
    #:opts '(#:always-lexical all))
  (pass-if "always lexical option (list)"
    (progn (setq a 0 b 0)
           (defun dyna () a)
           (defun dynb () b)
           (let ((a 1)
                 (b 1))
             (and (= a 1) (= (dyna) 0)
                  (= b 1) (= (dynb) 1))))
    #:opts '(#:always-lexical (a)))
  (pass-if "with-always-lexical"
    (progn (setq a 0)
           (defun dyna () a)
           (with-always-lexical (a)
             (let ((a 1))
               (and (= a 1) (= (dyna) 0))))))

  (pass-if "lexical lambda args"
    (progn (setq a 1 b 1)
           (defun dyna () a)
           (defun dynb () b)
           (with-always-lexical (a c)
             ((lambda (a b &optional c)
                (and (= a 3) (= (dyna) 1)
                     (= b 2) (= (dynb) 2)
                     (= c 1)))
              3 2 1))))

  ; Check if a lambda without dynamically bound arguments
  ; is tail-optimized by doing a deep recursion that would otherwise overflow
  ; the stack.
  (pass-if "lexical lambda tail-recursion"
    (with-always-lexical (i)
      (setq to 1000000)
      (defun iteration-1 (i)
        (if (< i to)
          (iteration-1 (1+ i))))
      (iteration-1 0)
      (setq x 0)
      (defun iteration-2 ()
        (if (< x to)
          (setq x (1+ x))
          (iteration-2)))
      (iteration-2)
      t)))


(with-test-prefix/compile "defconst and defvar"

  (pass-if-equal "defconst without docstring" 3.141
    (progn (setq pi 3)
           (defconst pi 3.141)
           pi))
  (pass-if-equal "defconst value" 'pi
    (defconst pi 3.141 "Pi"))

  (pass-if-equal "defvar without value" 42
    (progn (setq a 42)
           (defvar a)
           a))
  (pass-if-equal "defvar on already defined variable" 42
    (progn (setq a 42)
           (defvar a 1 "Some docstring is also ok")
           a))
  (pass-if-equal "defvar on undefined variable" 1
    (progn (makunbound 'a)
           (defvar a 1)
           a))
  (pass-if-equal "defvar value" 'a
    (defvar a)))


; Functions and lambda expressions.
; =================================

(with-test-prefix/compile "Lambda Expressions"

  (pass-if-equal "required arguments" 3
    ((lambda (a b c) c) 1 2 3))

  (pass-if-equal "optional argument" 3
    ((function (lambda (a &optional b c) c)) 1 2 3))
  (pass-if-equal "optional missing" nil-value
    ((lambda (&optional a) a)))

  (pass-if-equal "rest argument" '(3 4 5)
    ((lambda (a b &rest c) c) 1 2 3 4 5))
  (pass-if-equal "rest missing" nil-value
    ((lambda (a b &rest c) c) 1 2)))

(with-test-prefix/compile "Function Definitions"

  (pass-if-equal "defun" 3
    (progn (defun test (a b) (+ a b))
           (test 1 2)))
  (pass-if-equal "defun value" 'test
    (defun test (a b) (+ a b)))

  (pass-if "fset and symbol-function"
    (progn (setq myfunc 'x x 5)
           (and (= (fset myfunc 42) 42)
                (= (symbol-function myfunc) 42)
                (= x 5))))
  (pass-if "void function values"
    (progn (setq a 1)
           (defun test (a b) (+ a b))
           (fmakunbound 'a)
           (fset 'b 5)
           (and (fboundp 'b) (fboundp 'test)
                (not (fboundp 'a))
                (= a 1))))

  (pass-if "flet and flet*"
    (progn (defun foobar () 42)
           (defun test () (foobar))
           (and (= (test) 42)
                (flet ((foobar (lambda () 0))
                       (myfoo (symbol-function 'foobar)))
                  (and (= (myfoo) 42)
                       (= (test) 0)))
                (flet* ((foobar (lambda () 0))
                        (myfoo (symbol-function 'foobar)))
                  (= (myfoo) 0))
                (flet (foobar)
                  (defun foobar () 0)
                  (= (test) 0))
                (= (test) 42)))))

(with-test-prefix/compile "Calling Functions"

  (pass-if-equal "recursion" 120
    (progn (defun factorial (n prod)
             (if (zerop n)
               prod
               (factorial (1- n) (* prod n))))
           (factorial 5 1)))

  (pass-if "dynamic scoping"
    (progn (setq a 0)
           (defun foo ()
             (setq a (1+ a))
             a)
           (defun bar (a)
             (foo))
           (and (= 43 (bar 42))
                (zerop a))))

  (pass-if "funcall and apply argument handling"
    (and (defun allid (&rest args) args)
         (setq allid-var (symbol-function 'allid))
         (equal (funcall allid-var 1 2 3) '(1 2 3))
         (equal (funcall allid-var) nil)
         (equal (funcall allid-var 1 2 '(3 4)) '(1 2 (3 4)))
         (equal (funcall allid-var '()) '(()))
         (equal (apply allid-var 1 2 '(3 4)) '(1 2 3 4))
         (equal (apply allid-var '(1 2)) '(1 2))
         (equal (apply allid-var '()) nil)))

  (pass-if "raw functions with funcall"
    (and (= (funcall '+ 1 2) 3)
         (= (funcall (lambda (a b) (+ a b)) 1 2) 3)
         (= (funcall '(lambda (a b) (+ a b)) 1 2) 3))))


; Quoting and Backquotation.
; ==========================

(with-test-prefix/compile "Quotation"

  (pass-if "quote"
    (and (equal '42 42) (equal '"abc" "abc")
         (equal '(1 2 (3 (4) x)) '(1 2 (3 (4) x)))
         (not (equal '(1 2 (3 4 (x))) '(1 2 3 4 x)))
         (equal '(1 2 . 3) '(1 2 . 3))))

  (pass-if "simple backquote"
    (and (equal (#{`}# 42) 42)
         (equal (#{`}# (1 (a))) '(1 (a)))
         (equal (#{`}# (1 . 2)) '(1 . 2))))
  (pass-if "unquote"
    (progn (setq a 42 l '(18 12))
           (and (equal (#{`}# (#{,}# a)) 42)
                (equal (#{`}# (1 a ((#{,}# l)) . (#{,}# a))) '(1 a ((18 12)) . 42)))))
  (pass-if "unquote splicing"
    (progn (setq l '(18 12) empty '())
           (and (equal (#{`}# (#{,@}# l)) '(18 12))
                (equal (#{`}# (l 2 (3 (#{,@}# l)) ((#{,@}# l)) (#{,@}# l)))
                       '(l 2 (3 18 12) (18 12) 18 12))
                (equal (#{`}# (1 2 (#{,@}# empty) 3)) '(1 2 3))))))
      


; Macros.
; =======

(with-test-prefix/compile "Macros"

  (pass-if-equal "defmacro value" 'magic-number
    (defmacro magic-number () 42))

  (pass-if-equal "macro expansion" 1
    (progn (defmacro take-first (a b) a)
           (take-first 1 (/ 1 0)))))


; Test the built-ins.
; ===================

(with-test-prefix/compile "Equivalence Predicates"

  (pass-if "equal"
    (and (equal 2 2) (not (equal 1 2))
         (equal "abc" "abc") (not (equal "abc" "ABC"))
         (equal 'abc 'abc) (not (equal 'abc 'def))
         (equal '(1 2 (3 4) 5) '(1 2 (3 4) 5))
         (not (equal '(1 2 3 4 5) '(1 2 (3 4) 5)))))

  (pass-if "eq"
    (progn (setq some-list '(1 2))
           (setq some-string "abc")
           (and (eq 2 2) (not (eq 1 2))
                (eq 'abc 'abc) (not (eq 'abc 'def))
                (eq some-string some-string) (not (eq some-string "abc"))
                (eq some-list some-list) (not (eq some-list '(1 2)))))))

(with-test-prefix/compile "Number Built-Ins"

  (pass-if "floatp"
    (and (floatp 1.0) (not (floatp 1)) (not (floatp 'a))))
  (pass-if "integerp"
    (and (integerp 42) (integerp -2) (not (integerp 1.0))))
  (pass-if "numberp"
    (and (numberp 1.0) (numberp -2) (not (numberp 'a))))
  (pass-if "wholenump"
    (and (wholenump 0) (not (wholenump -2)) (not (wholenump 1.0))))
  (pass-if "zerop"
    (and (zerop 0) (zerop 0.0) (not (zerop 1))))

  (pass-if "comparisons"
    (and (= 1 1.0) (/= 0 1)
         (< 1 2) (> 2 1) (>= 1 1) (<= 1 1)
         (not (< 1 1)) (not (<= 2 1))))

  (pass-if "max and min"
    (and (= (max -5 2 4.0 1) 4.0) (= (min -5 2 4.0 1) -5)
         (= (max 1) 1) (= (min 1) 1)))
  (pass-if "abs"
    (and (= (abs 1.0) 1.0) (= (abs -5) 5)))

  (pass-if "float"
    (and (= (float 1) 1) (= (float 5.5) 5.5)
         (floatp (float 1))))

  (pass-if-equal "basic arithmetic operators" -8.5
    (+ (1+ 0) (1- 0) (- 5.5) (* 2 -2) (- 2 1)))
  (pass-if "modulo"
    (= (% 5 3) 2))

  (pass-if "floating point rounding"
    (and (= (ffloor 1.7) 1.0) (= (ffloor -1.2) -2.0) (= (ffloor 1.0) 1.0)
         (= (fceiling 1.2) 2.0) (= (fceiling -1.7) -1.0) (= (fceiling 1.0) 1.0)
         (= (ftruncate 1.6) 1.0) (= (ftruncate -1.7) -1.0)
         (= (fround 1.2) 1.0) (= (fround 1.7) 2.0) (= (fround -1.7) -2.0))))

(with-test-prefix/compile "List Built-Ins"

  (pass-if "consp and atomp"
    (and (consp '(1 2 3)) (consp '(1 2 . 3)) (consp '(a . b))
         (not (consp '())) (not (consp 1)) (not (consp "abc"))
         (atomp 'a) (atomp '()) (atomp -1.5) (atomp "abc")
         (not (atomp '(1 . 2))) (not (atomp '(1)))))
  (pass-if "listp and nlistp"
    (and (listp '(1 2 3)) (listp '(1)) (listp '()) (listp '(1 . 2))
         (not (listp 'a)) (not (listp 42)) (nlistp 42)
         (not (nlistp '())) (not (nlistp '(1 2 3))) (not (nlistp '(1 . 2)))))
  (pass-if "null"
    (and (null '()) (not (null 1)) (not (null '(1 2))) (not (null '(1 . 2)))))

  (pass-if "car and cdr"
    (and (equal (car '(1 2 3)) 1) (equal (cdr '(1 2 3)) '(2 3))
         (equal (car '()) nil) (equal (cdr '()) nil)
         (equal (car '(1 . 2)) 1) (equal (cdr '(1 . 2)) 2)
         (null (cdr '(1)))))
  (pass-if "car-safe and cdr-safe"
    (and (equal (car-safe '(1 2)) 1) (equal (cdr-safe '(1 2)) '(2))
         (equal (car-safe 5) nil) (equal (cdr-safe 5) nil)))

  (pass-if "pop"
    (progn (setq mylist '(a b c))
           (setq value (pop mylist))
           (and (equal value 'a)
                (equal mylist '(b c)))))
  (pass-if-equal "push" '(a b c)
    (progn (setq mylist '(b c))
           (push 'a mylist)))

  (pass-if "nth and nthcdr"
    (and (equal (nth -5 '(1 2 3)) 1) (equal (nth 3 '(1 2 3)) nil)
         (equal (nth 0 '(1 2 3)) 1) (equal (nth 2 '(1 2 3)) 3)
         (equal (nthcdr -5 '(1 2 3)) '(1 2 3))
         (equal (nthcdr 4 '(1 2 3)) nil)
         (equal (nthcdr 1 '(1 2 3)) '(2 3))
         (equal (nthcdr 2 '(1 2 3)) '(3))))

  (pass-if "length"
    (and (= (length '()) 0)
         (= (length '(1 2 3 4 5)) 5)
         (= (length '(1 2 (3 4 (5)) 6)) 4)))

  (pass-if "cons, list and make-list"
    (and (equal (cons 1 2) '(1 . 2)) (equal (cons 1 '(2 3)) '(1 2 3))
         (equal (cons 1 '()) '(1))
         (equal (list 'a) '(a)) (equal (list) '()) (equal (list 1 2) '(1 2))
         (equal (make-list 3 42) '(42 42 42))
         (equal (make-list 0 1) '())))
  (pass-if "append"
    (and (equal (append '(1 2) '(3 4) '(5)) '(1 2 3 4 5))
         (equal (append '(1 2) 3) '(1 2 . 3))))
  (pass-if "reverse"
    (and (equal (reverse '(5 4 3 2 1)) '(1 2 3 4 5))
         (equal (reverse '()) '())))
  (pass-if "copy-tree"
    (progn (setq mylist '(1 2 (3 4)))
           (and (not (eq mylist (copy-tree mylist)))
                (equal mylist (copy-tree mylist)))))

  (pass-if "number-sequence"
    (and (equal (number-sequence 5) '(5))
         (equal (number-sequence 5 9) '(5 6 7 8 9))
         (equal (number-sequence 5 9 3) '(5 8))
         (equal (number-sequence 5 1 -2) '(5 3 1))
         (equal (number-sequence 5 8 -1) '())
         (equal (number-sequence 5 1) '())
         (equal (number-sequence 5 5 0) '(5))))

  (pass-if "setcar and setcdr"
    (progn (setq pair '(1 . 2))
           (setq copy pair)
           (setq a (setcar copy 3))
           (setq b (setcdr copy 4))
           (and (= a 3) (= b 4)
                (equal pair '(3 . 4))))))