Remove unnecessary raw stirngs.

This commit is contained in:
Stephen Chung 2021-06-05 15:26:43 +08:00
parent 3371eed411
commit a530fbf4ff
8 changed files with 85 additions and 83 deletions

View File

@ -417,10 +417,10 @@ impl AST {
/// ///
/// let engine = Engine::new(); /// let engine = Engine::new();
/// ///
/// let ast1 = engine.compile(r#" /// let ast1 = engine.compile("
/// fn foo(x) { 42 + x } /// fn foo(x) { 42 + x }
/// foo(1) /// foo(1)
/// "#)?; /// ")?;
/// ///
/// let ast2 = engine.compile(r#" /// let ast2 = engine.compile(r#"
/// fn foo(n) { `hello${n}` } /// fn foo(n) { `hello${n}` }
@ -469,10 +469,10 @@ impl AST {
/// ///
/// let engine = Engine::new(); /// let engine = Engine::new();
/// ///
/// let mut ast1 = engine.compile(r#" /// let mut ast1 = engine.compile("
/// fn foo(x) { 42 + x } /// fn foo(x) { 42 + x }
/// foo(1) /// foo(1)
/// "#)?; /// ")?;
/// ///
/// let ast2 = engine.compile(r#" /// let ast2 = engine.compile(r#"
/// fn foo(n) { `hello${n}` } /// fn foo(n) { `hello${n}` }
@ -523,10 +523,10 @@ impl AST {
/// ///
/// let engine = Engine::new(); /// let engine = Engine::new();
/// ///
/// let ast1 = engine.compile(r#" /// let ast1 = engine.compile("
/// fn foo(x) { 42 + x } /// fn foo(x) { 42 + x }
/// foo(1) /// foo(1)
/// "#)?; /// ")?;
/// ///
/// let ast2 = engine.compile(r#" /// let ast2 = engine.compile(r#"
/// fn foo(n) { `hello${n}` } /// fn foo(n) { `hello${n}` }
@ -606,10 +606,10 @@ impl AST {
/// ///
/// let engine = Engine::new(); /// let engine = Engine::new();
/// ///
/// let mut ast1 = engine.compile(r#" /// let mut ast1 = engine.compile("
/// fn foo(x) { 42 + x } /// fn foo(x) { 42 + x }
/// foo(1) /// foo(1)
/// "#)?; /// ")?;
/// ///
/// let ast2 = engine.compile(r#" /// let ast2 = engine.compile(r#"
/// fn foo(n) { `hello${n}` } /// fn foo(n) { `hello${n}` }

View File

@ -1354,7 +1354,8 @@ impl Engine {
/// ///
/// let map = engine.parse_json( /// let map = engine.parse_json(
/// r#"{"a":123, "b":42, "c":{"x":false, "y":true}, "d":null}"# /// 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.len(), 4);
/// assert_eq!(map["a"].as_int().unwrap(), 123); /// assert_eq!(map["a"].as_int().unwrap(), 123);

View File

@ -40,11 +40,12 @@ pub trait FuncArgs {
/// let engine = Engine::new(); /// let engine = Engine::new();
/// let mut scope = Scope::new(); /// let mut scope = Scope::new();
/// ///
/// let ast = engine.compile(r#" /// let ast = engine.compile(
/// "
/// fn hello(x, y, z) { /// fn hello(x, y, z) {
/// if x { `hello ${y}` } else { y + z } /// if x { `hello ${y}` } else { y + z }
/// } /// }
/// "#)?; /// ")?;
/// ///
/// let result: String = engine.call_fn(&mut scope, &ast, "hello", options)?; /// let result: String = engine.call_fn(&mut scope, &ast, "hello", options)?;
/// ///

View File

@ -208,13 +208,13 @@ fn test_arrays_map_reduce() -> Result<(), Box<EvalAltResult>> {
assert_eq!( assert_eq!(
engine.eval::<INT>( engine.eval::<INT>(
r#" "
let x = [1, 2, 3]; let x = [1, 2, 3];
x.reduce(|sum, v, i| { x.reduce(|sum, v, i| {
if i == 0 { sum = 10 } if i == 0 { sum = 10 }
sum + v * v sum + v * v
}) })
"# "
)?, )?,
24 24
); );
@ -231,40 +231,40 @@ fn test_arrays_map_reduce() -> Result<(), Box<EvalAltResult>> {
assert_eq!( assert_eq!(
engine.eval::<INT>( engine.eval::<INT>(
r#" "
let x = [1, 2, 3]; let x = [1, 2, 3];
x.reduce_rev(|sum, v, i| { if i == 2 { sum = 10 } sum + v * v }) x.reduce_rev(|sum, v, i| { if i == 2 { sum = 10 } sum + v * v })
"# "
)?, )?,
24 24
); );
assert!(engine.eval::<bool>( assert!(engine.eval::<bool>(
r#" "
let x = [1, 2, 3]; let x = [1, 2, 3];
x.some(|v| v > 1) x.some(|v| v > 1)
"# "
)?); )?);
assert!(engine.eval::<bool>( assert!(engine.eval::<bool>(
r#" "
let x = [1, 2, 3]; let x = [1, 2, 3];
x.some(|v, i| v * i == 0) x.some(|v, i| v * i == 0)
"# "
)?); )?);
assert!(!engine.eval::<bool>( assert!(!engine.eval::<bool>(
r#" "
let x = [1, 2, 3]; let x = [1, 2, 3];
x.all(|v| v > 1) x.all(|v| v > 1)
"# "
)?); )?);
assert!(engine.eval::<bool>( assert!(engine.eval::<bool>(
r#" "
let x = [1, 2, 3]; let x = [1, 2, 3];
x.all(|v, i| v > i) x.all(|v, i| v > i)
"# "
)?); )?);
Ok(()) Ok(())

View File

@ -79,11 +79,11 @@ fn test_call_fn_args() -> Result<(), Box<EvalAltResult>> {
let mut scope = Scope::new(); let mut scope = Scope::new();
let ast = engine.compile( let ast = engine.compile(
r#" "
fn hello(x, y, z) { fn hello(x, y, z) {
if x { `hello ${y}` } else { y + z } if x { `hello ${y}` } else { y + z }
} }
"#, ",
)?; )?;
let result: String = engine.call_fn(&mut scope, &ast, "hello", options)?; let result: String = engine.call_fn(&mut scope, &ast, "hello", options)?;

View File

@ -25,12 +25,12 @@ fn test_fn_ptr_curry_call() -> Result<(), Box<EvalAltResult>> {
#[cfg(not(feature = "no_object"))] #[cfg(not(feature = "no_object"))]
assert_eq!( assert_eq!(
engine.eval::<INT>( engine.eval::<INT>(
r#" "
let addition = |x, y| { x + y }; let addition = |x, y| { x + y };
let curried = addition.curry(2); let curried = addition.curry(2);
call_with_arg(curried, 40) call_with_arg(curried, 40)
"# "
)?, )?,
42 42
); );
@ -65,7 +65,7 @@ fn test_closures() -> Result<(), Box<EvalAltResult>> {
assert_eq!( assert_eq!(
engine.eval::<INT>( engine.eval::<INT>(
r#" "
let x = 8; let x = 8;
let res = |y, z| { let res = |y, z| {
@ -75,55 +75,55 @@ fn test_closures() -> Result<(), Box<EvalAltResult>> {
}.curry(15).call(2); }.curry(15).call(2);
res + (|| x - 3).call() res + (|| x - 3).call()
"# "
)?, )?,
42 42
); );
assert_eq!( assert_eq!(
engine.eval::<INT>( engine.eval::<INT>(
r#" "
let a = 41; let a = 41;
let foo = |x| { a += x }; let foo = |x| { a += x };
foo.call(1); foo.call(1);
a a
"# "
)?, )?,
42 42
); );
assert!(engine.eval::<bool>( assert!(engine.eval::<bool>(
r#" "
let a = 41; let a = 41;
let foo = |x| { a += x }; let foo = |x| { a += x };
a.is_shared() a.is_shared()
"# "
)?); )?);
assert!(engine.eval::<bool>( assert!(engine.eval::<bool>(
r#" "
let a = 41; let a = 41;
let foo = |x| { a += x }; let foo = |x| { a += x };
is_shared(a) is_shared(a)
"# "
)?); )?);
engine.register_fn("plus_one", |x: INT| x + 1); engine.register_fn("plus_one", |x: INT| x + 1);
assert_eq!( assert_eq!(
engine.eval::<INT>( engine.eval::<INT>(
r#" "
let a = 41; let a = 41;
let f = || plus_one(a); let f = || plus_one(a);
f.call() f.call()
"# "
)?, )?,
42 42
); );
assert_eq!( assert_eq!(
engine.eval::<INT>( engine.eval::<INT>(
r#" "
let a = 40; let a = 40;
let f = |x| { let f = |x| {
let f = |x| { let f = |x| {
@ -133,19 +133,19 @@ fn test_closures() -> Result<(), Box<EvalAltResult>> {
f.call(x) f.call(x)
}; };
f.call(1) f.call(1)
"# "
)?, )?,
42 42
); );
assert_eq!( assert_eq!(
engine.eval::<INT>( engine.eval::<INT>(
r#" "
let a = 21; let a = 21;
let f = |x| a += x; let f = |x| a += x;
f.call(a); f.call(a);
a a
"# "
)?, )?,
42 42
); );
@ -163,13 +163,13 @@ fn test_closures() -> Result<(), Box<EvalAltResult>> {
assert_eq!( assert_eq!(
engine.eval::<INT>( engine.eval::<INT>(
r#" "
let a = 41; let a = 41;
let b = 0; let b = 0;
let f = || b.custom_call(|| a + 1); let f = || b.custom_call(|| a + 1);
f.call() f.call()
"# "
)?, )?,
42 42
); );
@ -231,13 +231,13 @@ fn test_closures_data_race() -> Result<(), Box<EvalAltResult>> {
assert_eq!( assert_eq!(
engine.eval::<INT>( engine.eval::<INT>(
r#" "
let a = 1; let a = 1;
let b = 40; let b = 40;
let foo = |x| { this += a + x }; let foo = |x| { this += a + x };
b.call(foo, 1); b.call(foo, 1);
b b
"# "
)?, )?,
42 42
); );
@ -245,12 +245,12 @@ fn test_closures_data_race() -> Result<(), Box<EvalAltResult>> {
assert!(matches!( assert!(matches!(
*engine *engine
.eval::<INT>( .eval::<INT>(
r#" "
let a = 20; let a = 20;
let foo = |x| { this += a + x }; let foo = |x| { this += a + x };
a.call(foo, 1); a.call(foo, 1);
a a
"# "
) )
.expect_err("should error"), .expect_err("should error"),
EvalAltResult::ErrorDataRace(_, _) EvalAltResult::ErrorDataRace(_, _)

View File

@ -11,12 +11,12 @@ fn test_comments() -> Result<(), Box<EvalAltResult>> {
assert_eq!( assert_eq!(
engine.eval::<INT>( engine.eval::<INT>(
r#" "
let /* I am a let /* I am a
multi-line multi-line
comment, yay! comment, yay!
*/ x = 42; x */ x = 42; x
"# "
)?, )?,
42 42
); );

View File

@ -210,28 +210,28 @@ fn test_internal_fn_captures() -> Result<(), Box<EvalAltResult>> {
assert_eq!( assert_eq!(
engine.eval::<INT>( engine.eval::<INT>(
r#" "
fn foo(y) { x += y; x } fn foo(y) { x += y; x }
let x = 41; let x = 41;
let y = 999; let y = 999;
foo!(1) + x foo!(1) + x
"# "
)?, )?,
83 83
); );
assert!(engine assert!(engine
.eval::<INT>( .eval::<INT>(
r#" "
fn foo(y) { x += y; x } fn foo(y) { x += y; x }
let x = 41; let x = 41;
let y = 999; let y = 999;
foo(1) + x foo(1) + x
"# "
) )
.is_err()); .is_err());
@ -239,14 +239,14 @@ fn test_internal_fn_captures() -> Result<(), Box<EvalAltResult>> {
assert!(matches!( assert!(matches!(
*engine *engine
.compile( .compile(
r#" "
fn foo() { this += x; } fn foo() { this += x; }
let x = 41; let x = 41;
let y = 999; let y = 999;
y.foo!(); y.foo!();
"# "
) )
.expect_err("should error") .expect_err("should error")
.0, .0,