Add more tests.

This commit is contained in:
Stephen Chung 2022-01-09 17:26:46 +08:00
parent e4e2bb3356
commit 683cf31de2
2 changed files with 27 additions and 0 deletions

View File

@ -106,6 +106,21 @@ fn bench_eval_call(bench: &mut Bencher) {
bench.iter(|| engine.eval::<bool>(script).unwrap()); bench.iter(|| engine.eval::<bool>(script).unwrap());
} }
#[bench]
fn bench_eval_deeply_nested(bench: &mut Bencher) {
let script = r#"
(1 + 2 * 3 - 9) * 4 < 5 * 6 - 70 / 8 &&
(42 + 99 > 1 + 2 - 3 + 4 * 5 || 123 - 88 < 123 + 88 - 99 + 100)
&& true
&& !!!!!!!!false
"#;
let mut engine = Engine::new();
engine.set_optimization_level(OptimizationLevel::None);
bench.iter(|| engine.eval::<bool>(script).unwrap());
}
#[bench] #[bench]
fn bench_eval_loop_number(bench: &mut Bencher) { fn bench_eval_loop_number(bench: &mut Bencher) {
let script = " let script = "

View File

@ -120,6 +120,18 @@ fn test_arrays() -> Result<(), Box<EvalAltResult>> {
.into_typed_array::<INT>()?, .into_typed_array::<INT>()?,
[1, 2, 3, 4, 5] [1, 2, 3, 4, 5]
); );
#[cfg(not(feature = "no_closure"))]
assert!(!engine.eval::<bool>(
"
let x = 42;
let y = [];
let f = || x;
for n in 0..10 {
y += x;
}
some(y, |x| is_shared(x))
"
)?);
Ok(()) Ok(())
} }