Refactor regex tests into own module
This commit is contained in:
parent
e1ef617eaa
commit
15cdb3eb50
@ -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]
|
#[test]
|
||||||
fn test_errors() {
|
fn test_errors() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
30
tests/regex.rs
Normal file
30
tests/regex.rs
Normal file
@ -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()))
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user