mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-03-27 01:01:52 -07:00
Add test for weak hash tables
The current implementation doesn't pass this test. The weak hash table pcase--memoize is a real world example where this matters. * test/src/fns-tests.el (ft-ephemeron-table): New test. (ft--test-ephemeron-table): New helper.
This commit is contained in:
parent
005f908680
commit
f6c32b3dba
1 changed files with 16 additions and 0 deletions
|
|
@ -1389,6 +1389,22 @@
|
|||
(dolist (test '(eq eql equal))
|
||||
(ft--test-weak-fixnums w test))))
|
||||
|
||||
;; Emacs's weak hash tables work like ephemerons: if an object is only
|
||||
;; reachable through a weak hash table, then the object should be
|
||||
;; collected.
|
||||
(defun ft--test-ephemeron-table (weakness)
|
||||
(let* ((h (make-hash-table :weakness weakness :test 'eq))
|
||||
(n 1000))
|
||||
(dotimes (i n)
|
||||
(let* ((obj (cons 'a i)))
|
||||
(puthash obj obj h)))
|
||||
(ft--gc weakness)
|
||||
(should (< (hash-table-count h) n))))
|
||||
|
||||
(ert-deftest ft-ephemeron-table ()
|
||||
(dolist (w '(key value key-and-value key-or-value))
|
||||
(ft--test-ephemeron-table w)))
|
||||
|
||||
|
||||
|
||||
(ert-deftest test-hash-function-that-mutates-hash-table ()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue