Build in operators between string and char.
This commit is contained in:
@@ -6,10 +6,10 @@ fn test_decrement() -> Result<(), Box<EvalAltResult>> {
|
||||
|
||||
assert_eq!(engine.eval::<INT>("let x = 10; x -= 7; x")?, 3);
|
||||
|
||||
assert!(matches!(
|
||||
*engine.eval::<String>(r#"let s = "test"; s -= "ing"; s"#).expect_err("expects error"),
|
||||
EvalAltResult::ErrorFunctionNotFound(err, _) if err == "- (&str | ImmutableString | String, &str | ImmutableString | String)"
|
||||
));
|
||||
assert_eq!(
|
||||
engine.eval::<String>(r#"let s = "test"; s -= 's'; s"#)?,
|
||||
"tet"
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@ fn test_increment() -> Result<(), Box<EvalAltResult>> {
|
||||
assert_eq!(engine.eval::<INT>("let x = 1; x += 2; x")?, 3);
|
||||
|
||||
assert_eq!(
|
||||
engine.eval::<String>("let s = \"test\"; s += \"ing\"; s")?,
|
||||
engine.eval::<String>(r#"let s = "test"; s += "ing"; s"#)?,
|
||||
"testing"
|
||||
);
|
||||
|
||||
|
14
tests/ops.rs
14
tests/ops.rs
@@ -34,7 +34,19 @@ fn test_ops_numbers() -> Result<(), Box<EvalAltResult>> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_op_precedence() -> Result<(), Box<EvalAltResult>> {
|
||||
fn test_ops_strings() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert!(engine.eval::<bool>(r#""hello" > 'c'"#)?);
|
||||
assert!(engine.eval::<bool>(r#""" < 'c'"#)?);
|
||||
assert!(engine.eval::<bool>(r#"'x' > "hello""#)?);
|
||||
assert!(engine.eval::<bool>(r#""hello" > "foo""#)?);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ops_precedence() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert_eq!(
|
||||
|
@@ -132,6 +132,19 @@ fn test_string_substring() -> Result<(), Box<EvalAltResult>> {
|
||||
"❤❤ hello! ❤❤❤"
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
engine.eval::<String>(
|
||||
r#"let x = "\u2764\u2764\u2764 hello! \u2764\u2764\u2764"; x -= 'l'; x"#
|
||||
)?,
|
||||
"❤❤❤ heo! ❤❤❤"
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
engine.eval::<String>(
|
||||
r#"let x = "\u2764\u2764\u2764 hello! \u2764\u2764\u2764"; x -= "\u2764\u2764"; x"#
|
||||
)?,
|
||||
"❤ hello! ❤"
|
||||
);
|
||||
assert_eq!(
|
||||
engine.eval::<INT>(
|
||||
r#"let x = "\u2764\u2764\u2764 hello! \u2764\u2764\u2764"; x.index_of('\u2764')"#
|
||||
|
Reference in New Issue
Block a user