diff --git a/tests/constants.rs b/tests/constants.rs index 266b6ac2..4569cda0 100644 --- a/tests/constants.rs +++ b/tests/constants.rs @@ -21,3 +21,29 @@ fn test_constant() -> Result<(), Box> { Ok(()) } + +#[test] +fn test_var_is_def() -> Result<(), Box> { + let engine = Engine::new(); + + assert!(engine.eval::( + r#" + let x = 42; + is_def_var("x") + "# + )?); + assert!(!engine.eval::( + r#" + let x = 42; + is_def_var("y") + "# + )?); + assert!(engine.eval::( + r#" + const x = 42; + is_def_var("x") + "# + )?); + + Ok(()) +} diff --git a/tests/functions.rs b/tests/functions.rs index 34143ab6..062eb1ae 100644 --- a/tests/functions.rs +++ b/tests/functions.rs @@ -173,3 +173,29 @@ fn test_function_captures() -> Result<(), Box> { Ok(()) } + +#[test] +fn test_function_is_def() -> Result<(), Box> { + let engine = Engine::new(); + + assert!(engine.eval::( + r#" + fn foo(x) { x + 1 } + is_def_fn("foo", 1) + "# + )?); + assert!(!engine.eval::( + r#" + fn foo(x) { x + 1 } + is_def_fn("bar", 1) + "# + )?); + assert!(!engine.eval::( + r#" + fn foo(x) { x + 1 } + is_def_fn("foo", 0) + "# + )?); + + Ok(()) +}