You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.2 KiB
42 lines
1.2 KiB
//! Tests for the Lua stdlib, ported from flowbox-rt's fb_lua `lua_tests` and
|
|
//! adapted to this project's sandbox and stdlib.
|
|
|
|
mod async_tests;
|
|
mod core_tests;
|
|
mod math_tests;
|
|
mod os_tests;
|
|
mod require_tests;
|
|
mod table_tests;
|
|
mod utils_tests;
|
|
|
|
use mlua::Lua;
|
|
|
|
/// A fresh sandboxed Lua with the full stdlib installed - the same state scripts get.
|
|
pub(crate) fn lua() -> Lua {
|
|
crate::sandbox::create_sandboxed_lua().unwrap()
|
|
}
|
|
|
|
/// Compare two JSON strings as parsed values (key order independent).
|
|
#[allow(dead_code)]
|
|
pub(crate) fn json_eq(a: &str, b: &str) -> bool {
|
|
let a: serde_json::Value = serde_json::from_str(a).unwrap();
|
|
let b: serde_json::Value = serde_json::from_str(b).unwrap();
|
|
a == b
|
|
}
|
|
|
|
/// Assert that two f64 values are equal within an epsilon (default `f64::EPSILON`).
|
|
macro_rules! assert_eq_f64 {
|
|
($a:expr, $b:expr) => {
|
|
assert_eq_f64!($a, $b, f64::EPSILON)
|
|
};
|
|
($a:expr, $b:expr, $eps:expr) => {{
|
|
let (a, b): (f64, f64) = ($a, $b);
|
|
let eps: f64 = $eps;
|
|
assert!(
|
|
(a - b).abs() <= eps,
|
|
"assertion failed: `(left !== right)` (left: `{a:?}`, right: `{b:?}`, epsilon: `{eps:?}`, diff: `{:?}`)",
|
|
(a - b).abs()
|
|
);
|
|
}};
|
|
}
|
|
pub(crate) use assert_eq_f64;
|
|
|