aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric S. Raymond2026-02-25 19:03:02 -0500
committerEric S. Raymond2026-02-25 19:03:02 -0500
commitd7a3d442b4cdfd88447eec49339dfa5d69342de9 (patch)
tree95c5edaca3faa931ffcbbccbefce37316fb3e8c2
parentcd038e5617ff940ead880fbc9c1df95e61453246 (diff)
downloademacs-d7a3d442b4cdfd88447eec49339dfa5d69342de9.tar.gz
emacs-d7a3d442b4cdfd88447eec49339dfa5d69342de9.zip
Tests for the lreaf.c amd print.c primitives.
-rw-r--r--test/src/lread-tests.el46
-rw-r--r--test/src/print-tests.el40
2 files changed, 86 insertions, 0 deletions
diff --git a/test/src/lread-tests.el b/test/src/lread-tests.el
index e621a9d58b9..50281471389 100644
--- a/test/src/lread-tests.el
+++ b/test/src/lread-tests.el
@@ -504,4 +504,50 @@ literals (Bug#20852)."
504 (should (equal (oa-syms oa) (list s2)))) 504 (should (equal (oa-syms oa) (list s2))))
505 )) 505 ))
506 506
507(ert-deftest lread-tests--get-load-suffixes ()
508 (let ((load-suffixes '(".el" ".elc"))
509 (load-file-rep-suffixes '("" ".gz")))
510 (should (equal (get-load-suffixes)
511 '(".el" ".el.gz" ".elc" ".elc.gz")))))
512
513(ert-deftest lread-tests--locate-file-internal ()
514 (let* ((dir (make-temp-file "lread-tests" t))
515 (file (expand-file-name "foo.el" dir))
516 (subdir (expand-file-name "bar" dir)))
517 (unwind-protect
518 (progn
519 (with-temp-file file)
520 (make-directory subdir)
521 (should (equal (locate-file-internal "foo" (list dir) '(".el") nil)
522 file))
523 (should-not (locate-file-internal "bar" (list dir) nil nil))
524 (should (equal (locate-file-internal
525 "bar" (list dir) nil
526 (lambda (path)
527 (if (file-directory-p path) 'dir-ok
528 (file-readable-p path))))
529 subdir)))
530 (ignore-errors (delete-file file))
531 (ignore-errors (delete-directory subdir))
532 (ignore-errors (delete-directory dir)))))
533
534(ert-deftest lread-tests--internal-obarray-buckets ()
535 (let* ((oa (obarray-make 7))
536 (s1 (intern "alpha" oa))
537 (s2 (intern "beta" oa))
538 (s3 (intern "gamma" oa))
539 (buckets (internal--obarray-buckets oa))
540 (flat nil)
541 (expected (list s1 s2 s3)))
542 (dolist (bucket buckets)
543 (dolist (sym bucket)
544 (push sym flat)))
545 (should (= (length flat) (length (delete-dups (copy-sequence flat)))))
546 (setq flat (sort flat (lambda (a b)
547 (string< (symbol-name a) (symbol-name b)))))
548 (setq expected (sort (copy-sequence expected)
549 (lambda (a b)
550 (string< (symbol-name a) (symbol-name b)))))
551 (should (equal flat expected))))
552
507;;; lread-tests.el ends here 553;;; lread-tests.el ends here
diff --git a/test/src/print-tests.el b/test/src/print-tests.el
index 1485e063ab3..033049afbdf 100644
--- a/test/src/print-tests.el
+++ b/test/src/print-tests.el
@@ -570,5 +570,45 @@ otherwise, use a different charset."
570 (should (equal (prin1-to-string (make-symbol "th\303\251")) 570 (should (equal (prin1-to-string (make-symbol "th\303\251"))
571 (string-to-multibyte "th\303\251")))) 571 (string-to-multibyte "th\303\251"))))
572 572
573(ert-deftest print-tests--write-char ()
574 (should (equal (with-output-to-string (write-char ?A)) "A"))
575 (let (out)
576 (should (= (write-char ?Z (lambda (c)
577 (setq out (concat out (string c)))))
578 ?Z))
579 (should (equal out "Z"))))
580
581(ert-deftest print-tests--redirect-debugging-output ()
582 (let ((file (make-temp-file "print-tests-debug")))
583 (unwind-protect
584 (progn
585 (redirect-debugging-output file nil)
586 (external-debugging-output ?A)
587 (external-debugging-output ?B)
588 (redirect-debugging-output nil)
589 (should (equal (with-temp-buffer
590 (insert-file-contents file)
591 (buffer-string))
592 "AB")))
593 (ignore-errors (redirect-debugging-output nil))
594 (ignore-errors (delete-file file)))))
595
596(ert-deftest print-tests--preprocess ()
597 (let* ((x (list 1 2))
598 (obj (list x x))
599 (print-circle t)
600 (print-number-table nil))
601 (print--preprocess obj)
602 (should (hash-table-p print-number-table))
603 (should (> (hash-table-count print-number-table) 0))
604 (should (gethash x print-number-table)))
605 (let* ((x (list 1 2))
606 (obj (list x x))
607 (print-circle nil)
608 (print-number-table (make-hash-table :test 'eq)))
609 (puthash 'sentinel 'value print-number-table)
610 (print--preprocess obj)
611 (should (eq (gethash 'sentinel print-number-table) 'value))))
612
573(provide 'print-tests) 613(provide 'print-tests)
574;;; print-tests.el ends here 614;;; print-tests.el ends here