0.9.2.25:
[sbcl.git] / tests / reader.impure.lisp
index 46be9f9..1d90ae1 100644 (file)
 (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))))
+
 ;;; success
 (quit :unix-status 104)