diff options
| author | Stefan Kangas | 2020-04-29 09:52:34 +0200 |
|---|---|---|
| committer | Stefan Kangas | 2020-04-29 09:52:34 +0200 |
| commit | 702d9d86f2a7ba9df693a1140565aa111135f1bb (patch) | |
| tree | 502d47c46bf263d2ff4f1f8bdf53fa7ec6e4b017 | |
| parent | c8115e88f180bf33154dcc9de9767bba797af827 (diff) | |
| download | emacs-702d9d86f2a7ba9df693a1140565aa111135f1bb.tar.gz emacs-702d9d86f2a7ba9df693a1140565aa111135f1bb.zip | |
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.
| -rw-r--r-- | lisp/emacs-lisp/bindat.el | 2 | ||||
| -rw-r--r-- | test/lisp/emacs-lisp/bindat-tests.el | 16 |
2 files changed, 17 insertions, 1 deletions
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." | |||
| 632 | (bindat-format-vector vect "%d" (if (stringp sep) sep "."))) | 632 | (bindat-format-vector vect "%d" (if (stringp sep) sep "."))) |
| 633 | 633 | ||
| 634 | (defun bindat-vector-to-hex (vect &optional sep) | 634 | (defun bindat-vector-to-hex (vect &optional sep) |
| 635 | "Format vector VECT in hex format separated by dots. | 635 | "Format vector VECT in hex format separated by colons. |
| 636 | If optional second arg SEP is a string, use that as separator." | 636 | If optional second arg SEP is a string, use that as separator." |
| 637 | (bindat-format-vector vect "%02x" (if (stringp sep) sep ":"))) | 637 | (bindat-format-vector vect "%02x" (if (stringp sep) sep ":"))) |
| 638 | 638 | ||
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 @@ | |||
| 96 | (dest-ip . | 96 | (dest-ip . |
| 97 | [192 168 1 100])))))) | 97 | [192 168 1 100])))))) |
| 98 | 98 | ||
| 99 | (ert-deftest bindat-test-format-vector () | ||
| 100 | (should (equal (bindat-format-vector [1 2 3] "%d" "x" 2) "1x2")) | ||
| 101 | (should (equal (bindat-format-vector [1 2 3] "%d" "x") "1x2x3"))) | ||
| 102 | |||
| 103 | (ert-deftest bindat-test-vector-to-dec () | ||
| 104 | (should (equal (bindat-vector-to-dec [1 2 3]) "1.2.3")) | ||
| 105 | (should (equal (bindat-vector-to-dec [2048 1024 512] ".") "2048.1024.512"))) | ||
| 106 | |||
| 107 | (ert-deftest bindat-test-vector-to-hex () | ||
| 108 | (should (equal (bindat-vector-to-hex [1 2 3]) "01:02:03")) | ||
| 109 | (should (equal (bindat-vector-to-hex [2048 1024 512] ".") "800.400.200"))) | ||
| 110 | |||
| 111 | (ert-deftest bindat-test-ip-to-string () | ||
| 112 | (should (equal (bindat-ip-to-string [192 168 0 1]) "192.168.0.1")) | ||
| 113 | (should (equal (bindat-ip-to-string "\300\250\0\1") "192.168.0.1"))) | ||
| 114 | |||
| 99 | ;;; bindat-tests.el ends here | 115 | ;;; bindat-tests.el ends here |