Add is_def_XXX tests.
This commit is contained in:
parent
1e13e6be5f
commit
9664ae42a7
@ -21,3 +21,29 @@ fn test_constant() -> Result<(), Box<EvalAltResult>> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_var_is_def() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert!(engine.eval::<bool>(
|
||||
r#"
|
||||
let x = 42;
|
||||
is_def_var("x")
|
||||
"#
|
||||
)?);
|
||||
assert!(!engine.eval::<bool>(
|
||||
r#"
|
||||
let x = 42;
|
||||
is_def_var("y")
|
||||
"#
|
||||
)?);
|
||||
assert!(engine.eval::<bool>(
|
||||
r#"
|
||||
const x = 42;
|
||||
is_def_var("x")
|
||||
"#
|
||||
)?);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -173,3 +173,29 @@ fn test_function_captures() -> Result<(), Box<EvalAltResult>> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_function_is_def() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
|
||||
assert!(engine.eval::<bool>(
|
||||
r#"
|
||||
fn foo(x) { x + 1 }
|
||||
is_def_fn("foo", 1)
|
||||
"#
|
||||
)?);
|
||||
assert!(!engine.eval::<bool>(
|
||||
r#"
|
||||
fn foo(x) { x + 1 }
|
||||
is_def_fn("bar", 1)
|
||||
"#
|
||||
)?);
|
||||
assert!(!engine.eval::<bool>(
|
||||
r#"
|
||||
fn foo(x) { x + 1 }
|
||||
is_def_fn("foo", 0)
|
||||
"#
|
||||
)?);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user