Add feature to disable symbols.
This commit is contained in:
20
tests/tokens.rs
Normal file
20
tests/tokens.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
use rhai::{Engine, ParseErrorType};
|
||||
|
||||
#[test]
|
||||
fn test_tokens_disabled() {
|
||||
let mut engine = Engine::new();
|
||||
|
||||
engine.disable_symbol("if"); // disable the 'if' keyword
|
||||
|
||||
assert!(matches!(
|
||||
*engine.compile("let x = if true { 42 } else { 0 };").expect_err("should error").0,
|
||||
ParseErrorType::MissingToken(ref token, _) if token == ";"
|
||||
));
|
||||
|
||||
engine.disable_symbol("+="); // disable the '+=' operator
|
||||
|
||||
assert!(matches!(
|
||||
*engine.compile("let x = 40 + 2; x += 1;").expect_err("should error").0,
|
||||
ParseErrorType::BadInput(ref s) if s == "Unexpected '+='"
|
||||
));
|
||||
}
|
Reference in New Issue
Block a user