Raymond Toy pushed to branch issue-367-count-octets-for-encoding at cmucl / cmucl Commits: 02be9b8b by Raymond Toy at 2025-01-13T13:19:18-08:00 Add test that errors are signaled in string-octet-count Just test that we signal an error when converting a string to :ascii. - - - - - 06488aeb by Raymond Toy at 2025-01-13T13:25:19-08:00 Add some sanity checks for STRING-TO-OCTETS Since `string-to-octets` can return a buffer of octets whose length is not the same as the returned number of octets, add a check that they are the same. If not, then we `string-octet-count` may not be consistent. Also add a check that the converted number of characters matches the length of the string. - - - - - 1 changed file: - tests/external-formats.lisp Changes: ===================================== tests/external-formats.lisp ===================================== @@ -20,9 +20,22 @@ "Random test string with codepoints below 20000") + (defmacro test-octet-count (string format) - `(assert-equal (length (stream:string-to-octets ,string :external-format ,format)) - (stream::string-octet-count ,string :external-format ,format))) + "Test that STRING-OCTET-COUNT returns the correct number of octets" + ;; We expect STRING-OCTET-COUNT returns the same number of octets + ;; that are produced by STRING-TO-OCTETS. + `(multiple-value-bind (octets count converted) + (stream:string-to-octets ,string :external-format ,format) + ;; While we're at it, make sure that the length of the octet + ;; buffer matches returned count. And make sure we converted all + ;; the characters in the string. + (assert-equal (length octets) count) + (assert-equal (length ,string) converted) + ;; Finally, make sure that STRING-OCTET-COUNT returns the same + ;; number of octets from STRING-TO-OCTETS. + (assert-equal (length octets) + (stream::string-octet-count ,string :external-format ,format)))) (define-test octet-count.iso8859-1 (:tag :octet-count) @@ -32,6 +45,13 @@ (:tag :octet-count) (test-octet-count *test-iso8859-1* :ascii)) +(define-test octet-count.ascii.error + (:tag :octet-count) + (assert-error 'simple-error + (stream::string-octet-count *test-iso8859-1* + :external-format :ascii + :error 'error))) + (define-test octet-count.utf-8 (:tag :octet-count) (test-octet-count *test-unicode* :utf-8)) View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/ccd15fcecd9a55e61b22a7f... -- View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/ccd15fcecd9a55e61b22a7f... You're receiving this email because of your account on gitlab.common-lisp.net.