X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=tests%2Fhash.impure.lisp;h=dfbb9c4ff4227ac360f1cf9110753ab23c622be5;hb=794cf077e3b1d4368f1103f393a4a56abd09e72a;hp=42dbcbd85a70303cf7b37a956291040b5ed9ec41;hpb=99bcb3a92b44ce343586f8bd7c717d665f31f4ad;p=sbcl.git diff --git a/tests/hash.impure.lisp b/tests/hash.impure.lisp index 42dbcbd..dfbb9c4 100644 --- a/tests/hash.impure.lisp +++ b/tests/hash.impure.lisp @@ -51,7 +51,19 @@ (complex 1.0 2.0) (complex 1.0d0 2.0) (complex 1.5 -3/2) (complex 1.5 -1.5d0) - #\x #\X #\*)) + #\x #\X #\* + + (copy-seq "foo") (copy-seq "foobar") (copy-seq "foobarbaz") + + (copy-seq #*) + (copy-seq #*0) (copy-seq #*1) + (copy-seq #*00) (copy-seq #*10) + (copy-seq #*01) (copy-seq #*11) + (copy-seq #*10010) (copy-seq #*100101) (bit-not #*01101) + (make-array 6 :fill-pointer 6 + :element-type 'bit :initial-contents #*100101) + + #'allocate-instance #'no-applicable-method)) (make-psxhash-extra-subtests () (list (copy-seq "") (copy-seq #*) @@ -178,11 +190,17 @@ ;; that the SXHASH distribution changes, not once every time the ;; tests are run.) (dolist (i sxhash-tests) - (unless (typep (sxhash i) '(and fixnum unsigned-byte)) + (declare (notinline funcall)) + (unless (typep (funcall #'sxhash i) '(and fixnum unsigned-byte)) (error "bad SXHASH behavior for ~S" i)) (dolist (j sxhash-tests) - (unless (eq (t->boolean (equal i j)) - (t->boolean (= (sxhash i) (sxhash j)))) + (unless (or (eq (t->boolean (equal i j)) + (t->boolean (= (sxhash i) (sxhash j)))) + (and (typep i 'number) + (typep j 'number) + (= i j) + (subtypep (type-of i) (type-of j)) + (subtypep (type-of j) (type-of i)))) ;; (If you get a surprising failure here, maybe you were ;; just very unlucky; see the notes above.) (error "bad SXHASH behavior for ~S ~S" i j)))) @@ -197,5 +215,46 @@ (error "bad PSXHASH behavior for ~S ~S" i j)))) ))) +;;; As of sbcl-0.6.12.10, writing hash tables readably should work. +;;; This isn't required by the ANSI standard, but it should be, since +;;; it's well-defined useful behavior which ANSI prohibits the users +;;; from implementing themselves. (ANSI says the users can't define +;;; their own their own PRINT-OBJECT (HASH-TABLE T) methods, and they +;;; can't even wiggle out of it by subclassing HASH-TABLE or STREAM.) +(let ((original-ht (make-hash-table :test 'equal :size 111)) + (original-keys '(1 10 11 400030002 -100000000))) + (dolist (key original-keys) + (setf (gethash key original-ht) + (expt key 4))) + (let* ((written-ht (with-output-to-string (s) + (write original-ht :stream s :readably t))) + (read-ht (with-input-from-string (s written-ht) + (read s)))) + (assert (= (hash-table-count read-ht) + (hash-table-count original-ht) + (length original-keys))) + (assert (eql (hash-table-test original-ht) (hash-table-test read-ht))) + (assert (eql (hash-table-size original-ht) (hash-table-size read-ht))) + (dolist (key original-keys) + (assert (eql (gethash key read-ht) + (gethash key original-ht)))))) + +;;; NIL is both SYMBOL and LIST +(dolist (fun '(sxhash sb-impl::psxhash)) + (assert (= (eval `(,fun nil)) + (funcall fun nil) + (funcall (compile nil `(lambda (x) + (declare (symbol x)) + (,fun x))) + nil) + (funcall (compile nil `(lambda (x) + (declare (list x)) + (,fun x))) + nil) + (funcall (compile nil `(lambda (x) + (declare (null x)) + (,fun x))) + nil)))) + ;;; success (quit :unix-status 104)