summaryrefslogtreecommitdiff
path: root/test/lisp/emacs-lisp
diff options
context:
space:
mode:
authorNacho Barrientos <nacho.barrientos@cern.ch>2022-10-20 14:16:43 +0200
committerStefan Monnier <monnier@iro.umontreal.ca>2022-10-21 11:26:36 -0400
commit40a361fbd600cba00f97e853112534626f10c654 (patch)
tree0ebb0c275e9a7de0e4b8f6dc7a66355b8f6f9a78 /test/lisp/emacs-lisp
parent693443bbf7d87e5508fe109f35d81e064400f3db (diff)
downloademacs-40a361fbd600cba00f97e853112534626f10c654.tar.gz
emacs-40a361fbd600cba00f97e853112534626f10c654.tar.bz2
emacs-40a361fbd600cba00f97e853112534626f10c654.zip
Bindat (src, strz): Operate on vectors too
Copyright-paperwork-exempt: yes * lisp/emacs-lisp/bindat.el (bindat--unpack-str, bindat--unpack-strz): Fix the non-string case. * test/lisp/emacs-lisp/bindat-tests.el (bindat-test--strz-array-unpack) (bindat-test--str-simple-array-unpack,bindat-test--str-combined-array-unpack): New tests.
Diffstat (limited to 'test/lisp/emacs-lisp')
-rw-r--r--test/lisp/emacs-lisp/bindat-tests.el19
1 files changed, 18 insertions, 1 deletions
diff --git a/test/lisp/emacs-lisp/bindat-tests.el b/test/lisp/emacs-lisp/bindat-tests.el
index 0c03c51e2ef..2abf714852f 100644
--- a/test/lisp/emacs-lisp/bindat-tests.el
+++ b/test/lisp/emacs-lisp/bindat-tests.el
@@ -252,7 +252,24 @@
(should (equal (bindat-unpack spec "abc\0") "abc"))
;; Missing null terminator.
(should-error (bindat-unpack spec ""))
- (should-error (bindat-unpack spec "a"))))
+ (should-error (bindat-unpack spec "a")))
+
+ (ert-deftest bindat-test--strz-array-unpack ()
+ (should (equal (bindat-unpack spec [#x61 #x62 #x63 #x00]) "abc"))))
+
+(let ((spec (bindat-type str 3)))
+ (ert-deftest bindat-test--str-simple-array-unpack ()
+ (should (equal (bindat-unpack spec [#x61 #x62 #x63]) "abc"))))
+
+(let ((spec (bindat-type
+ (first u8)
+ (string str 3)
+ (last uint 16))))
+ (ert-deftest bindat-test--str-combined-array-unpack ()
+ (let ((unpacked (bindat-unpack spec [#xff #x63 #x62 #x61 #xff #xff])))
+ (should (equal (bindat-get-field unpacked 'string) "cba"))
+ (should (equal (bindat-get-field unpacked 'first) (- (expt 2 8) 1)))
+ (should (equal (bindat-get-field unpacked 'last) (- (expt 2 16) 1))))))
(let ((spec '((x strz 2))))
(ert-deftest bindat-test--strz-legacy-fixedlen-len ()