rhai/tests/comments.rs

94 lines
1.7 KiB
Rust
Raw Normal View History

2020-11-14 23:43:36 +08:00
use rhai::{Engine, EvalAltResult, INT};
2017-11-03 09:58:51 -07:00
#[test]
2020-11-14 23:43:36 +08:00
fn test_comments() -> Result<(), Box<EvalAltResult>> {
let engine = Engine::new();
2017-11-03 09:58:51 -07:00
2020-11-14 23:43:36 +08:00
assert_eq!(
engine.eval::<INT>("let x = 42; x // I am a single line comment, yay!")?,
42
);
2017-11-03 09:58:51 -07:00
2020-11-14 23:43:36 +08:00
assert_eq!(
engine.eval::<INT>(
2021-06-05 15:26:43 +08:00
"
let /* I am a
multi-line
comment, yay!
*/ x = 42; x
2021-06-05 15:26:43 +08:00
"
2020-11-14 23:43:36 +08:00
)?,
42
);
2022-01-10 13:26:33 +08:00
assert_eq!(engine.run("/* Hello world */")?, ());
2020-12-18 16:07:19 +08:00
Ok(())
}
#[cfg(not(feature = "no_function"))]
2021-04-09 23:13:33 +08:00
#[cfg(feature = "metadata")]
2020-12-18 16:07:19 +08:00
#[test]
fn test_comments_doc() -> Result<(), Box<EvalAltResult>> {
2021-05-03 13:07:51 +08:00
let engine = Engine::new();
2020-12-18 16:07:19 +08:00
let ast = engine.compile(
2021-04-20 12:01:35 +08:00
"
2020-12-18 16:07:19 +08:00
/// Hello world
fn foo() {}
",
)?;
assert_eq!(
ast.iter_functions().next().unwrap().comments[0],
"/// Hello world"
);
assert!(engine
.compile(
2021-04-20 12:01:35 +08:00
"
2020-12-18 16:07:19 +08:00
/// Hello world
let x = 42;
"
)
.is_err());
engine.compile(
2021-04-20 12:01:35 +08:00
"
///////////////
let x = 42;
/***************/
let x = 42;
",
)?;
2020-12-18 16:07:19 +08:00
let ast = engine.compile(
2021-04-20 12:01:35 +08:00
"
2020-12-18 16:07:19 +08:00
/** 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(
2021-04-20 12:01:35 +08:00
"
2020-12-18 16:07:19 +08:00
/** Hello world */
let x = 42;
"
)
.is_err());
2020-11-14 23:43:36 +08:00
Ok(())
2017-11-03 09:58:51 -07:00
}