Add unit tests on utf8Encode.

This commit is contained in:
Jean-Christophe Amiel 2025-09-17 18:02:06 +02:00
parent b756e18468
commit 4394eaf87f
No known key found for this signature in database
GPG Key ID: 07FF11CFD55356CC
1 changed files with 26 additions and 0 deletions

View File

@ -34,3 +34,29 @@ pub fn eval_utf8_encode(
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use hurl_core::ast::SourceInfo;
use hurl_core::reader::Pos;
#[test]
fn eval_filter_utf8_decode_ok() {
let datas = [
("Hello World", b"Hello World".to_vec()),
// With emojis
(
"🐶🐱🐭🐹",
b"\xF0\x9F\x90\xB6\xF0\x9F\x90\xB1\xF0\x9F\x90\xAD\xF0\x9F\x90\xB9".to_vec(),
),
];
let source_info = SourceInfo::new(Pos::new(1, 1), Pos::new(1, 10));
for (str, expected) in datas {
let ret = eval_utf8_encode(&Value::String(str.to_string()), source_info, false);
assert_eq!(ret.unwrap().unwrap(), Value::Bytes(expected));
}
}
}