2024-05-13 13:37:53 +00:00
|
|
|
use crate::repl::tests::{fail_test, run_test, TestResult};
|
2022-04-07 06:23:14 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn contains() -> TestResult {
|
|
|
|
run_test(r#"'foobarbaz' =~ bar"#, "true")
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn contains_case_insensitive() -> TestResult {
|
|
|
|
run_test(r#"'foobarbaz' =~ '(?i)BaR'"#, "true")
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn not_contains() -> TestResult {
|
|
|
|
run_test(r#"'foobarbaz' !~ asdf"#, "true")
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn match_full_line() -> TestResult {
|
|
|
|
run_test(r#"'foobarbaz' =~ '^foobarbaz$'"#, "true")
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn not_match_full_line() -> TestResult {
|
|
|
|
run_test(r#"'foobarbaz' !~ '^foobarbaz$'"#, "false")
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn starts_with() -> TestResult {
|
|
|
|
run_test(r#"'foobarbaz' =~ '^foo'"#, "true")
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn not_starts_with() -> TestResult {
|
|
|
|
run_test(r#"'foobarbaz' !~ '^foo'"#, "false")
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn ends_with() -> TestResult {
|
|
|
|
run_test(r#"'foobarbaz' =~ 'baz$'"#, "true")
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn not_ends_with() -> TestResult {
|
|
|
|
run_test(r#"'foobarbaz' !~ 'baz$'"#, "false")
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn where_works() -> TestResult {
|
|
|
|
run_test(
|
|
|
|
r#"[{name: somefile.txt} {name: anotherfile.csv }] | where name =~ ^s | get name.0"#,
|
|
|
|
"somefile.txt",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn where_not_works() -> TestResult {
|
|
|
|
run_test(
|
|
|
|
r#"[{name: somefile.txt} {name: anotherfile.csv }] | where name !~ ^s | get name.0"#,
|
|
|
|
"anotherfile.csv",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn invalid_regex_fails() -> TestResult {
|
2022-08-04 19:51:02 +00:00
|
|
|
fail_test(r#"'foo' =~ '['"#, "Invalid character class")
|
2022-04-07 06:23:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn invalid_not_regex_fails() -> TestResult {
|
2022-08-04 19:51:02 +00:00
|
|
|
fail_test(r#"'foo' !~ '['"#, "Invalid character class")
|
2022-04-07 06:23:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn regex_on_int_fails() -> TestResult {
|
2023-04-07 21:32:44 +00:00
|
|
|
fail_test(r#"33 =~ foo"#, "is not supported")
|
2022-04-07 06:23:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn not_regex_on_int_fails() -> TestResult {
|
2023-04-07 21:32:44 +00:00
|
|
|
fail_test(r#"33 !~ foo"#, "is not supported")
|
2022-04-07 06:23:14 +00:00
|
|
|
}
|