summaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/custom/03_stdlib/56_hexdec29
-rw-r--r--tests/custom/03_stdlib/57_hexenc24
2 files changed, 53 insertions, 0 deletions
diff --git a/tests/custom/03_stdlib/56_hexdec b/tests/custom/03_stdlib/56_hexdec
new file mode 100644
index 0000000..cb842ca
--- /dev/null
+++ b/tests/custom/03_stdlib/56_hexdec
@@ -0,0 +1,29 @@
+The `hexdec()` function decodes the given hexadecimal digit string into
+a byte string, optionally skipping specified characters.
+
+Returns null if the input string contains invalid characters or an uneven
+amount of hex digits.
+
+Returns the decoded byte string on success.
+
+-- Testcase --
+{%
+ printf("%.J\n", [
+ hexdec("44 55 66 77 33 44\n"), // whitespace is skipped by default
+ hexdec("44-55-66:77-33-44", ":-"), // skip specified characters
+ hexdec("abc"), // error; uneven amount of digits
+ hexdec("ab cd !"), // error; non-whitespace, non-hex, non-skipped char
+ hexdec(1234), // error; non-string input
+ ]);
+%}
+-- End --
+
+-- Expect stdout --
+[
+ "DUfw3D",
+ "DUfw3D",
+ null,
+ null,
+ null
+]
+-- End --
diff --git a/tests/custom/03_stdlib/57_hexenc b/tests/custom/03_stdlib/57_hexenc
new file mode 100644
index 0000000..235ad66
--- /dev/null
+++ b/tests/custom/03_stdlib/57_hexenc
@@ -0,0 +1,24 @@
+The `hexenc()` function encodes the given byte string into a hexadecimal
+digit string, converting the input value to a string if needed.
+
+Returns the encoded hexadecimal digit string.
+
+-- Testcase --
+{%
+ printf("%.J\n", [
+ hexenc("Hello world!\n"), // encoding a simple string
+ hexenc(""), // empty input -> empty output
+ hexenc([1, 2, 3]), // implicit stringification
+ hexenc(null), // null input -> null output
+ ]);
+%}
+-- End --
+
+-- Expect stdout --
+[
+ "48656c6c6f20776f726c64210a",
+ "",
+ "5b20312c20322c2033205d",
+ null
+]
+-- End --