FIX - fixes panic when constant array is assigned to. Refine README section on constants.

This commit is contained in:
Stephen Chung
2020-03-14 19:46:44 +08:00
parent 504fd56f1f
commit 26bdc8ba08
5 changed files with 161 additions and 69 deletions

View File

@@ -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"),