From 46cdec12803e331358622b971e907fc00c7e5431 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Mon, 6 Jul 2020 16:20:03 +0800 Subject: [PATCH] Refine docs and tests. --- doc/src/language/loop.md | 2 +- doc/src/language/while.md | 2 +- src/api.rs | 6 +++--- tests/call_fn.rs | 2 +- tests/looping.rs | 2 +- tests/var_scope.rs | 2 +- tests/while_loop.rs | 4 ++-- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/doc/src/language/loop.md b/doc/src/language/loop.md index b92c3f7e..e625082a 100644 --- a/doc/src/language/loop.md +++ b/doc/src/language/loop.md @@ -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 diff --git a/doc/src/language/while.md b/doc/src/language/while.md index e912175e..5b7a5ac8 100644 --- a/doc/src/language/while.md +++ b/doc/src/language/while.md @@ -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 diff --git a/src/api.rs b/src/api.rs index 42805fa3..5df12aba 100644 --- a/src/api.rs +++ b/src/api.rs @@ -1046,8 +1046,8 @@ impl Engine { /// let mut scope = Scope::new(); /// scope.push("x", 40_i64); /// - /// assert_eq!(engine.eval_with_scope::(&mut scope, "x = x + 2; x")?, 42); - /// assert_eq!(engine.eval_with_scope::(&mut scope, "x = x + 2; x")?, 44); + /// assert_eq!(engine.eval_with_scope::(&mut scope, "x += 2; x")?, 42); + /// assert_eq!(engine.eval_with_scope::(&mut scope, "x += 2; x")?, 44); /// /// // The variable in the scope is modified /// assert_eq!(scope.get_value::("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::(&mut scope, &ast)?, 42); diff --git a/tests/call_fn.rs b/tests/call_fn.rs index 690577ce..715fbc87 100644 --- a/tests/call_fn.rs +++ b/tests/call_fn.rs @@ -32,7 +32,7 @@ fn test_call_fn() -> Result<(), Box> { x + y } fn hello(x) { - x = x * foo; + x *= foo; foo = 1; x } diff --git a/tests/looping.rs b/tests/looping.rs index 3a4804ce..951f8cd7 100644 --- a/tests/looping.rs +++ b/tests/looping.rs @@ -14,7 +14,7 @@ fn test_loop() -> Result<(), Box> { if i < 10 { i += 1; if x > 20 { continue; } - x = x + i; + x += i; } else { break; } diff --git a/tests/var_scope.rs b/tests/var_scope.rs index fde83a05..0b3cc1b9 100644 --- a/tests/var_scope.rs +++ b/tests/var_scope.rs @@ -7,7 +7,7 @@ fn test_var_scope() -> Result<(), Box> { engine.eval_with_scope::<()>(&mut scope, "let x = 4 + 5")?; assert_eq!(engine.eval_with_scope::(&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::(&mut scope, "x")?, 12); scope.set_value("x", 42 as INT); diff --git a/tests/while_loop.rs b/tests/while_loop.rs index 8916cd7c..bbcd091b 100644 --- a/tests/while_loop.rs +++ b/tests/while_loop.rs @@ -10,10 +10,10 @@ fn test_while() -> Result<(), Box> { 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