diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-01-29 23:31:16 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-02-03 17:22:43 +0100 |
commit | 7edad5cefa0f065aa83dffd2d7830aeaf9f38662 (patch) | |
tree | 86b727f434302ffb28cb59278243517f9765e170 /tests/custom/03_stdlib/13_ord | |
parent | d5003fde57eab19588da7bfdbaefe93d47435eb6 (diff) |
tests: add functional tests for builtin functions
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'tests/custom/03_stdlib/13_ord')
-rw-r--r-- | tests/custom/03_stdlib/13_ord | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/custom/03_stdlib/13_ord b/tests/custom/03_stdlib/13_ord new file mode 100644 index 0000000..3a69228 --- /dev/null +++ b/tests/custom/03_stdlib/13_ord @@ -0,0 +1,46 @@ +The `ord()` function extracts the byte values of characters within the +given input string at different offsets, depending on the arguments. + +Without further arguments, the function will return the byte value of +the first character within the given string. + +If one or more offset arguments are given, the function returns an array +containing the byte values of each character at the corresponding offset. + +Returns `null` if the given input string argument is not a string. + +Returns `null` if the given input string is empty and no offset arguments +are provided. + +If invalid offsets are given, the corresponding values within the result +array will be set to `null`. + +Invalid offsets are non-integer values or integers equal to or larger than +the length of the input string. Negative offsets are converted to positive +ones by adding the length of the input string. If the negative value is +too large, the offset is considered invalid. + + +-- Testcase -- +{% + print(join("\n", [ + ord(123), + ord(""), + ord("abcd"), + ord("abcd", 0), + ord("abcd", 1, 3, 2), + ord("abcd", -1, -2), + ord("abcd", -10, 10) + ]), "\n"); +%} +-- End -- + +-- Expect stdout -- +null +null +97 +[ 97 ] +[ 98, 100, 99 ] +[ 100, 99 ] +[ null, null ] +-- End -- |