use crate::repl::tests::{TestResult, fail_test, run_test};
#[test]
fn contains() -> TestResult {
run_test("'foobarbaz' =~ bar", "true")
}
#[test]
fn contains_case_insensitive() -> TestResult {
run_test("'foobarbaz' =~ '(?i)BaR'", "true")
}
#[test]
fn not_contains() -> TestResult {
run_test("'foobarbaz' !~ asdf", "true")
}
#[test]
fn match_full_line() -> TestResult {
run_test("'foobarbaz' =~ '^foobarbaz$'", "true")
}
#[test]
fn not_match_full_line() -> TestResult {
run_test("'foobarbaz' !~ '^foobarbaz$'", "false")
}
#[test]
fn starts_with() -> TestResult {
run_test("'foobarbaz' =~ '^foo'", "true")
}
#[test]
fn not_starts_with() -> TestResult {
run_test("'foobarbaz' !~ '^foo'", "false")
}
#[test]
fn ends_with() -> TestResult {
run_test("'foobarbaz' =~ 'baz$'", "true")
}
#[test]
fn not_ends_with() -> TestResult {
run_test("'foobarbaz' !~ 'baz$'", "false")
}
#[test]
fn where_works() -> TestResult {
run_test(
"[{name: somefile.txt} {name: anotherfile.csv }] | where name =~ ^s | get name.0",
"somefile.txt",
)
}
#[test]
fn where_not_works() -> TestResult {
run_test(
"[{name: somefile.txt} {name: anotherfile.csv }] | where name !~ ^s | get name.0",
"anotherfile.csv",
)
}
#[test]
fn invalid_regex_fails() -> TestResult {
fail_test("'foo' =~ '['", "Invalid character class")
}
#[test]
fn invalid_not_regex_fails() -> TestResult {
fail_test("'foo' !~ '['", "Invalid character class")
}
#[test]
fn regex_on_int_fails() -> TestResult {
fail_test("33 =~ foo", "nu::parser::operator_unsupported_type")
}
#[test]
fn not_regex_on_int_fails() -> TestResult {
fail_test("33 !~ foo", "nu::parser::operator_unsupported_type")
}