728722a1064a9afff2bd323fab681bdb7d52cad7
[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"))))