From 9664ae42a7c75dc6395cda7c5756f35c53a27344 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sat, 3 Oct 2020 21:59:19 +0800 Subject: [PATCH] Add is_def_XXX tests. --- tests/constants.rs | 26 ++++++++++++++++++++++++++ tests/functions.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) 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(()) +}