master: Add tests for simd-utf8-strlen

stassats via Sbcl-commits <[email protected]> Mon, 22 Jun 2026 18:04:51 +0000
Newsgroups gmane.lisp.steel-bank.cvs
Message-ID <[email protected]>
The branch "master" has been updated in SBCL:
       via  46780e06666c9654ace786d1b924a67b88c9d490 (commit)
      from  b4c1ff116f1d9785f5e36806ad05f937398c9b3c (commit)

- Log -----------------------------------------------------------------
commit 46780e06666c9654ace786d1b924a67b88c9d490
Author: Stas Boukarev <[email protected]>
Date:   Mon Jun 22 21:03:24 2026 +0300

    Add tests for simd-utf8-strlen
---
 tests/utf-8.pure.lisp | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/tests/utf-8.pure.lisp b/tests/utf-8.pure.lisp
index f70030e4c..a6e108a2e 100644
--- a/tests/utf-8.pure.lisp
+++ b/tests/utf-8.pure.lisp
@@ -463,3 +463,41 @@
         (assert (string= string readback1))
         (assert (string= string readback2))
         (assert (string= string readback3))))))
+
+
+(with-test (:name :utf8-strlen)
+  (flet ((test (bytes expexcted-length &optional expexcted-ascii-p (offset 0))
+           (let ((bytes (coerce bytes '(vector (unsigned-byte 8)))))
+             (sb-sys:with-pinned-objects (bytes)
+               (multiple-value-bind (length ascii-p)
+                   (sb-vm::simd-utf8-strlen (sb-sys:sap+ (sb-sys:vector-sap bytes) offset))
+                 (assert (eql expexcted-length length))
+                 (assert (eql expexcted-ascii-p ascii-p)))))))
+    (test '(1 2 0 255 255) 2 t)
+    (test (append (loop for i from 1 to 64 collect i) '(0 1 255)) 64 t)
+    (test '(1 2 0 1 1 1) 2 t)
+    (test '(0 0 1 2 0) 2 t 2)
+    (test '(1 1 1 2 0) 2 t 2)
+    (test '(255 255 1 127 0) 2 t 2)
+    (test '(255 255 1 2 0) nil)
+    (test '(255 255 1 2 0) nil)
+    (test '(240 159 152 130 0) 1)
+    (test '(1 240 159 152 130 0) 2)
+    (test '(1 240 159 152 130 2 0) 3)
+    (test '(65 195 132 226 130 172 240 159 152 130 0) 4)
+    (test '(#xf4 #x8f #xbf #xbf 0) 1)
+    (test '(#xe0 #xa0 #x80 0) 1)
+    (test (append (loop for i from 1 to 61 collect i) '(240 159 152 130 0 255)) 62)
+    (test (append (loop for i from 1 to 62 collect i) '(240 159 152 130 0 240)) 63)
+    (test (append (loop for i from 1 to 63 collect i) '(240 159 152 130 0 250)) 64)
+    (test (append (loop for i from 1 to 63 collect i) '(195 169 0 128)) 64)
+
+    (test '(#xc0 #xaf 0) nil)
+    (test '(#xe0 #x80 #x80 0) nil)
+    (test '(#xf0 #x80 #x80 #x80 0) nil)
+    (test '(#xed #xa0 #x80 0) nil)
+    (test '(#xf4 #x90 #x80 #x80 0) nil)
+    (test '(#x41 #xff #x42 0) nil)
+    (test '(#x80 #x80 #x80 0) nil)
+    (test '(#xe2 #x82 #x41 0) nil)
+    (test '(#xf0 #x9f #x92 0) nil)))

-----------------------------------------------------------------------


hooks/post-receive
-- 
SBCL