Fix array bug.

This commit is contained in:
Stephen Chung
2022-12-26 22:05:29 +08:00
parent c5cb2d5e0f
commit 07f522e6d7
2 changed files with 18 additions and 6 deletions

View File

@@ -303,6 +303,18 @@ fn test_arrays_map_reduce() -> Result<(), Box<EvalAltResult>> {
engine.eval::<INT>("let x = [1, 2, 3]; x.for_each(|| this += 41); x[0]")?,
42
);
assert_eq!(
engine.eval::<INT>(
"
let x = [1, 2, 3];
let sum = 0;
let factor = 2;
x.for_each(|| sum += this * factor);
sum
"
)?,
12
);
assert_eq!(engine.eval::<INT>("([1].map(|x| x + 41))[0]")?, 42);
assert_eq!(
engine.eval::<INT>("let c = 40; let y = 1; [1].map(|x, i| c + x + y + i)[0]")?,