Make for loops for efficient.
This commit is contained in:
28
tests/for.rs
28
tests/for.rs
@@ -371,3 +371,31 @@ fn test_for_module_iterator() -> Result<(), Box<EvalAltResult>> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
fn test_for_capture() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(
|
||||
engine.eval::<INT>(
|
||||
"
|
||||
let a = [];
|
||||
|
||||
for (x, i) in 100..110 {
|
||||
a += || i + x;
|
||||
}
|
||||
|
||||
let sum = 0;
|
||||
|
||||
for fp in a {
|
||||
sum += fp.call();
|
||||
}
|
||||
|
||||
sum
|
||||
"
|
||||
)?,
|
||||
1180
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
Reference in New Issue
Block a user