2020-11-14 16:43:36 +01:00
|
|
|
use rhai::{Engine, EvalAltResult, INT};
|
2017-11-03 17:58:51 +01:00
|
|
|
|
|
|
|
#[test]
|
2020-11-14 16:43:36 +01:00
|
|
|
fn test_comments() -> Result<(), Box<EvalAltResult>> {
|
2020-04-07 07:23:06 +02:00
|
|
|
let engine = Engine::new();
|
2017-11-03 17:58:51 +01:00
|
|
|
|
2020-11-14 16:43:36 +01:00
|
|
|
assert_eq!(
|
|
|
|
engine.eval::<INT>("let x = 42; x // I am a single line comment, yay!")?,
|
|
|
|
42
|
|
|
|
);
|
2017-11-03 17:58:51 +01:00
|
|
|
|
2020-11-14 16:43:36 +01:00
|
|
|
assert_eq!(
|
|
|
|
engine.eval::<INT>(
|
|
|
|
r#"
|
2021-01-28 09:59:19 +01:00
|
|
|
let /* I am a
|
|
|
|
multi-line
|
|
|
|
comment, yay!
|
|
|
|
*/ x = 42; x
|
2020-11-14 16:43:36 +01:00
|
|
|
"#
|
|
|
|
)?,
|
|
|
|
42
|
|
|
|
);
|
|
|
|
|
2020-12-18 09:07:19 +01:00
|
|
|
assert_eq!(engine.eval::<()>("/* Hello world */")?, ());
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(feature = "no_function"))]
|
2021-04-09 17:13:33 +02:00
|
|
|
#[cfg(feature = "metadata")]
|
2020-12-18 09:07:19 +01:00
|
|
|
#[test]
|
|
|
|
fn test_comments_doc() -> Result<(), Box<EvalAltResult>> {
|
2020-12-20 13:05:23 +01:00
|
|
|
let mut engine = Engine::new();
|
2020-12-18 09:07:19 +01:00
|
|
|
|
|
|
|
let ast = engine.compile(
|
|
|
|
r"
|
|
|
|
/// Hello world
|
|
|
|
|
|
|
|
|
|
|
|
fn foo() {}
|
|
|
|
",
|
|
|
|
)?;
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
ast.iter_functions().next().unwrap().comments[0],
|
|
|
|
"/// Hello world"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert!(engine
|
|
|
|
.compile(
|
|
|
|
r"
|
|
|
|
/// Hello world
|
|
|
|
let x = 42;
|
|
|
|
"
|
|
|
|
)
|
|
|
|
.is_err());
|
|
|
|
|
2020-12-20 13:05:23 +01:00
|
|
|
engine.compile(
|
|
|
|
r"
|
|
|
|
///////////////
|
|
|
|
let x = 42;
|
|
|
|
|
|
|
|
/***************/
|
|
|
|
let x = 42;
|
|
|
|
",
|
|
|
|
)?;
|
|
|
|
|
2020-12-18 09:07:19 +01:00
|
|
|
let ast = engine.compile(
|
|
|
|
r"
|
|
|
|
/** Hello world
|
|
|
|
** how are you?
|
|
|
|
**/
|
|
|
|
|
|
|
|
fn foo() {}
|
|
|
|
",
|
|
|
|
)?;
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
ast.iter_functions().next().unwrap().comments[0],
|
|
|
|
"/** Hello world\n ** how are you?\n **/"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert!(engine
|
|
|
|
.compile(
|
|
|
|
r"
|
|
|
|
/** Hello world */
|
|
|
|
let x = 42;
|
|
|
|
"
|
|
|
|
)
|
|
|
|
.is_err());
|
|
|
|
|
2021-01-28 09:59:19 +01:00
|
|
|
engine.enable_doc_comments(false);
|
2020-12-20 13:05:23 +01:00
|
|
|
|
|
|
|
engine.compile(
|
|
|
|
r"
|
|
|
|
/// Hello world!
|
|
|
|
let x = 42;
|
|
|
|
|
|
|
|
/** Hello world! */
|
|
|
|
let x = 42;
|
|
|
|
",
|
|
|
|
)?;
|
|
|
|
|
2020-11-14 16:43:36 +01:00
|
|
|
Ok(())
|
2017-11-03 17:58:51 +01:00
|
|
|
}
|