2020-03-02 15:11:56 +01:00
|
|
|
use rhai::{Engine, EvalAltResult};
|
2017-11-03 17:58:51 +01:00
|
|
|
|
|
|
|
#[test]
|
2020-03-02 15:11:56 +01:00
|
|
|
fn test_chars() -> Result<(), EvalAltResult> {
|
2020-04-07 07:23:06 +02:00
|
|
|
let engine = Engine::new();
|
2017-11-03 17:58:51 +01:00
|
|
|
|
2020-03-02 15:11:56 +01:00
|
|
|
assert_eq!(engine.eval::<char>("'y'")?, 'y');
|
|
|
|
assert_eq!(engine.eval::<char>("'\\u2764'")?, '❤');
|
2020-03-10 12:48:47 +01:00
|
|
|
|
|
|
|
#[cfg(not(feature = "no_index"))]
|
|
|
|
{
|
|
|
|
assert_eq!(engine.eval::<char>(r#"let x="hello"; x[2]"#)?, 'l');
|
|
|
|
assert_eq!(
|
2020-03-13 11:12:41 +01:00
|
|
|
engine.eval::<String>(r#"let y="hello"; y[2]='$'; y"#)?,
|
2020-03-31 04:00:17 +02:00
|
|
|
"he$lo"
|
2020-03-10 12:48:47 +01:00
|
|
|
);
|
|
|
|
}
|
2020-03-01 06:30:22 +01:00
|
|
|
|
2020-03-13 11:12:41 +01:00
|
|
|
assert!(engine.eval::<char>(r"'\uhello'").is_err());
|
2020-03-02 15:11:56 +01:00
|
|
|
assert!(engine.eval::<char>("''").is_err());
|
2017-11-03 17:58:51 +01:00
|
|
|
|
2020-03-02 15:11:56 +01:00
|
|
|
Ok(())
|
2018-06-13 10:56:29 +02:00
|
|
|
}
|