reader support for ## and #=
[jscl.git] / tests / read.lisp
1 ;; TODO: Uncomment when either read-from-string supports all these parameters
2 ;; or when test macro supports error handling, whichever comes first
3 ;; (test (equal (read-from-string " 1 3 5" t nil :start 2) (values 3 5)))
4 (expected-failure
5  (equal (multiple-value-list (read-from-string "(a b c)"))
6         '((A B C) 7)))
7
8 (test (equal (symbol-name (read-from-string "cl:cond")) "COND"))
9 (test (equal (symbol-name (read-from-string "co|N|d")) "COND"))
10 (test (equal (symbol-name (read-from-string "abc\\def")) "ABCdEF"))
11 (test (equal (symbol-name (read-from-string "|.|")) "."))
12 (test (equal (read-from-string "(1 .25)") '(1 0.25)))
13 (test (equal (read-from-string ".25") 0.25))
14 (test (equal (read-from-string "(1 . 25)") '(1 . 25)))
15
16 (test (equal (read-from-string "(#1=99 2 3 #1#)") '(99 2 3 99)))
17 (test (equal (read-from-string "#(#1=99 2 3 #1#)") '#(99 2 3 99)))
18
19 (test (let ((x (read-from-string "#1=(42 . #1#)")))
20         (and (eql (nth 99 x) 42)
21              (progn
22                (rplaca x 13)
23                (eql (nth 99 x) 13))
24              (eq x (cdr x)))))
25
26 (test (let ((x (read-from-string "#1=#(1 #2=99 #1# #2#)")))
27         (and (eql (aref x 0) 1)
28              (eql (aref x 1) 99)
29              (eq (aref x 2) x)
30              (eql (aref x 3) 99))))
31
32 (test (let ((x (read-from-string "#1=(1 2 #2=#(3 4 #1#) 5 #2#)")))
33         (and (eql (nth 0 x) 1)
34              (eql (nth 1 x) 2)
35              (eql (aref (nth 2 x) 0) 3)
36              (eql (aref (nth 2 x) 1) 4)
37              (eq (aref (nth 2 x) 2) x)
38              (eql (nth 3 x) 5)
39              (eq (nth 4 x) (nth 2 x)))))
40