comparison tests/automated/lisp-reader-tests.el @ 5904:ee27ca517e90

Revise print_symbol(), never calling is{float,ratio}_string(). src/ChangeLog addition: 2015-05-08 Aidan Kehoe <kehoea@parhasard.net> * print.c (print_symbol): Revise this. No longer call isfloat_string() and isratio_string() on practically every symbol seen; check explicitly for the known float format in this function, which turns out to be a more limited and cheap job than you would think. Also check for integer and ratio syntax in passing. Use Vdigit_fixnum_map when working out whether a given character is a digit. * lisp.h: Make Vdigit_fixnum_map available generally. tests/ChangeLog addition: 2015-05-08 Aidan Kehoe <kehoea@parhasard.net> * automated/lisp-reader-tests.el: Check read and print handling of symbols that look like numbers. In passing, check the read and print handling of the associated numbers.
author Aidan Kehoe <kehoea@parhasard.net>
date Fri, 08 May 2015 14:33:46 +0100
parents cc7f8a0e569a
children 6174848f3e6c
comparison
equal deleted inserted replaced
5903:5afddd952c46 5904:ee27ca517e90
153 (when (featurep 'bignum) 153 (when (featurep 'bignum)
154 (Assert (null (list-length (read (format "#%d=(1 #1=(5) 3 4 . #%d#)" 154 (Assert (null (list-length (read (format "#%d=(1 #1=(5) 3 4 . #%d#)"
155 (+ most-positive-fixnum 2) 155 (+ most-positive-fixnum 2)
156 (+ most-positive-fixnum 2))))) 156 (+ most-positive-fixnum 2)))))
157 "checking bignum object labels don't wrap on reading")) 157 "checking bignum object labels don't wrap on reading"))
158
159 (Assert (not (eq (intern "") (read (prin1-to-string (make-symbol "")))))
160 "checking uninterned zero-length symbol printed distinctly")
161
162 ;; Check the read and print handling of symbols that look like numbers. In
163 ;; passing, check the read and print handling of the associated numbers.
164 (Assert (eql (log 1) '0e0) "checking float syntax with e accepted")
165 (Assert (eql (log 1) 0.0) "checking float syntax with decimal point accepted")
166 (Assert (not (ratiop (read "2/-3")))
167 "ratios can't have a negative sign in the denominator")
168 (Assert (not (ratiop (read "2/+3")))
169 "ratios can't have a positive sign in the denominator")
170
171 (macrolet
172 ((Assert-no-symbol-number-confusion (&rest values)
173 `(let ((print-gensym t)
174 (print-readably t))
175 ,@(loop
176 for (type . rest) in values
177 collect (cons
178 'progn
179 (loop for string in rest
180 collect
181 `(progn
182 (Assert (symbolp (read (prin1-to-string
183 (make-symbol ,string)))))
184 (Assert (equal (symbol-name
185 (read (prin1-to-string
186 (make-symbol ,string))))
187 ,string))
188 ,@(when (ignore-errors (coerce-number 1 type))
189 `((Assert (typep (read ,string)
190 ',type))
191 (Assert (eql (string-to-number
192 ,string)
193 (read ,string))))))))))))
194 (Assert-no-symbol-number-confusion
195 (float "0.0" "0E0" "-.0" "0.0e0" "3.1415926535897932384E0"
196 "6.02E+23" "602E+21" "3.010299957e-1" "-0.000000001e9")
197 (fixnum "1" "1." "1073741823" "-1" "-1073741824")
198 (ratio "1/2" "2/5" "-1073741822/1073741823"
199 "+2/3" "-3/2"
200 "2894802230932904885589274625217197696331749616641014100986439600\
201 1978282409984/20"
202 "+289480223093290488558927462521719769633174961664101410098643960\
203 01978282409984/20"
204 "-289480223093290488558927462521719769633174961664101410098643960\
205 01978282409984/20"
206 "20/2894802230932904885589274625217197696331749616641014100986439\
207 6001978282409984"
208 "+20/289480223093290488558927462521719769633174961664101410098643\
209 96001978282409984"
210 "-20/289480223093290488558927462521719769633174961664101410098643\
211 96001978282409984")
212 ;; These two are (lsh 1 254) and (lognot (lsh 1 254)). The assumption that
213 ;; they are always bignums if they can be made into rationals should hold
214 ;; for another couple of processor generations at least.
215 (bignum
216 "2894802230932904885589274625217197696331749616641014100986439600197828\
217 2409984"
218 "-289480223093290488558927462521719769633174961664101410098643960019782\
219 82409985")))