use crate::brain::tools::bash::*;
#[test]
fn grep_no_match_is_success() {
assert!(is_search_no_match("grep foo file.txt", 1, ""));
assert!(is_search_no_match("grep -r 'pattern' /path", 1, " \n "));
}
#[test]
fn grep_real_error_is_failure() {
assert!(!is_search_no_match(
"grep foo file.txt",
2,
"grep: file.txt: No such file or directory"
));
assert!(!is_search_no_match(
"grep [invalid",
1,
"grep: invalid regex"
));
}
#[test]
fn non_grep_exit_1_is_failure() {
assert!(!is_search_no_match("ls /nonexistent", 1, ""));
assert!(!is_search_no_match("cat missing.txt", 1, ""));
}
#[test]
fn piped_grep_no_match_is_success() {
assert!(is_search_no_match("cat file.txt | grep foo", 1, ""));
assert!(is_search_no_match("echo bar | grep baz", 1, ""));
}
#[test]
fn git_grep_no_match_is_success() {
assert!(is_search_no_match("git grep 'nonexistent'", 1, ""));
assert!(is_search_no_match("git grep -i pattern", 1, ""));
}
#[test]
fn rg_no_match_is_success() {
assert!(is_search_no_match("rg 'pattern'", 1, ""));
assert!(is_search_no_match("rg --type rust foo", 1, ""));
}
#[test]
fn egrep_fgrep_no_match_is_success() {
assert!(is_search_no_match("egrep 'pattern'", 1, ""));
assert!(is_search_no_match("fgrep 'literal'", 1, ""));
}
#[test]
fn grep_as_argument_not_command() {
assert!(!is_search_no_match("echo grep", 1, ""));
assert!(!is_search_no_match("cat file | wc -l", 1, ""));
}