Add append/mixin functions for arrays and maps.

This commit is contained in:
Stephen Chung
2020-04-01 22:56:54 +08:00
parent 4ea2fb88ae
commit c4a51b1390
4 changed files with 127 additions and 31 deletions

View File

@@ -1,5 +1,5 @@
#![cfg(not(feature = "no_index"))]
use rhai::{Engine, EvalAltResult, RegisterFn, INT};
use rhai::{Array, Engine, EvalAltResult, RegisterFn, INT};
#[test]
fn test_arrays() -> Result<(), EvalAltResult> {
@@ -12,6 +12,43 @@ fn test_arrays() -> Result<(), EvalAltResult> {
'3'
);
#[cfg(not(feature = "no_stdlib"))]
{
assert_eq!(
engine.eval::<INT>(
r"
let x = [1, 2, 3];
let y = [4, 5];
x.append(y);
x.len()
"
)?,
5
);
assert_eq!(
engine.eval::<INT>(
r"
let x = [1, 2, 3];
x += [4, 5];
x.len()
"
)?,
5
);
assert_eq!(
engine
.eval::<Array>(
r"
let x = [1, 2, 3];
let y = [4, 5];
x + y
"
)?
.len(),
5
);
}
Ok(())
}