diff options
| author | Eric S. Raymond | 2026-02-25 18:25:58 -0500 |
|---|---|---|
| committer | Eric S. Raymond | 2026-02-25 18:25:58 -0500 |
| commit | 40ff4512ad12fd29a5bea887fe77c3bddfa4caec (patch) | |
| tree | 0d45da798b648f2e7c06858353e3cd15948ae875 /test/src | |
| parent | 67e8f875627e38450a6c713e810dcea2106c6d9c (diff) | |
| download | emacs-40ff4512ad12fd29a5bea887fe77c3bddfa4caec.tar.gz emacs-40ff4512ad12fd29a5bea887fe77c3bddfa4caec.zip | |
More correctness tesrs for orinitives from fns.c.
Diffstat (limited to 'test/src')
| -rw-r--r-- | test/src/fns-tests.el | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el index 955b3cbe7fb..d0cb11c2305 100644 --- a/test/src/fns-tests.el +++ b/test/src/fns-tests.el | |||
| @@ -64,6 +64,133 @@ | |||
| 64 | (ert-deftest fns-tests-string-bytes () | 64 | (ert-deftest fns-tests-string-bytes () |
| 65 | (should (= (string-bytes "abc") 3))) | 65 | (should (= (string-bytes "abc") 3))) |
| 66 | 66 | ||
| 67 | (ert-deftest fns-tests-string-make-multibyte () | ||
| 68 | (let* ((ascii (string-make-unibyte "abc")) | ||
| 69 | (ascii-mb (string-make-multibyte ascii))) | ||
| 70 | (should (string= ascii-mb "abc")) | ||
| 71 | (should-not (multibyte-string-p ascii-mb))) | ||
| 72 | (let* ((u (string-make-unibyte "é")) | ||
| 73 | (m (string-make-multibyte u))) | ||
| 74 | (should (multibyte-string-p m)) | ||
| 75 | (should (string= (string-as-unibyte m) u)))) | ||
| 76 | |||
| 77 | (ert-deftest fns-tests-string-make-unibyte () | ||
| 78 | (let ((s (propertize "é" 'foo 'bar))) | ||
| 79 | (let ((u (string-make-unibyte s))) | ||
| 80 | (should-not (multibyte-string-p u)) | ||
| 81 | (should (equal (aref u 0) ?\xE9)) | ||
| 82 | (should-not (text-properties-at 0 u))))) | ||
| 83 | |||
| 84 | (ert-deftest fns-tests-string-as-multibyte () | ||
| 85 | (let* ((u (string-make-unibyte "abc")) | ||
| 86 | (m (string-as-multibyte u))) | ||
| 87 | (should (string= m "abc")) | ||
| 88 | (should (multibyte-string-p m)) | ||
| 89 | (should-not (text-properties-at 0 m))) | ||
| 90 | (let ((m "abc")) | ||
| 91 | (should (string= (string-as-multibyte m) m)))) | ||
| 92 | |||
| 93 | (ert-deftest fns-tests-fillarray () | ||
| 94 | (let ((v (vector 1 2 3))) | ||
| 95 | (fillarray v 'x) | ||
| 96 | (should (equal v [x x x]))) | ||
| 97 | (let ((s (string-make-unibyte "aaa"))) | ||
| 98 | (fillarray s ?b) | ||
| 99 | (should (string= s "bbb")) | ||
| 100 | (should-not (multibyte-string-p s))) | ||
| 101 | (let ((bv (make-bool-vector 4 nil))) | ||
| 102 | (fillarray bv t) | ||
| 103 | (should (equal bv (make-bool-vector 4 t)))) | ||
| 104 | (let ((ct (make-char-table 'fns-tests))) | ||
| 105 | (fillarray ct 'z) | ||
| 106 | (should (eq (char-table-range ct ?a) 'z)))) | ||
| 107 | |||
| 108 | (ert-deftest fns-tests-clear-string () | ||
| 109 | (let ((s (propertize "é" 'foo 'bar))) | ||
| 110 | (clear-string s) | ||
| 111 | (should-not (multibyte-string-p s)) | ||
| 112 | (should (equal s (make-string 2 0))) | ||
| 113 | (should-not (text-properties-at 0 s)))) | ||
| 114 | |||
| 115 | (ert-deftest fns-tests-load-average () | ||
| 116 | (let ((res (condition-case err | ||
| 117 | (list :ok (load-average) (load-average t)) | ||
| 118 | (error (list :error err))))) | ||
| 119 | (pcase res | ||
| 120 | (`(:ok ,ints ,floats) | ||
| 121 | (should (listp ints)) | ||
| 122 | (should (<= 1 (length ints) 3)) | ||
| 123 | (dolist (v ints) | ||
| 124 | (should (integerp v)) | ||
| 125 | (should (>= v 0))) | ||
| 126 | (should (listp floats)) | ||
| 127 | (should (<= 1 (length floats) 3)) | ||
| 128 | (dolist (v floats) | ||
| 129 | (should (floatp v)) | ||
| 130 | (should (>= v 0.0)))) | ||
| 131 | (`(:error ,err) | ||
| 132 | (should (string-match-p "load-average not implemented" | ||
| 133 | (error-message-string err))))))) | ||
| 134 | |||
| 135 | (ert-deftest fns-tests-locale-info () | ||
| 136 | (let ((codeset (locale-info 'codeset))) | ||
| 137 | (should (or (null codeset) (stringp codeset)))) | ||
| 138 | (let ((days (locale-info 'days))) | ||
| 139 | (should (or (null days) (and (vectorp days) (= (length days) 7))))) | ||
| 140 | (let ((months (locale-info 'months))) | ||
| 141 | (should (or (null months) (and (vectorp months) (= (length months) 12))))) | ||
| 142 | (let ((paper (locale-info 'paper))) | ||
| 143 | (should (or (null paper) | ||
| 144 | (and (consp paper) | ||
| 145 | (= (length paper) 2) | ||
| 146 | (integerp (car paper)) | ||
| 147 | (integerp (cadr paper)))))) | ||
| 148 | (should-not (locale-info 'fns-tests-no-such-item))) | ||
| 149 | |||
| 150 | (ert-deftest fns-tests-sxhash-eql () | ||
| 151 | (let* ((a (1+ most-positive-fixnum)) | ||
| 152 | (b (+ most-positive-fixnum 1))) | ||
| 153 | (should (eql a b)) | ||
| 154 | (should (integerp (sxhash-eql a))) | ||
| 155 | (should (= (sxhash-eql a) (sxhash-eql b))))) | ||
| 156 | |||
| 157 | (ert-deftest fns-tests-sxhash-equal-including-properties () | ||
| 158 | (let ((a (propertize "foo" 'face 'bold)) | ||
| 159 | (b (propertize "foo" 'face 'bold))) | ||
| 160 | (should (equal-including-properties a b)) | ||
| 161 | (should (integerp (sxhash-equal-including-properties a))) | ||
| 162 | (should (= (sxhash-equal-including-properties a) | ||
| 163 | (sxhash-equal-including-properties b))))) | ||
| 164 | |||
| 165 | (ert-deftest fns-tests-hash-table-metadata () | ||
| 166 | (let ((h (make-hash-table :test 'equal))) | ||
| 167 | (puthash "a" 1 h) | ||
| 168 | (puthash "b" 2 h) | ||
| 169 | (should (= (hash-table-rehash-size h) 1.5)) | ||
| 170 | (should (= (hash-table-rehash-threshold h) 0.8125)) | ||
| 171 | (should (integerp (hash-table-size h))) | ||
| 172 | (should (>= (hash-table-size h) (hash-table-count h))) | ||
| 173 | (should (integerp (internal--hash-table-index-size h))) | ||
| 174 | (let ((hist (internal--hash-table-histogram h))) | ||
| 175 | (should (or (null hist) | ||
| 176 | (and (consp hist) | ||
| 177 | (consp (car hist)) | ||
| 178 | (integerp (caar hist)) | ||
| 179 | (integerp (cdar hist)))))) | ||
| 180 | (let ((buckets (internal--hash-table-buckets h))) | ||
| 181 | (should (listp buckets)) | ||
| 182 | (let ((keys (cl-loop for bucket in buckets | ||
| 183 | append (mapcar #'car bucket)))) | ||
| 184 | (should (member "a" keys)) | ||
| 185 | (should (member "b" keys)))))) | ||
| 186 | |||
| 187 | (ert-deftest fns-tests-secure-hash-algorithms () | ||
| 188 | (let ((algs (secure-hash-algorithms))) | ||
| 189 | (should (listp algs)) | ||
| 190 | (should (memq 'md5 algs)) | ||
| 191 | (should (memq 'sha1 algs)) | ||
| 192 | (should (memq 'sha256 algs)))) | ||
| 193 | |||
| 67 | ;; Test that equality predicates work correctly on NaNs when combined | 194 | ;; Test that equality predicates work correctly on NaNs when combined |
| 68 | ;; with hash tables based on those predicates. This was not the case | 195 | ;; with hash tables based on those predicates. This was not the case |
| 69 | ;; for eql in Emacs 26. | 196 | ;; for eql in Emacs 26. |