summaryrefslogtreecommitdiffstats
path: root/tests/018
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-05-04 07:19:15 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-05-04 07:19:15 -0700
commitf32073001a616fad05b04dd8451292350d572352 (patch)
tree8da6c8bbf5b131b5c815248cdb1ecafdf80c2fbb /tests/018
parent0c07bd4a499379c47916ce7cbf8d03af79e3aa98 (diff)
downloadtxr-f32073001a616fad05b04dd8451292350d572352.tar.gz
txr-f32073001a616fad05b04dd8451292350d572352.tar.bz2
txr-f32073001a616fad05b04dd8451292350d572352.zip
format: ~x/~X specifiers support buffers.
* buf.c (buf_hex): New function. * buf.h (buf_hex): Declared. * stream.c (formatv): Support printing of buffers in hex via temporary buffer containing hex characters, similarly to how bignums are handled. * tests/018/format.tl: New file, providing some coverage over new and affected code.
Diffstat (limited to 'tests/018')
-rw-r--r--tests/018/format.tl29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/018/format.tl b/tests/018/format.tl
new file mode 100644
index 00000000..3e9e4f5b
--- /dev/null
+++ b/tests/018/format.tl
@@ -0,0 +1,29 @@
+(load "../common")
+
+(mtest
+ (fmt "~x" #b'') ""
+ (fmt "~4x" #b'') " "
+ (fmt "~4,02x" #b'') " 00"
+ (fmt "~x" #b'AF') "af"
+ (fmt "~4x" #b'AF') " af"
+ (fmt "~-4x" #b'AF') "af "
+ (fmt "~4,03x" #b'AF') " 0af"
+ (fmt "~-4,03X" #b'AF') "0AF ")
+
+(mtest
+ (fmt "~x" #\xaf) "af"
+ (fmt "~4x" #\xaf) " af"
+ (fmt "~-4x" #\xaf) "af "
+ (fmt "~4,03x" #\xaf) " 0af"
+ (fmt "~-4,03X" #\xaf) "0AF ")
+
+(mtest
+ (fmt "~x" #xaf) "af"
+ (fmt "~4x" #xaf) " af"
+ (fmt "~-4x" #xaf) "af "
+ (fmt "~4,03x" #xaf) " 0af"
+ (fmt "~-4,03X" #xaf) "0AF ")
+
+(test
+ (fmt "~x" (sha256 "abc"))
+ "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad")