;;; tests/reader-smoke.el --- exercise src/reader.lisp under elisp -*- lexical-binding: t -*- ;; ;; Copyright (C) 2026 Anthony Green ;; SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 ;; ;; Quick smoke driver: load src/reader.lisp in the elisp host and parse ;; a few sample inputs, printing the result. Intended to be run from ;; the repo root via ;; ;; emacs --batch -l tests/reader-smoke.el ;; ;; Exits 0 on every printed result OK; non-zero on elisp error. (require 'cl-lib) (defvar funcl-test-root (file-name-directory (directory-file-name (file-name-directory (or load-file-name buffer-file-name))))) (load (expand-file-name "elisp/compat.el" funcl-test-root) nil 'nomessage) (load (expand-file-name "src/cold/buffer.lisp" funcl-test-root) nil 'nomessage) (load (expand-file-name "src/cold/reader.lisp" funcl-test-root) nil 'nomessage) (defun reader-smoke--bv-from-string (s) "Pack each byte of S into a fresh byte-vector and return it." (let ((bv (make-byte-vector))) (dotimes (i (length s)) (byte-vector-push bv (aref s i))) bv)) (defun reader-smoke--bv-to-string (bv) "Render BV (a byte-vector) as an emacs string for display." (with-current-buffer bv (buffer-substring-no-properties (point-min) (point-max)))) (defun reader-smoke--pp (x) "Render a reader-produced value for display. Byte-vectors come back as the buffer object itself, which is unreadable; convert them to their string form so the eyeball check is meaningful." (cond ((null x) "nil") ((bufferp x) (format "" (reader-smoke--bv-to-string x))) ((consp x) (concat "(" (mapconcat #'reader-smoke--pp x " ") ")")) (t (format "%S" x)))) (defun reader-smoke--run (label input) (let* ((bv (reader-smoke--bv-from-string input)) (forms (reader-read-all-from-bv bv))) (princ (format "%-24s %-40s → %s\n" label (format "%S" input) (reader-smoke--pp forms))))) (reader-smoke--run "integer" "42") (reader-smoke--run "negative" "-17") (reader-smoke--run "explicit-plus" "+99") (reader-smoke--run "symbol" "foo") (reader-smoke--run "list of ints" "(1 2 3)") (reader-smoke--run "nested" "(a (b c) d)") (reader-smoke--run "quoted" "'foo") (reader-smoke--run "quoted list" "'(a b c)") (reader-smoke--run "string" "\"hello\"") (reader-smoke--run "string with esc" "\"a\\nb\"") (reader-smoke--run "comment" "; this is a comment\n42") (reader-smoke--run "multi forms" "1 2 3") (reader-smoke--run "defun-shape" "(defun add (a b) (+ a b))") (reader-smoke--run "complex" "(defun fact (n) (if (= n 0) 1 (* n (fact (- n 1)))))") (kill-emacs 0) ;;; reader-smoke.el ends here