Fix bug in indexing.

This commit is contained in:
Stephen Chung
2021-07-24 12:27:33 +08:00
parent 106c8ab5d1
commit b8485b1909
6 changed files with 150 additions and 112 deletions

View File

@@ -53,6 +53,18 @@ fn test_arrays() -> Result<(), Box<EvalAltResult>> {
convert_to_vec::<INT>(engine.eval("let y = [1, 2, 3]; y.insert(-999, 4); y")?),
[4, 1, 2, 3]
);
assert_eq!(
engine.eval::<INT>("let y = [1, 2, 3]; let z = [42]; y[z.len]")?,
2
);
assert_eq!(
engine.eval::<INT>("let y = [1, 2, [3, 4, 5, 6]]; let z = [42]; y[2][z.len]")?,
4
);
assert_eq!(
engine.eval::<INT>("let y = [1, 2, 3]; let z = [2]; y[z[0]]")?,
3
);
assert_eq!(
convert_to_vec::<INT>(engine.eval(