(should (not (proper-list-p (make-bool-vector 0 nil))))
(should (not (proper-list-p (make-symbol "a")))))
+(ert-deftest test-hash-table ()
+ (let ((h (make-hash-table))
+ (val "anything"))
+ (puthash 123 val h)
+ (should (eq (gethash 123 h) val)))
+ (let ((h (make-hash-table :test 'equal))
+ (val "anything"))
+ (puthash '("hello" 123) val h)
+ (should (eq (gethash '("hello" 123) h) val))))
+
+(ert-deftest test-hash-table-wrong-keywords ()
+ (should (make-hash-table :purecopy t)) ; obsolete and ignored
+ (should (make-hash-table :rehash-size 123)) ; obsolete and ignored
+ (should (make-hash-table :rehash-threshold 123)) ; obsolete and ignored
+ (should-error (make-hash-table :some-random-keyword 123)))
+
+(ert-deftest test-remhash ()
+ (let ((h (make-hash-table))
+ (val "anything"))
+ (puthash 'foo val h)
+ (remhash 'foo h)
+ (should-not (gethash 'foo h))))
+
+(ert-deftest test-clrhash ()
+ (let ((h (make-hash-table)))
+ (puthash 'foo1 'bar1 h)
+ (puthash 'foo2 'bar2 h)
+ (puthash 'foo3 'bar3 h)
+ (puthash 'foo4 'bar4 h)
+ (clrhash h)
+ (should-not (gethash 'foo h))))
+
+(ert-deftest test-hash-table-p ()
+ (let ((h (make-hash-table)))
+ (should (hash-table-p h)))
+ (should-not (hash-table-p 123))
+ (should-not (hash-table-p "foo"))
+ (should-not (hash-table-p [foo]))
+ (should-not (hash-table-p (list 'foo))))
+
+(ert-deftest test-hash-table-count ()
+ (let ((h (make-hash-table)))
+ (puthash 'foo1 'bar1 h)
+ (should (= (hash-table-count h) 1))
+ (puthash 'foo2 'bar2 h)
+ (should (= (hash-table-count h) 2))
+ (puthash 'foo3 'bar3 h)
+ (should (= (hash-table-count h) 3))
+ (puthash 'foo4 'bar4 h)
+ (should (= (hash-table-count h) 4))
+ (clrhash h)
+ (should (= (hash-table-count h) 0))))
+
+(ert-deftest test-maphash ()
+ (let ((h (make-hash-table))
+ (sum 0))
+ (puthash 'foo1 1 h)
+ (puthash 'foo2 22 h)
+ (puthash 'foo3 333 h)
+ (puthash 'foo4 4444 h)
+ (maphash (lambda (_key value) (incf sum value)) h)
+ (should (= sum 4800))))
+
+(ert-deftest test-copy-hash-table ()
+ (let* ((h1 (make-hash-table))
+ h2)
+ (puthash 'foo '(bar baz) h1)
+ (setq h2 (copy-hash-table h1))
+ (should-not (eq h1 h2))
+ (should (equal (gethash 'foo h2) '(bar baz)))))
+
(ert-deftest test-hash-function-that-mutates-hash-table ()
(define-hash-table-test 'badeq 'eq 'bad-hash)
(let ((h (make-hash-table :test 'badeq :size 1 :rehash-size 1)))