diff --git a/src/ast.rs b/src/ast.rs index da2c9fc2..a2d81e44 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -417,15 +417,15 @@ impl AST { /// /// let engine = Engine::new(); /// - /// let ast1 = engine.compile(r#" - /// fn foo(x) { 42 + x } - /// foo(1) - /// "#)?; + /// let ast1 = engine.compile(" + /// fn foo(x) { 42 + x } + /// foo(1) + /// ")?; /// /// let ast2 = engine.compile(r#" - /// fn foo(n) { `hello${n}` } - /// foo("!") - /// "#)?; + /// fn foo(n) { `hello${n}` } + /// foo("!") + /// "#)?; /// /// let ast = ast1.merge(&ast2); // Merge 'ast2' into 'ast1' /// @@ -469,15 +469,15 @@ impl AST { /// /// let engine = Engine::new(); /// - /// let mut ast1 = engine.compile(r#" - /// fn foo(x) { 42 + x } - /// foo(1) - /// "#)?; + /// let mut ast1 = engine.compile(" + /// fn foo(x) { 42 + x } + /// foo(1) + /// ")?; /// /// let ast2 = engine.compile(r#" - /// fn foo(n) { `hello${n}` } - /// foo("!") - /// "#)?; + /// fn foo(n) { `hello${n}` } + /// foo("!") + /// "#)?; /// /// ast1.combine(ast2); // Combine 'ast2' into 'ast1' /// @@ -523,16 +523,16 @@ impl AST { /// /// let engine = Engine::new(); /// - /// let ast1 = engine.compile(r#" - /// fn foo(x) { 42 + x } - /// foo(1) - /// "#)?; + /// let ast1 = engine.compile(" + /// fn foo(x) { 42 + x } + /// foo(1) + /// ")?; /// /// let ast2 = engine.compile(r#" - /// fn foo(n) { `hello${n}` } - /// fn error() { 0 } - /// foo("!") - /// "#)?; + /// fn foo(n) { `hello${n}` } + /// fn error() { 0 } + /// foo("!") + /// "#)?; /// /// // Merge 'ast2', picking only 'error()' but not 'foo(_)', into 'ast1' /// let ast = ast1.merge_filtered(&ast2, |_, _, script, name, params| @@ -606,16 +606,16 @@ impl AST { /// /// let engine = Engine::new(); /// - /// let mut ast1 = engine.compile(r#" - /// fn foo(x) { 42 + x } - /// foo(1) - /// "#)?; + /// let mut ast1 = engine.compile(" + /// fn foo(x) { 42 + x } + /// foo(1) + /// ")?; /// /// let ast2 = engine.compile(r#" - /// fn foo(n) { `hello${n}` } - /// fn error() { 0 } - /// foo("!") - /// "#)?; + /// fn foo(n) { `hello${n}` } + /// fn error() { 0 } + /// foo("!") + /// "#)?; /// /// // Combine 'ast2', picking only 'error()' but not 'foo(_)', into 'ast1' /// ast1.combine_filtered(ast2, |_, _, script, name, params| @@ -664,9 +664,9 @@ impl AST { /// let engine = Engine::new(); /// /// let mut ast = engine.compile(r#" - /// fn foo(n) { n + 1 } - /// fn bar() { print("hello"); } - /// "#)?; + /// fn foo(n) { n + 1 } + /// fn bar() { print("hello"); } + /// "#)?; /// /// // Remove all functions except 'foo(_)' /// ast.retain_functions(|_, _, name, params| name == "foo" && params == 1); diff --git a/src/engine_api.rs b/src/engine_api.rs index d2a118ac..7d97e884 100644 --- a/src/engine_api.rs +++ b/src/engine_api.rs @@ -1354,7 +1354,8 @@ impl Engine { /// /// let map = engine.parse_json( /// r#"{"a":123, "b":42, "c":{"x":false, "y":true}, "d":null}"# - /// .replace("{", "#{").as_str(), true)?; + /// .replace("{", "#{").as_str(), + /// true)?; /// /// assert_eq!(map.len(), 4); /// assert_eq!(map["a"].as_int().unwrap(), 123); diff --git a/src/fn_args.rs b/src/fn_args.rs index 10a4e022..e575ec19 100644 --- a/src/fn_args.rs +++ b/src/fn_args.rs @@ -40,11 +40,12 @@ pub trait FuncArgs { /// let engine = Engine::new(); /// let mut scope = Scope::new(); /// - /// let ast = engine.compile(r#" - /// fn hello(x, y, z) { - /// if x { `hello ${y}` } else { y + z } - /// } - /// "#)?; + /// let ast = engine.compile( + /// " + /// fn hello(x, y, z) { + /// if x { `hello ${y}` } else { y + z } + /// } + /// ")?; /// /// let result: String = engine.call_fn(&mut scope, &ast, "hello", options)?; /// diff --git a/tests/arrays.rs b/tests/arrays.rs index 74cea10b..eb17d0a9 100644 --- a/tests/arrays.rs +++ b/tests/arrays.rs @@ -208,13 +208,13 @@ fn test_arrays_map_reduce() -> Result<(), Box> { assert_eq!( engine.eval::( - r#" + " let x = [1, 2, 3]; x.reduce(|sum, v, i| { if i == 0 { sum = 10 } sum + v * v }) - "# + " )?, 24 ); @@ -231,40 +231,40 @@ fn test_arrays_map_reduce() -> Result<(), Box> { assert_eq!( engine.eval::( - r#" + " let x = [1, 2, 3]; x.reduce_rev(|sum, v, i| { if i == 2 { sum = 10 } sum + v * v }) - "# + " )?, 24 ); assert!(engine.eval::( - r#" + " let x = [1, 2, 3]; x.some(|v| v > 1) - "# + " )?); assert!(engine.eval::( - r#" + " let x = [1, 2, 3]; x.some(|v, i| v * i == 0) - "# + " )?); assert!(!engine.eval::( - r#" + " let x = [1, 2, 3]; x.all(|v| v > 1) - "# + " )?); assert!(engine.eval::( - r#" + " let x = [1, 2, 3]; x.all(|v, i| v > i) - "# + " )?); Ok(()) diff --git a/tests/call_fn.rs b/tests/call_fn.rs index cb9aa559..a239e4a5 100644 --- a/tests/call_fn.rs +++ b/tests/call_fn.rs @@ -79,11 +79,11 @@ fn test_call_fn_args() -> Result<(), Box> { let mut scope = Scope::new(); let ast = engine.compile( - r#" + " fn hello(x, y, z) { if x { `hello ${y}` } else { y + z } } - "#, + ", )?; let result: String = engine.call_fn(&mut scope, &ast, "hello", options)?; diff --git a/tests/closures.rs b/tests/closures.rs index 67ad11a9..51a728e9 100644 --- a/tests/closures.rs +++ b/tests/closures.rs @@ -25,12 +25,12 @@ fn test_fn_ptr_curry_call() -> Result<(), Box> { #[cfg(not(feature = "no_object"))] assert_eq!( engine.eval::( - r#" + " let addition = |x, y| { x + y }; let curried = addition.curry(2); call_with_arg(curried, 40) - "# + " )?, 42 ); @@ -65,7 +65,7 @@ fn test_closures() -> Result<(), Box> { assert_eq!( engine.eval::( - r#" + " let x = 8; let res = |y, z| { @@ -75,55 +75,55 @@ fn test_closures() -> Result<(), Box> { }.curry(15).call(2); res + (|| x - 3).call() - "# + " )?, 42 ); assert_eq!( engine.eval::( - r#" + " let a = 41; let foo = |x| { a += x }; foo.call(1); a - "# + " )?, 42 ); assert!(engine.eval::( - r#" + " let a = 41; let foo = |x| { a += x }; a.is_shared() - "# + " )?); assert!(engine.eval::( - r#" + " let a = 41; let foo = |x| { a += x }; is_shared(a) - "# + " )?); engine.register_fn("plus_one", |x: INT| x + 1); assert_eq!( engine.eval::( - r#" + " let a = 41; let f = || plus_one(a); f.call() - "# + " )?, 42 ); assert_eq!( engine.eval::( - r#" + " let a = 40; let f = |x| { let f = |x| { @@ -133,19 +133,19 @@ fn test_closures() -> Result<(), Box> { f.call(x) }; f.call(1) - "# + " )?, 42 ); assert_eq!( engine.eval::( - r#" + " let a = 21; let f = |x| a += x; f.call(a); a - "# + " )?, 42 ); @@ -163,13 +163,13 @@ fn test_closures() -> Result<(), Box> { assert_eq!( engine.eval::( - r#" + " let a = 41; let b = 0; let f = || b.custom_call(|| a + 1); f.call() - "# + " )?, 42 ); @@ -231,13 +231,13 @@ fn test_closures_data_race() -> Result<(), Box> { assert_eq!( engine.eval::( - r#" + " let a = 1; let b = 40; let foo = |x| { this += a + x }; b.call(foo, 1); b - "# + " )?, 42 ); @@ -245,12 +245,12 @@ fn test_closures_data_race() -> Result<(), Box> { assert!(matches!( *engine .eval::( - r#" + " let a = 20; let foo = |x| { this += a + x }; a.call(foo, 1); a - "# + " ) .expect_err("should error"), EvalAltResult::ErrorDataRace(_, _) diff --git a/tests/comments.rs b/tests/comments.rs index 695c47a4..e0a2d2a2 100644 --- a/tests/comments.rs +++ b/tests/comments.rs @@ -11,12 +11,12 @@ fn test_comments() -> Result<(), Box> { assert_eq!( engine.eval::( - r#" + " let /* I am a multi-line comment, yay! */ x = 42; x - "# + " )?, 42 ); diff --git a/tests/internal_fn.rs b/tests/internal_fn.rs index eaa3364b..18ee31fd 100644 --- a/tests/internal_fn.rs +++ b/tests/internal_fn.rs @@ -210,28 +210,28 @@ fn test_internal_fn_captures() -> Result<(), Box> { assert_eq!( engine.eval::( - r#" + " fn foo(y) { x += y; x } let x = 41; let y = 999; foo!(1) + x - "# + " )?, 83 ); assert!(engine .eval::( - r#" + " fn foo(y) { x += y; x } let x = 41; let y = 999; foo(1) + x - "# + " ) .is_err()); @@ -239,14 +239,14 @@ fn test_internal_fn_captures() -> Result<(), Box> { assert!(matches!( *engine .compile( - r#" + " fn foo() { this += x; } let x = 41; let y = 999; y.foo!(); - "# + " ) .expect_err("should error") .0,