0.7.7.31:
[sbcl.git] / tests / reader.impure.lisp
1 ;;;; tests related to the Lisp reader
2
3 ;;;; This file is impure because we want to modify the readtable and stuff.
4
5 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; more information.
7 ;;;;
8 ;;;; While most of SBCL is derived from the CMU CL system, the test
9 ;;;; files (like this one) were written from scratch after the fork
10 ;;;; from CMU CL.
11 ;;;; 
12 ;;;; This software is in the public domain and is provided with
13 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
14 ;;;; more information.
15
16 (in-package :cl-user)
17
18 (load "assertoid.lisp")
19
20 ;;; Bug 30, involving mistakes in binding the read table, made this
21 ;;; code fail.
22 (defun read-vector (stream char)
23   (declare (ignorable char))
24   (coerce (read-delimited-list #\] stream t) 'vector))
25 (set-macro-character #\[ #'read-vector nil)
26 (set-macro-character #\] (get-macro-character #\)) nil)
27 (multiple-value-bind (res pos)
28     (read-from-string "[1 2 3]") ; ==> #(1 2 3), 7
29   (assert (equalp res #(1 2 3)))
30   (assert (= pos 7)))
31 (multiple-value-bind (res pos)
32     (read-from-string "#\\x") ; ==> #\x, 3
33   (assert (equalp res #\x))
34   (assert (= pos 3)))
35 (multiple-value-bind (res pos)
36     (read-from-string "[#\\x]")
37   (assert (equalp res #(#\x)))
38   (assert (= pos 5)))
39
40 ;;; Bug 51b. (try to throw READER-ERRORs when the reader encounters
41 ;;; dubious input)
42 (assert (raises-error? (read-from-string "1e1000") reader-error))
43 (assert (raises-error? (read-from-string "1/0") reader-error))
44
45 ;;; success
46 (quit :unix-status 104)