diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-02-11 18:13:02 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-02-11 18:13:02 +0100 |
commit | 86f0662f891ac83f474a412b4271af996f1ea44e (patch) | |
tree | 58032802705426c0f66fe1c13399140a95e21903 /tests/custom/04_bugs | |
parent | 116a8ce35fd50e586d1c79d6f99237428adfa2ef (diff) |
lib: change `ord()` to always return single byte value
The most common usecase is extracting the value of a single byte at a
specific offset, e.g. to scan a string char-by-char to construct a hash.
Furthermore, constructing an array which contains the results of multiple
`ord()` invocations is trivial while efficiently extracting a single byte
value without the overhead of an intermediate array is not.
Due to that, change `ord()` to always return a single integer byte value
at the offset specified as second argument or at offset 0 in case no
argument was supplied.
That means that `ord("Abc", 0, 1, 2)` will now return `65` instead of the
former `[ 65, 98, 99 ]` result.
Code relying on the former behaviour should either perform multiple calls
to `ord()`, passing different offsets each time or switch to the `struct`
module which allows efficient unpacking of string data.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'tests/custom/04_bugs')
-rw-r--r-- | tests/custom/04_bugs/19_truncated_format_string | 2 | ||||
-rw-r--r-- | tests/custom/04_bugs/31_vallist_8bit_shortstrings | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/tests/custom/04_bugs/19_truncated_format_string b/tests/custom/04_bugs/19_truncated_format_string index 8ddd0a3..ead0fdb 100644 --- a/tests/custom/04_bugs/19_truncated_format_string +++ b/tests/custom/04_bugs/19_truncated_format_string @@ -9,6 +9,6 @@ to the resulting string. -- Testcase -- {% let s = sprintf("%"); - print(ord(s, 0, 1), "\n"); + print([ ord(s, 0), ord(s, 1) ], "\n"); %} -- End -- diff --git a/tests/custom/04_bugs/31_vallist_8bit_shortstrings b/tests/custom/04_bugs/31_vallist_8bit_shortstrings index 98ccf0b..9d02f42 100644 --- a/tests/custom/04_bugs/31_vallist_8bit_shortstrings +++ b/tests/custom/04_bugs/31_vallist_8bit_shortstrings @@ -3,7 +3,7 @@ to/from pointer addresses, 8 bit characters where incorrectly clamped to `-1` (`255`). -- Testcase -- -{{ ord("ö", 1)[0] != -1 }} +{{ ord("ö", 1) != -1 }} -- End -- -- Expect stdout -- |