#![allow(clippy::unwrap_used, clippy::expect_used)]
use kaish_kernel::{Kernel, KernelConfig};
mod common;
async fn run(source: &str) -> (i64, String, String) {
let k = Kernel::new(KernelConfig::isolated()).expect("kernel");
let r = k.execute(source).await.expect("kernel execute");
(r.code, r.text_out().trim().to_string(), r.err.clone())
}
async fn err_of(source: &str) -> String {
let k = Kernel::new(KernelConfig::isolated()).expect("kernel").into_arc();
match k.execute(source).await {
Ok(r) => {
assert!(!r.ok(), "{source:?} should fail");
format!("{}{}", r.text_out(), r.err)
}
Err(e) => format!("{e:?}"),
}
}
#[tokio::test]
async fn non_finite_operands_are_refused_not_compared() {
for source in [r#"[[ "1e309" -gt 1 ]]"#, "[[ inf -gt 1 ]]", "[[ nan -eq nan ]]"] {
let text = err_of(source).await;
assert!(
!text.contains("NaN comparison"),
"{source:?} must not reach the NaN-comparison diagnostic: {text:?}"
);
}
}
#[tokio::test]
async fn overflowing_float_spelling_names_the_range() {
let text = err_of(r#"[[ "1e309" -gt 1 ]]"#).await;
assert!(text.contains("64-bit float range"), "must name the range: {text:?}");
}
#[tokio::test]
async fn ordinary_float_operands_still_compare() {
let (code, _, err) = run(r#"[[ "1.5" -gt 1 ]]"#).await;
assert_eq!(code, 0, "must still compare: {err:?}");
let (code, _, err) = run(r#"[[ "1e3" -eq 1000 ]]"#).await;
assert_eq!(code, 0, "must still compare: {err:?}");
}
#[tokio::test]
async fn return_of_an_overflowing_string_names_the_limit() {
let text = err_of(r#"x="9223372036854775808"; f() { return $x; }; f"#).await;
assert!(text.contains("64-bit"), "must name the limit: {text:?}");
}