2,180 changes: 1,191 additions & 989 deletions src/lread.c

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions test/src/lread-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,40 @@ literals (Bug#20852)."
(should (equal (lread-test-read-and-print str) str))))
(should-error (read-from-string "#1=#1#") :type 'invalid-read-syntax))

(ert-deftest lread-deeply-nested ()
;; Check that we can read a deeply nested data structure correctly.
(let ((levels 10000)
(prefix nil)
(suffix nil))
(dotimes (_ levels)
(push "([#s(r " prefix)
(push ")])" suffix))
(let ((str (concat (apply #'concat prefix)
"a"
(apply #'concat suffix))))
(let* ((read-circle t)
(result (read-from-string str)))
(should (equal (cdr result) (length str)))
;; Check the result. (We can't build a reference value and compare
;; using `equal' because that function is currently depth-limited.)
(named-let check ((x (car result)) (level 0))
(if (equal level levels)
(should (equal x 'a))
(should (and (consp x) (null (cdr x))))
(let ((x2 (car x)))
(should (and (vectorp x2) (equal (length x2) 1)))
(let ((x3 (aref x2 0)))
(should (and (recordp x3) (equal (length x3) 2)
(equal (aref x3 0) 'r)))
(check (aref x3 1) (1+ level))))))))))

(ert-deftest lread-misc ()
;; Regression tests for issues found and fixed in bug#55676:
;; Non-breaking space after a dot makes it a dot token.
(should (equal (read-from-string "(a .\u00A0b)")
'((a . b) . 7)))
;; #_ without symbol following is the interned empty symbol.
(should (equal (read-from-string "#_")
'(## . 2))))

;;; lread-tests.el ends here