summaryrefslogtreecommitdiffhomepage
path: root/tests/custom/03_stdlib/31_arrtoip
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2022-01-29 23:31:16 +0100
committerJo-Philipp Wich <jo@mein.io>2022-02-03 17:22:43 +0100
commit7edad5cefa0f065aa83dffd2d7830aeaf9f38662 (patch)
tree86b727f434302ffb28cb59278243517f9765e170 /tests/custom/03_stdlib/31_arrtoip
parentd5003fde57eab19588da7bfdbaefe93d47435eb6 (diff)
tests: add functional tests for builtin functions
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'tests/custom/03_stdlib/31_arrtoip')
-rw-r--r--tests/custom/03_stdlib/31_arrtoip57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/custom/03_stdlib/31_arrtoip b/tests/custom/03_stdlib/31_arrtoip
new file mode 100644
index 0000000..61d82e1
--- /dev/null
+++ b/tests/custom/03_stdlib/31_arrtoip
@@ -0,0 +1,57 @@
+The `arrtoip()` function converts the given byte array into an IP address
+string. Array of length 4 are converted to IPv4 addresses, arrays of
+length 16 to IPv6 addresses.
+
+Returns the resulting IPv4 or IPv6 address string.
+
+Returns `null` if the given value is not an array, if the array has an
+unsuitable length or if any item within the array is not an integer within
+the range 0-255.
+
+-- Testcase --
+{%
+ print(join("\n", [
+ arrtoip([ 0, 0, 0, 0 ]),
+ arrtoip([ 192, 168, 1, 1 ]),
+ arrtoip([ 255, 255, 255, 255 ]),
+ arrtoip([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]),
+ arrtoip([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 192, 168, 1, 1 ]),
+ arrtoip([ 32, 1, 13, 184, 18, 52, 69, 103, 120, 154, 188, 222, 240, 18, 52, 86 ]),
+ arrtoip([ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ])
+ ]), "\n");
+%}
+-- End --
+
+-- Expect stdout --
+0.0.0.0
+192.168.1.1
+255.255.255.255
+::
+::ffff:192.168.1.1
+2001:db8:1234:4567:789a:bcde:f012:3456
+ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
+-- End --
+
+
+Supplying a non-array value, an array of unsuitable length or an array
+containing invalid byte values yields `null`.
+
+-- Testcase --
+{%
+ print(join("\n", [
+ arrtoip(true),
+ arrtoip([ ]),
+ arrtoip([ 1, 2, 3 ]),
+ arrtoip([ 192, 168, 1, -1 ]),
+ arrtoip([ true, false, -5, 500 ])
+ ]), "\n");
+%}
+-- End --
+
+-- Expect stdout --
+null
+null
+null
+null
+null
+-- End --