Refine docs and tests.
This commit is contained in:
parent
3e45d5d9a5
commit
46cdec1280
@ -12,7 +12,7 @@ Like C, `continue` can be used to skip to the next iteration, by-passing all fol
|
||||
let x = 10;
|
||||
|
||||
loop {
|
||||
x = x - 1;
|
||||
x -= 1;
|
||||
|
||||
if x > 5 { continue; } // skip to the next iteration
|
||||
|
||||
|
@ -12,7 +12,7 @@ Like C, `continue` can be used to skip to the next iteration, by-passing all fol
|
||||
let x = 10;
|
||||
|
||||
while x > 0 {
|
||||
x = x - 1;
|
||||
x -= 1;
|
||||
if x < 6 { continue; } // skip to the next iteration
|
||||
print(x);
|
||||
if x == 5 { break; } // break out of while loop
|
||||
|
@ -1046,8 +1046,8 @@ impl Engine {
|
||||
/// let mut scope = Scope::new();
|
||||
/// scope.push("x", 40_i64);
|
||||
///
|
||||
/// assert_eq!(engine.eval_with_scope::<i64>(&mut scope, "x = x + 2; x")?, 42);
|
||||
/// assert_eq!(engine.eval_with_scope::<i64>(&mut scope, "x = x + 2; x")?, 44);
|
||||
/// assert_eq!(engine.eval_with_scope::<i64>(&mut scope, "x += 2; x")?, 42);
|
||||
/// assert_eq!(engine.eval_with_scope::<i64>(&mut scope, "x += 2; x")?, 44);
|
||||
///
|
||||
/// // The variable in the scope is modified
|
||||
/// assert_eq!(scope.get_value::<i64>("x").expect("variable x should exist"), 44);
|
||||
@ -1160,7 +1160,7 @@ impl Engine {
|
||||
/// scope.push("x", 40_i64);
|
||||
///
|
||||
/// // Compile a script to an AST and store it for later evaluation
|
||||
/// let ast = engine.compile("x = x + 2; x")?;
|
||||
/// let ast = engine.compile("x += 2; x")?;
|
||||
///
|
||||
/// // Evaluate it
|
||||
/// assert_eq!(engine.eval_ast_with_scope::<i64>(&mut scope, &ast)?, 42);
|
||||
|
@ -32,7 +32,7 @@ fn test_call_fn() -> Result<(), Box<EvalAltResult>> {
|
||||
x + y
|
||||
}
|
||||
fn hello(x) {
|
||||
x = x * foo;
|
||||
x *= foo;
|
||||
foo = 1;
|
||||
x
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ fn test_loop() -> Result<(), Box<EvalAltResult>> {
|
||||
if i < 10 {
|
||||
i += 1;
|
||||
if x > 20 { continue; }
|
||||
x = x + i;
|
||||
x += i;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ fn test_var_scope() -> Result<(), Box<EvalAltResult>> {
|
||||
|
||||
engine.eval_with_scope::<()>(&mut scope, "let x = 4 + 5")?;
|
||||
assert_eq!(engine.eval_with_scope::<INT>(&mut scope, "x")?, 9);
|
||||
engine.eval_with_scope::<()>(&mut scope, "x = x + 1; x = x + 2;")?;
|
||||
engine.eval_with_scope::<()>(&mut scope, "x += 1; x += 2;")?;
|
||||
assert_eq!(engine.eval_with_scope::<INT>(&mut scope, "x")?, 12);
|
||||
|
||||
scope.set_value("x", 42 as INT);
|
||||
|
@ -10,10 +10,10 @@ fn test_while() -> Result<(), Box<EvalAltResult>> {
|
||||
let x = 0;
|
||||
|
||||
while x < 10 {
|
||||
x = x + 1;
|
||||
x += 1;
|
||||
if x > 5 { break; }
|
||||
if x > 3 { continue; }
|
||||
x = x + 3;
|
||||
x += 3;
|
||||
}
|
||||
|
||||
x
|
||||
|
Loading…
Reference in New Issue
Block a user