hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 7cc3a1ebd3ce92df01d78ebf420ce4e4d68d5c15
parent 2365c4223864011e259ac15efade67f7deae3528
Author: Martin Quinson <martin.quinson@ens-rennes.fr>
Date:   Mon, 29 Jan 2024 02:21:38 +0100

More testing of encoding::base64

- Use the existing decode tests with the url_encoding too
- Add a few more invalid encodings to the collection

Signed-off-by: Martin Quinson <martin.quinson@ens-rennes.fr>

Diffstat:
Mencoding/base64/base64.ha | 48++++++++++++++++++++++--------------------------
1 file changed, 22 insertions(+), 26 deletions(-)

diff --git a/encoding/base64/base64.ha b/encoding/base64/base64.ha @@ -486,38 +486,34 @@ export fn decode( assert(bytes::equal(decb, strings::toutf8(cases[i].1))); }; - const invalid: [_](str, *encoding) = [ + const invalid: [_]str = [ // invalid padding - ("=", &std_encoding), - ("==", &std_encoding), - ("===", &std_encoding), - ("=====", &std_encoding), - ("======", &std_encoding), + "=", "==", "===", "=====", "======", // invalid characters - ("@Zg=", &std_encoding), - ("êg=", &std_encoding), - ("êg==", &std_encoding), + "@Zg=", "êg=", "êg==", "$3d==", "%3d==", "[==", "!", // data after padding is encountered - ("Zg==Zg==", &std_encoding), - ("Zm8=Zm8=", &std_encoding), + "Zg==Zg==", "Zm8=Zm8=", ]; + const encodings: [_]*encoding = [&std_encoding, &url_encoding]; for (let i = 0z; i < len(invalid); i += 1) { - let in = memio::fixed(strings::toutf8(invalid[i].0)); - let decoder = newdecoder(invalid[i].1, &in); - let buf: [1]u8 = [0...]; - let valid = false; - for (true) match(io::read(&decoder, buf)) { - case errors::invalid => - break; - case size => - valid = true; - case io::EOF => - break; - }; - assert(valid == false, "valid is not false"); + for (let enc = 0z; enc < 2; enc += 1) { + let in = memio::fixed(strings::toutf8(invalid[i])); + let decoder = newdecoder(encodings[enc], &in); + let buf: [1]u8 = [0...]; + let valid = false; + for (true) match(io::read(&decoder, buf)) { + case errors::invalid => + break; + case size => + valid = true; + case io::EOF => + break; + }; + assert(valid == false, "valid is not false"); - // Testing decodestr should cover decodeslice too - assert(decodestr(invalid[i].1, invalid[i].0) is errors::invalid); + // Testing decodestr should cover decodeslice too + assert(decodestr(encodings[enc], invalid[i]) is errors::invalid); + }; }; };