aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJacob S. Gordon2025-05-19 15:05:37 -0400
committerEli Zaretskii2025-06-14 17:07:19 +0300
commit5bd9fa084dcf0ce8efaaf9212c24addec48d824f (patch)
treee032a62cd687f5a15d24595684bfd1d16647e0ae /test
parent82766b71a45a691e19386422d3a12a3e0321b2e8 (diff)
downloademacs-5bd9fa084dcf0ce8efaaf9212c24addec48d824f.tar.gz
emacs-5bd9fa084dcf0ce8efaaf9212c24addec48d824f.zip
calc: Allow strings with character codes above Latin-1
The current behavior of the functions 'calc-display-strings', 'strings', and 'bstrings' is to skip any vector containing integers outside the Latin-1 range (0x00-0xFF). We introduce a custom variable 'calc-string-maximum-character' to replace this hard-coded maximum, and to allow vectors containing higher character codes to be displayed as strings. The default value of 0xFF preserves the existing behavior. * lisp/calc/calc.el (calc-string-maximum-character): Add custom variable 'calc-string-maximum-character'. * lisp/calc/calccomp.el (math-vector-is-string): Replace hard-coded maximum with 'calc-string-maximum-character', and the 'natnump' assertion with 'characterp'. The latter guards against the maximum being larger than '(max-char)', but not on invalid types of the maximum such as strings. * test/lisp/calc/calc-tests.el (calc-math-vector-is-string): Add tests for 'math-vector-is-string' using different values of 'calc-string-maximum-character'. * doc/misc/calc.texi (Quick Calculator, Strings, Customizing Calc): Add variable definition for 'calc-string-maximum-character' and reference thereof when discussing 'calc-display-strings'. Generalize a comment about string display and availability of 8-bit fonts. (Bug#78528)
Diffstat (limited to 'test')
-rw-r--r--test/lisp/calc/calc-tests.el67
1 files changed, 67 insertions, 0 deletions
diff --git a/test/lisp/calc/calc-tests.el b/test/lisp/calc/calc-tests.el
index 42eb6077b04..2fd6a6be45e 100644
--- a/test/lisp/calc/calc-tests.el
+++ b/test/lisp/calc/calc-tests.el
@@ -879,5 +879,72 @@ An existing calc stack is reused, otherwise a new one is created."
879 (should-error (math-read-preprocess-string nil)) 879 (should-error (math-read-preprocess-string nil))
880 (should-error (math-read-preprocess-string 42))) 880 (should-error (math-read-preprocess-string 42)))
881 881
882(ert-deftest calc-math-vector-is-string ()
883 "Test `math-vector-is-string' with varying `calc-string-maximum-character'.
884
885All tests operate on both an integer vector and the corresponding
886complex vector. The sets covered are:
887
8881. `calc-string-maximum-character' is a valid character. The last case
889with `0x3FFFFF' is borderline, as integers above it will not make it
890past the `characterp' test.
8912. `calc-string-maximum-character' is negative, so the test always fails.
8923. `calc-string-maximum-character' is above `(max-char)', so only the
893first `characterp' test is active.
8944. `calc-string-maximum-character' has an invalid type, which triggers
895an error in the comparison."
896 (cl-flet* ((make-vec (lambda (contents) (append (list 'vec) contents)))
897 (make-cplx (lambda (x) (list 'cplx x 0)))
898 (make-cplx-vec (lambda (contents)
899 (make-vec (mapcar #'make-cplx contents)))))
900 ;; 1: calc-string-maximum-character is a valid character
901 (dolist (maxchar '(#x7F #xFF #x10FFFF #x3FFFFD #x3FFFFF))
902 (let* ((calc-string-maximum-character maxchar)
903 (small-chars (number-sequence (- maxchar 2) maxchar))
904 (large-chars (number-sequence maxchar (+ maxchar 2)))
905 (small-real-vec (make-vec small-chars))
906 (large-real-vec (make-vec large-chars))
907 (small-cplx-vec (make-cplx-vec small-chars))
908 (large-cplx-vec (make-cplx-vec large-chars)))
909 (should (math-vector-is-string small-real-vec))
910 (should-not (math-vector-is-string large-real-vec))
911 (should (math-vector-is-string small-cplx-vec))
912 (should-not (math-vector-is-string large-cplx-vec))))
913 ;; 2: calc-string-maximum-character is negative
914 (let* ((maxchar -1)
915 (calc-string-maximum-character maxchar)
916 (valid-contents (number-sequence 0 2))
917 (invalid-contents (number-sequence (- maxchar 2) maxchar))
918 (valid-real-vec (make-vec valid-contents))
919 (invalid-real-vec (make-vec invalid-contents))
920 (valid-cplx-vec (make-cplx-vec valid-contents))
921 (invalid-cplx-vec (make-cplx-vec invalid-contents)))
922 (should-not (math-vector-is-string valid-real-vec))
923 (should-not (math-vector-is-string invalid-real-vec))
924 (should-not (math-vector-is-string valid-cplx-vec))
925 (should-not (math-vector-is-string invalid-cplx-vec)))
926 ;; 3: calc-string-maximum-character is larger than (max-char)
927 (let* ((maxchar (+ (max-char) 3))
928 (calc-string-maximum-character maxchar)
929 (valid-chars (number-sequence (- (max-char) 2) (max-char)))
930 (invalid-chars (number-sequence (1+ (max-char)) maxchar))
931 (valid-real-vec (make-vec valid-chars))
932 (invalid-real-vec (make-vec invalid-chars))
933 (valid-cplx-vec (make-cplx-vec valid-chars))
934 (invalid-cplx-vec (make-cplx-vec invalid-chars)))
935 (should (math-vector-is-string valid-real-vec))
936 (should-not (math-vector-is-string invalid-real-vec))
937 (should (math-vector-is-string valid-cplx-vec))
938 (should-not (math-vector-is-string invalid-cplx-vec)))
939 ;; 4: calc-string-maximum-character has the wrong type
940 (let* ((calc-string-maximum-character "wrong type")
941 (contents (number-sequence 0 2))
942 (real-vec (make-vec contents))
943 (cplx-vec (make-cplx-vec contents)))
944 (should-error (math-vector-is-string real-vec)
945 :type 'wrong-type-argument)
946 (should-error (math-vector-is-string cplx-vec)
947 :type 'wrong-type-argument))))
948
882(provide 'calc-tests) 949(provide 'calc-tests)
883;;; calc-tests.el ends here 950;;; calc-tests.el ends here