diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2021-03-05 13:31:16 -0500 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2021-03-05 13:31:16 -0500 |
commit | 03ada27cb81dabb87eff38f2d66fe8fc4a02da46 (patch) | |
tree | ee81ebdcc796bc856f5abf485f7861e484b80927 /test/lisp/emacs-lisp | |
parent | d582356a7f704f8a209a3ef31d6ea970520c6224 (diff) | |
download | emacs-03ada27cb81dabb87eff38f2d66fe8fc4a02da46.tar.gz emacs-03ada27cb81dabb87eff38f2d66fe8fc4a02da46.tar.bz2 emacs-03ada27cb81dabb87eff38f2d66fe8fc4a02da46.zip |
* lisp/emacs-lisp/bindat.el: Minor refactoring
(bindat--unpack-str, bindat--unpack-strz, bindat--unpack-bits):
New functions, extracted from `bindat--unpack-item`.
(bindat--unpack-item): Use them.
(bindat--align): New function.
(bindat--unpack-group, bindat--length-group, bindat--pack-group): Use it.
(bindat-get-field): Allow integers to index both lists (as returned by
`repeat`) and vectors (as returned by `vec`).
(bindat--pack-str, bindat--pack-bits): New functions, extracted from
`bindat--pack-item`.
(bindat--pack-item): Use them.
* test/lisp/emacs-lisp/bindat-tests.el (struct-bindat): Place the fields
in the order in which they appear in the structs.
Diffstat (limited to 'test/lisp/emacs-lisp')
-rw-r--r-- | test/lisp/emacs-lisp/bindat-tests.el | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/test/lisp/emacs-lisp/bindat-tests.el b/test/lisp/emacs-lisp/bindat-tests.el index 72883fc2ec7..9c417c855c7 100644 --- a/test/lisp/emacs-lisp/bindat-tests.el +++ b/test/lisp/emacs-lisp/bindat-tests.el @@ -1,4 +1,4 @@ -;;; bindat-tests.el --- tests for bindat.el -*- lexical-binding: t; coding: utf-8; -*- +;;; bindat-tests.el --- tests for bindat.el -*- lexical-binding: t -*- ;; Copyright (C) 2019-2021 Free Software Foundation, Inc. @@ -23,14 +23,14 @@ (require 'bindat) (require 'cl-lib) -(defvar header-bindat-spec +(defconst header-bindat-spec (bindat-spec (dest-ip ip) (src-ip ip) (dest-port u16) (src-port u16))) -(defvar data-bindat-spec +(defconst data-bindat-spec (bindat-spec (type u8) (opcode u8) @@ -39,7 +39,7 @@ (data vec (length)) (align 4))) -(defvar packet-bindat-spec +(defconst packet-bindat-spec (bindat-spec (header struct header-bindat-spec) (items u8) @@ -47,23 +47,23 @@ (item repeat (items) (struct data-bindat-spec)))) -(defvar struct-bindat +(defconst struct-bindat '((header (dest-ip . [192 168 1 100]) (src-ip . [192 168 1 101]) (dest-port . 284) (src-port . 5408)) (items . 2) - (item ((data . [1 2 3 4 5]) - (id . "ABCDEF") - (length . 5) + (item ((type . 2) (opcode . 3) - (type . 2)) - ((data . [6 7 8 9 10 11 12]) - (id . "BCDEFG") - (length . 7) + (length . 5) + (id . "ABCDEF") + (data . [1 2 3 4 5])) + ((type . 1) (opcode . 4) - (type . 1))))) + (length . 7) + (id . "BCDEFG") + (data . [6 7 8 9 10 11 12]))))) (ert-deftest bindat-test-pack () (should (equal |