From: Stefan Kangas Date: Wed, 29 Apr 2020 07:52:34 +0000 (+0200) Subject: Add new tests to bindat-tests.el X-Git-Tag: emacs-28.0.90~7487 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=702d9d86f2a7ba9df693a1140565aa111135f1bb;p=emacs.git Add new tests to bindat-tests.el * test/lisp/emacs-lisp/bindat-tests.el (bindat-test-format-vector) (bindat-test-vector-to-dec, bindat-test-vector-to-hex) (bindat-test-ip-to-string): New tests. * lisp/emacs-lisp/bindat.el (bindat-vector-to-hex): Fix typo. --- diff --git a/lisp/emacs-lisp/bindat.el b/lisp/emacs-lisp/bindat.el index b5d99e34518..d168c255121 100644 --- a/lisp/emacs-lisp/bindat.el +++ b/lisp/emacs-lisp/bindat.el @@ -632,7 +632,7 @@ If optional second arg SEP is a string, use that as separator." (bindat-format-vector vect "%d" (if (stringp sep) sep "."))) (defun bindat-vector-to-hex (vect &optional sep) - "Format vector VECT in hex format separated by dots. + "Format vector VECT in hex format separated by colons. If optional second arg SEP is a string, use that as separator." (bindat-format-vector vect "%02x" (if (stringp sep) sep ":"))) diff --git a/test/lisp/emacs-lisp/bindat-tests.el b/test/lisp/emacs-lisp/bindat-tests.el index f8efa7902a4..14f95a8bf80 100644 --- a/test/lisp/emacs-lisp/bindat-tests.el +++ b/test/lisp/emacs-lisp/bindat-tests.el @@ -96,4 +96,20 @@ (dest-ip . [192 168 1 100])))))) +(ert-deftest bindat-test-format-vector () + (should (equal (bindat-format-vector [1 2 3] "%d" "x" 2) "1x2")) + (should (equal (bindat-format-vector [1 2 3] "%d" "x") "1x2x3"))) + +(ert-deftest bindat-test-vector-to-dec () + (should (equal (bindat-vector-to-dec [1 2 3]) "1.2.3")) + (should (equal (bindat-vector-to-dec [2048 1024 512] ".") "2048.1024.512"))) + +(ert-deftest bindat-test-vector-to-hex () + (should (equal (bindat-vector-to-hex [1 2 3]) "01:02:03")) + (should (equal (bindat-vector-to-hex [2048 1024 512] ".") "800.400.200"))) + +(ert-deftest bindat-test-ip-to-string () + (should (equal (bindat-ip-to-string [192 168 0 1]) "192.168.0.1")) + (should (equal (bindat-ip-to-string "\300\250\0\1") "192.168.0.1"))) + ;;; bindat-tests.el ends here