X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=tests%2Freader.impure.lisp;h=8b60a5ded2ebd3f5e1598e90aab952f3a33c4c4c;hb=dafb0472097d387a668b0f84bef3abc3a84e0b1d;hp=c3c8f4ea66201aeebb4c58a7daea370b9191b07a;hpb=50f728671defadb8f7b1e8691c984cb0e6aba17c;p=sbcl.git diff --git a/tests/reader.impure.lisp b/tests/reader.impure.lisp index c3c8f4e..8b60a5d 100644 --- a/tests/reader.impure.lisp +++ b/tests/reader.impure.lisp @@ -8,7 +8,7 @@ ;;;; While most of SBCL is derived from the CMU CL system, the test ;;;; files (like this one) were written from scratch after the fork ;;;; from CMU CL. -;;;; +;;;; ;;;; This software is in the public domain and is provided with ;;;; absolutely no warranty. See the COPYING and CREDITS files for ;;;; more information. @@ -62,9 +62,51 @@ ;;; CSR managed to break the #S reader macro in the process of merging ;;; SB-PCL:CLASS and CL:CLASS -- make sure it works (defstruct readable-struct a) -(assert (eq (readable-struct-a - (read-from-string "#S(READABLE-STRUCT :A T)")) - t)) +(macrolet + ((frob (string) + `(assert (eq (readable-struct-a (read-from-string ,string)) t)))) + (frob "#S(READABLE-STRUCT :A T)") + (frob "#S(READABLE-STRUCT A T)") + (frob "#S(READABLE-STRUCT \"A\" T)") + (frob "#S(READABLE-STRUCT #\\A T)") + (frob "#S(READABLE-STRUCT #\\A T :A NIL)")) +(macrolet + ((frob (string) + `(assert (raises-error? (read-from-string ,string) reader-error)))) + (frob "#S(READABLE-STRUCT . :A)") + (frob "#S(READABLE-STRUCT :A . T)") + (frob "#S(READABLE-STRUCT :A T . :A)") + (frob "#S(READABLE-STRUCT :A T :A . T)")) + +;;; reported by Henrik Motakef +(defpackage "") +(assert (eq (symbol-package (read-from-string "||::FOO")) + (find-package ""))) + +;;; test nested reads, test case by Helmut Eller for cmucl +(defclass my-in-stream (sb-gray:fundamental-character-input-stream) + ((last-char :initarg :last-char))) + +(let ((string " a ") + (i 0)) + (defmethod sb-gray:stream-read-char ((s my-in-stream)) + (with-input-from-string (s "b") (read s)) + (with-slots (last-char) s + (cond (last-char (prog1 last-char (setf last-char nil))) + (t (prog1 (aref string i) + (setq i (mod (1+ i) (length string))))))))) + +(defmethod sb-gray:stream-unread-char ((s my-in-stream) char) + (setf (slot-value s 'last-char) char) + nil) + +(assert (eq 'a (read (make-instance 'my-in-stream :last-char nil)))) + +;;; NIL as the last argument to SET-SYNTAX-FROM-CHAR in compiled code, +;;; reported by Levente Mészáros +(let ((fun (compile nil '(lambda () + (set-syntax-from-char #\{ #\( *readtable* nil))))) + (funcall fun) + (assert (equal '(:ok) (read-from-string "{:ok)")))) ;;; success -(quit :unix-status 104)