diff --git a/src/parsing.rs b/src/parsing.rs index 0d108c1..ca8781d 100644 --- a/src/parsing.rs +++ b/src/parsing.rs @@ -30,7 +30,7 @@ impl BackingFunction { } lazy_static::lazy_static! { - static ref VALID_VARIABLES: Vec = "xeπ".chars().collect(); + static ref VALID_VARIABLES: Vec = "xXEπ".chars().collect(); static ref LETTERS: Vec = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" .chars() .collect(); @@ -130,6 +130,29 @@ pub fn test_func(function_string: &str) -> Option { } } +// Used for testing: passes function to `add_asterisks` before running `test_func` +#[cfg(test)] +fn test_func_helper(function_string: &str) -> Option { + test_func(&add_asterisks(function_string.to_string())) +} + +#[test] +fn test_func_test() { + // These shouldn't fail + assert!(test_func_helper("x^2").is_none()); + assert!(test_func_helper("2x").is_none()); + // assert!(test_func_helper("e^x").is_none()); // need to fix!!! PR to exmex + assert!(test_func_helper("E^x").is_none()); + assert!(test_func_helper("log10(x)").is_none()); + assert!(test_func_helper("xxxxx").is_none()); + + // Expect these to fail + assert!(test_func_helper("a").is_some()); + assert!(test_func_helper("l^2").is_some()); + assert!(test_func_helper("log222(x)").is_some()); + assert!(test_func_helper("abcdef").is_some()); +} + // Tests to make sure my cursed function works as intended #[test] fn asterisk_test() {