FIX - fixes panic when constant array is assigned to. Refine README section on constants.
This commit is contained in:
@@ -7,6 +7,10 @@ fn test_arrays() -> Result<(), EvalAltResult> {
|
||||
|
||||
assert_eq!(engine.eval::<INT>("let x = [1, 2, 3]; x[1]")?, 2);
|
||||
assert_eq!(engine.eval::<INT>("let y = [1, 2, 3]; y[1] = 5; y[1]")?, 5);
|
||||
assert_eq!(
|
||||
engine.eval::<char>(r#"let y = [1, [ 42, 88, "93" ], 3]; y[1][2][1]"#)?,
|
||||
'3'
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -48,10 +52,12 @@ fn test_array_with_structs() -> Result<(), EvalAltResult> {
|
||||
|
||||
assert_eq!(
|
||||
engine.eval::<INT>(
|
||||
"let a = [new_ts()]; \
|
||||
a[0].x = 100; \
|
||||
a[0].update(); \
|
||||
a[0].x",
|
||||
r"
|
||||
let a = [new_ts()];
|
||||
a[0].x = 100;
|
||||
a[0].update();
|
||||
a[0].x
|
||||
"
|
||||
)?,
|
||||
1100
|
||||
);
|
||||
|
@@ -6,7 +6,13 @@ fn test_constant() -> Result<(), EvalAltResult> {
|
||||
|
||||
assert_eq!(engine.eval::<i64>("const x = 123; x")?, 123);
|
||||
|
||||
match engine.eval::<i64>("const x = 123; x = 42; x") {
|
||||
match engine.eval::<i64>("const x = 123; x = 42;") {
|
||||
Err(EvalAltResult::ErrorAssignmentToConstant(var, _)) if var == "x" => (),
|
||||
Err(err) => return Err(err),
|
||||
Ok(_) => panic!("expecting compilation error"),
|
||||
}
|
||||
|
||||
match engine.eval::<i64>("const x = [1, 2, 3, 4, 5]; x[2] = 42;") {
|
||||
Err(EvalAltResult::ErrorAssignmentToConstant(var, _)) if var == "x" => (),
|
||||
Err(err) => return Err(err),
|
||||
Ok(_) => panic!("expecting compilation error"),
|
||||
|
Reference in New Issue
Block a user