Use identifiers in format!
This commit is contained in:
@@ -45,7 +45,7 @@ fn test_custom_syntax() -> Result<(), Box<EvalAltResult>> {
|
||||
">=" => count < max,
|
||||
"==" => count != max,
|
||||
"!=" => count == max,
|
||||
_ => return Err(format!("Unsupported operator: {}", op).into()),
|
||||
_ => return Err(format!("Unsupported operator: {op}").into()),
|
||||
};
|
||||
|
||||
if done {
|
||||
@@ -63,7 +63,7 @@ fn test_custom_syntax() -> Result<(), Box<EvalAltResult>> {
|
||||
|
||||
context
|
||||
.scope_mut()
|
||||
.push(format!("{}{}", var_name, count), count);
|
||||
.push(format!("{var_name}{count}"), count);
|
||||
|
||||
let stop = !context
|
||||
.eval_expression_tree(condition)?
|
||||
@@ -189,7 +189,7 @@ fn test_custom_syntax() -> Result<(), Box<EvalAltResult>> {
|
||||
context.scope_mut().set_value(var_name.to_string(), value);
|
||||
Ok(Dynamic::UNIT)
|
||||
} else {
|
||||
Err(format!("variable {} is constant", var_name).into())
|
||||
Err(format!("variable {var_name} is constant").into())
|
||||
}
|
||||
},
|
||||
)?;
|
||||
|
@@ -68,11 +68,11 @@ fn test_native_overload() -> Result<(), Box<EvalAltResult>> {
|
||||
.register_fn(
|
||||
"+",
|
||||
|s1: ImmutableString, s2: ImmutableString| -> ImmutableString {
|
||||
format!("{}***{}", s1, s2).into()
|
||||
format!("{s1}***{s2}").into()
|
||||
},
|
||||
)
|
||||
.register_fn("+", |s1: ImmutableString, _: ()| -> ImmutableString {
|
||||
format!("{} Foo!", s1).into()
|
||||
format!("{s1} Foo!").into()
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
|
@@ -81,21 +81,21 @@ fn test_optimizer_parse() -> Result<(), Box<EvalAltResult>> {
|
||||
let ast = engine.compile("{ const DECISION = false; if DECISION { 42 } else { 123 } }")?;
|
||||
|
||||
assert_eq!(
|
||||
format!("{:?}", ast),
|
||||
format!("{ast:?}"),
|
||||
r#"AST { source: "", doc: "", resolver: None, body: [Expr(123 @ 1:53)] }"#
|
||||
);
|
||||
|
||||
let ast = engine.compile("const DECISION = false; if DECISION { 42 } else { 123 }")?;
|
||||
|
||||
assert_eq!(
|
||||
format!("{:?}", ast),
|
||||
format!("{ast:?}"),
|
||||
r#"AST { source: "", doc: "", resolver: None, body: [Var(("DECISION" @ 1:7, false @ 1:18, None), CONSTANT, 1:1), Expr(123 @ 1:51)] }"#
|
||||
);
|
||||
|
||||
let ast = engine.compile("if 1 == 2 { 42 }")?;
|
||||
|
||||
assert_eq!(
|
||||
format!("{:?}", ast),
|
||||
format!("{ast:?}"),
|
||||
r#"AST { source: "", doc: "", resolver: None, body: [] }"#
|
||||
);
|
||||
|
||||
@@ -104,14 +104,14 @@ fn test_optimizer_parse() -> Result<(), Box<EvalAltResult>> {
|
||||
let ast = engine.compile("abs(-42)")?;
|
||||
|
||||
assert_eq!(
|
||||
format!("{:?}", ast),
|
||||
format!("{ast:?}"),
|
||||
r#"AST { source: "", doc: "", resolver: None, body: [Expr(42 @ 1:1)] }"#
|
||||
);
|
||||
|
||||
let ast = engine.compile("NUMBER")?;
|
||||
|
||||
assert_eq!(
|
||||
format!("{:?}", ast),
|
||||
format!("{ast:?}"),
|
||||
r#"AST { source: "", doc: "", resolver: None, body: [Expr(Variable(NUMBER) @ 1:1)] }"#
|
||||
);
|
||||
|
||||
@@ -123,7 +123,7 @@ fn test_optimizer_parse() -> Result<(), Box<EvalAltResult>> {
|
||||
let ast = engine.compile("NUMBER")?;
|
||||
|
||||
assert_eq!(
|
||||
format!("{:?}", ast),
|
||||
format!("{ast:?}"),
|
||||
r#"AST { source: "", doc: "", resolver: None, body: [Expr(42 @ 1:1)] }"#
|
||||
);
|
||||
|
||||
|
@@ -70,7 +70,7 @@ macro_rules! reg_functions {
|
||||
}
|
||||
|
||||
fn make_greeting(n: impl std::fmt::Display) -> String {
|
||||
format!("{} kitties", n)
|
||||
format!("{n} kitties")
|
||||
}
|
||||
|
||||
gen_unary_functions!(greet = make_greeting(INT, bool, char) -> String);
|
||||
|
@@ -39,14 +39,12 @@ fn test_print_debug() -> Result<(), Box<EvalAltResult>> {
|
||||
let mut engine = Engine::new();
|
||||
|
||||
engine
|
||||
.on_print(move |s| log1.write().unwrap().push(format!("entry: {}", s)))
|
||||
.on_print(move |s| log1.write().unwrap().push(format!("entry: {s}")))
|
||||
.on_debug(move |s, src, pos| {
|
||||
log2.write().unwrap().push(format!(
|
||||
"DEBUG of {} at {:?}: {}",
|
||||
src.unwrap_or("unknown"),
|
||||
pos,
|
||||
s
|
||||
))
|
||||
let src = src.unwrap_or("unknown");
|
||||
log2.write()
|
||||
.unwrap()
|
||||
.push(format!("DEBUG of {src} at {pos:?}: {s}"))
|
||||
});
|
||||
|
||||
// Evaluate script
|
||||
|
@@ -744,7 +744,7 @@ fn test_serde_json() -> serde_json::Result<()> {
|
||||
let a = m.remove("b").unwrap().cast::<Array>();
|
||||
|
||||
assert_eq!(a.len(), 3);
|
||||
assert_eq!(format!("{:?}", a), "[1, 2, 3]");
|
||||
assert_eq!(format!("{a:?}"), "[1, 2, 3]");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Reference in New Issue
Block a user