0.8.3.47:
[sbcl.git] / tests / reader.pure.lisp
1 ;;;; tests related to the Lisp reader
2
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
6 ;;;; While most of SBCL is derived from the CMU CL system, the test
7 ;;;; files (like this one) were written from scratch after the fork
8 ;;;; from CMU CL.
9 ;;;; 
10 ;;;; This software is in the public domain and is provided with
11 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
12 ;;;; more information.
13
14 (in-package "CL-USER")
15
16 (assert (equal (symbol-name '#:|fd\sA|) "fdsA"))
17
18 ;;; Prior to sbcl-0.7.2.10, SBCL disobeyed the ANSI requirements on
19 ;;; returning NIL for unset dispatch-macro-character functions. (bug
20 ;;; 151, fixed by Alexey Dejenka sbcl-devel "bug 151" 2002-04-12)
21 (assert (not (get-dispatch-macro-character #\# #\{)))
22 (assert (not (get-dispatch-macro-character #\# #\0)))
23 ;;; And we might as well test that we don't have any cross-compilation
24 ;;; shebang residues left...
25 (assert (not (get-dispatch-macro-character #\# #\!)))
26 ;;; Also test that all the illegal sharp macro characters are
27 ;;; recognized as being illegal.
28 (loop for char in '(#\Backspace #\Tab #\Newline #\Linefeed
29                     #\Page #\Return #\Space #\) #\<)
30    do (assert (get-dispatch-macro-character #\# char)))
31
32 (assert (not (ignore-errors (get-dispatch-macro-character #\! #\0)
33                             t)))
34
35 ;;; In sbcl-0.7.3, GET-MACRO-CHARACTER and SET-MACRO-CHARACTER didn't
36 ;;; use NIL to represent the no-macro-attached-to-this-character case
37 ;;; as ANSI says they should. (This problem is parallel to the
38 ;;; GET-DISPATCH-MACRO misbehavior fixed in sbcl-0.7.2.10, but
39 ;;; was fixed a little later.)
40 (dolist (customizable-char
41          ;; According to ANSI "2.1.4 Character Syntax Types", these
42          ;; characters are reserved for the programmer.
43          '(#\? #\! #\[ #\] #\{ #\}))
44   ;; So they should have no macro-characterness.
45   (multiple-value-bind (macro-fun non-terminating-p)
46       (get-macro-character customizable-char)
47     (assert (null macro-fun))
48     ;; Also, in a bit of ANSI weirdness, NON-TERMINATING-P can be
49     ;; true only when MACRO-FUN is true. (When the character
50     ;; is not a macro character, it can be embedded in a token,
51     ;; so it'd be more logical for NON-TERMINATING-P to be T in
52     ;; this case; but ANSI says it's NIL in this case.
53     (assert (null non-terminating-p))))
54
55 ;;; rudimentary test of SET-SYNTAX-FROM-CHAR, just to verify that it
56 ;;; wasn't totally broken by the GET-MACRO-CHARACTER/SET-MACRO-CHARACTER
57 ;;; fixes in 0.7.3.16
58 (assert (= 123579 (read-from-string "123579")))
59 (let ((*readtable* (copy-readtable)))
60   (set-syntax-from-char #\7 #\;)
61   (assert (= 1235 (read-from-string "123579"))))
62
63 ;;; PARSE-INTEGER must signal an error of type PARSE-ERROR if it is
64 ;;; unable to parse an integer and :JUNK-ALLOWED is NIL.
65 (macrolet ((assert-parse-error (form)
66              `(multiple-value-bind (val cond)
67                   (ignore-errors ,form)
68                 (assert (null val))
69                 (assert (typep cond 'parse-error)))))
70   (assert-parse-error (parse-integer "    "))
71   (assert-parse-error (parse-integer "12 a"))
72   (assert-parse-error (parse-integer "12a"))
73   (assert-parse-error (parse-integer "a"))
74   (assert (= (parse-integer "12") 12))
75   (assert (= (parse-integer "   12   ") 12))
76   (assert (= (parse-integer "   12asdb" :junk-allowed t) 12)))
77
78 ;;; #A notation enforces that once one 0 dimension has been found, all
79 ;;; subsequent ones are also 0.
80 (assert (equal (array-dimensions (read-from-string "#3A()"))
81                '(0 0 0)))
82 (assert (equal (array-dimensions (read-from-string "#3A(())"))
83                '(1 0 0)))
84 (assert (equal (array-dimensions (read-from-string "#3A((() ()))"))
85                '(1 2 0)))
86
87 ;;; Bug reported by Nikodemus Siivola on sbcl-devel 2003-07-21:
88 ;;; package misconfiguration
89 (assert (eq
90          (handler-case (with-input-from-string (s "cl:") (read s))
91            (end-of-file (c)
92              'good))
93          'good))
94
95 ;;; Bugs found by Paul Dietz
96 (assert (equal (multiple-value-list
97                 (parse-integer "   123      "))
98                '(123 12)))
99
100 (let* ((base "xxx 123  yyy")
101        (intermediate (make-array 8 :element-type (array-element-type base)
102                                  :displaced-to base
103                                  :displaced-index-offset 2))
104        (string (make-array 6 :element-type (array-element-type base)
105                            :displaced-to intermediate
106                            :displaced-index-offset 1)))
107   (assert (equal (multiple-value-list
108                   (parse-integer string))
109                  '(123 6))))