use std::process::Command;
fn ilo() -> Command {
Command::new(env!("CARGO_BIN_EXE_ilo"))
}
#[cfg(feature = "cranelift")]
const ENGINES: &[&str] = &["--vm", "--jit"];
#[cfg(not(feature = "cranelift"))]
const ENGINES: &[&str] = &["--vm"];
fn run_ok(engine: &str, src: &str, entry: &str) -> String {
let out = ilo()
.args([src, engine, entry])
.output()
.expect("failed to run ilo");
assert!(
out.status.success(),
"ilo {engine} {src:?} {entry:?} failed: stderr={}",
String::from_utf8_lossy(&out.stderr)
);
String::from_utf8_lossy(&out.stdout).trim().to_string()
}
#[test]
fn hex_escape_null_byte() {
let src = r#"f>b;= "\x00" "\0""#;
for e in ENGINES {
assert_eq!(run_ok(e, src, "f"), "true", "engine={e}");
}
}
#[test]
fn hex_escape_lowercase_a() {
let src = r#"f>b;= "\x61" "a""#;
for e in ENGINES {
assert_eq!(run_ok(e, src, "f"), "true", "engine={e}");
}
}
#[test]
fn hex_escape_uppercase_hex_digits() {
let src = r#"f>b;= "\x41" "A""#;
for e in ENGINES {
assert_eq!(run_ok(e, src, "f"), "true", "engine={e}");
}
}
#[test]
fn hex_escape_mixed_case_hex_digits() {
let src = r#"f>b;= "\xAb" "\xab""#;
for e in ENGINES {
assert_eq!(run_ok(e, src, "f"), "true", "engine={e}");
}
}
#[test]
fn hex_escape_ansi_escape_char() {
let src = r#"f>n;len "\x1b""#;
for e in ENGINES {
assert_eq!(run_ok(e, src, "f"), "1", "engine={e}");
}
}
#[test]
fn hex_escape_inside_longer_string() {
let src = r#"f>b;= "\x48ello" "Hello""#;
for e in ENGINES {
assert_eq!(run_ok(e, src, "f"), "true", "engine={e}");
}
}
#[test]
fn hex_escape_multiple_in_one_string() {
let src = r#"f>b;= "\x68\x69" "hi""#;
for e in ENGINES {
assert_eq!(run_ok(e, src, "f"), "true", "engine={e}");
}
}
#[test]
fn hex_escape_high_byte_roundtrip() {
let src = r#"f>b;= "\xc3\xa9" "é""#;
for e in ENGINES {
assert_eq!(run_ok(e, src, "f"), "true", "engine={e}");
}
}
#[test]
fn hex_escape_non_hex_passed_through() {
let src = r#"f>n;len "\xZZ""#;
for e in ENGINES {
assert_eq!(run_ok(e, src, "f"), "4", "engine={e}");
}
}