X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=tests%2Freader.impure.lisp;h=1db35cac17c3b7706e6b9d366c33f7e9f5523cb2;hb=7ff2233608f1f110e112ae576fa829618ce181ae;hp=5b35f78e0a36b0308568acfddaa0db93d3997bf6;hpb=175c318c892b0627b36fa3c4db66f59680242204;p=sbcl.git diff --git a/tests/reader.impure.lisp b/tests/reader.impure.lisp index 5b35f78..1db35ca 100644 --- a/tests/reader.impure.lisp +++ b/tests/reader.impure.lisp @@ -58,6 +58,22 @@ (read-from-string "#1=[#1#]") (assert (eq (value res) res)) (assert (= pos 8))) +;;; much, much, later (in Feb 2007), CSR noticed that the problem +;;; still exists for funcallable instances. +(defclass funcallable-box (box sb-mop:funcallable-standard-object) () + (:metaclass sb-mop:funcallable-standard-class)) +(defun read-funcallable-box (stream char) + (declare (ignore char)) + (let ((objects (read-delimited-list #\} stream t))) + (unless (= 1 (length objects)) + (error "Unknown box reader syntax")) + (make-instance 'funcallable-box :value (first objects)))) +(set-macro-character #\{ 'read-funcallable-box) +(set-syntax-from-char #\} #\)) +(multiple-value-bind (res pos) + (read-from-string "#1={#1#}") + (assert (eq (value res) res)) + (assert (= pos 8))) ;;; CSR managed to break the #S reader macro in the process of merging ;;; SB-PCL:CLASS and CL:CLASS -- make sure it works @@ -102,4 +118,61 @@ (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)")))) + +(with-test (:name :bad-recursive-read) + ;; This use to signal an unbound-variable error instead. + (assert (eq :error + (handler-case + (with-input-from-string (s "42") + (read s t nil t)) + (reader-error (e) + :error))))) + +(with-test (:name :standard-readtable-modified) + (macrolet ((test (form &optional op) + `(assert + (eq :error + (handler-case + (progn ,form t) + (sb-int:standard-readtable-modified-error (e) + ,@(when op + `((assert + (equal ,op (sb-kernel::standard-readtable-modified-operation e))))) + :error)))))) + (let ((rt *readtable*)) + (with-standard-io-syntax + (let ((srt *readtable*)) + (test (setf (readtable-case srt) :preserve) '(setf readtable-case)) + (test (copy-readtable rt srt) 'copy-readtable) + (test (set-syntax-from-char #\a #\a srt rt) 'set-syntax-from-char) + (test (set-macro-character #\a (constantly t) t srt) 'set-macro-character) + (test (make-dispatch-macro-character #\! t srt)) + (test (set-dispatch-macro-character #\# #\a (constantly t) srt) 'set-dispatch-macro-character)))))) + +(with-test (:name :reader-package-errors) + (flet ((test (string) + (handler-case + (progn (read-from-string string) :feh) + (error (e) + (when (and (typep e 'reader-error) (typep e 'package-error)) + (package-error-package e)))))) + (assert (equal "NO-SUCH-PKG" (test "no-such-pkg::foo"))) + (assert (eq (find-package :cl) (test "cl:no-such-sym"))))) + +;;; THIS SHOULD BE LAST as it frobs the standard readtable +(with-test (:name :set-macro-character-nil) + (handler-bind ((sb-int:standard-readtable-modified-error #'continue)) + (let ((fun (lambda (&rest args) 'ok))) + ;; NIL means the standard readtable. + (assert (eq t (set-macro-character #\~ fun nil nil))) + (assert (eq fun (get-macro-character #\~ nil))) + (assert (eq t (set-dispatch-macro-character #\# #\~ fun nil))) + (assert (eq fun (get-dispatch-macro-character #\# #\~ nil)))))) + ;;; success