diff --git a/tests/integration.rs b/tests/integration.rs index 5300a61..353582e 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -291,34 +291,6 @@ fn test_builtin_functions() { ); } -#[test] -#[cfg(feature = "regex_support")] -fn test_regex_functions() { - assert_eq!( - eval("str::regex_matches(\"foobar\", \"[ob]{3}\")"), - Ok(Value::Boolean(true)) - ); - assert_eq!( - eval("str::regex_matches(\"gazonk\", \"[ob]{3}\")"), - Ok(Value::Boolean(false)) - ); - match eval("str::regex_matches(\"foo\", \"[\")") { - Err(EvalexprError::InvalidRegex { regex, message }) => { - assert_eq!(regex, "["); - assert!(message.contains("unclosed character class")); - }, - v => panic!(v), - }; - assert_eq!( - eval("str::regex_replace(\"foobar\", \".*?(o+)\", \"b$1\")"), - Ok(Value::String("boobar".to_owned())) - ); - assert_eq!( - eval("str::regex_replace(\"foobar\", \".*?(i+)\", \"b$1\")"), - Ok(Value::String("foobar".to_owned())) - ); -} - #[test] fn test_errors() { assert_eq!( diff --git a/tests/regex.rs b/tests/regex.rs new file mode 100644 index 0000000..c397825 --- /dev/null +++ b/tests/regex.rs @@ -0,0 +1,30 @@ +#![cfg(feature = "regex_support")] + +use evalexpr::*; + +#[test] +fn test_regex_functions() { + assert_eq!( + eval("str::regex_matches(\"foobar\", \"[ob]{3}\")"), + Ok(Value::Boolean(true)) + ); + assert_eq!( + eval("str::regex_matches(\"gazonk\", \"[ob]{3}\")"), + Ok(Value::Boolean(false)) + ); + match eval("str::regex_matches(\"foo\", \"[\")") { + Err(EvalexprError::InvalidRegex { regex, message }) => { + assert_eq!(regex, "["); + assert!(message.contains("unclosed character class")); + }, + v => panic!(v), + }; + assert_eq!( + eval("str::regex_replace(\"foobar\", \".*?(o+)\", \"b$1\")"), + Ok(Value::String("boobar".to_owned())) + ); + assert_eq!( + eval("str::regex_replace(\"foobar\", \".*?(i+)\", \"b$1\")"), + Ok(Value::String("foobar".to_owned())) + ); +} \ No newline at end of file