use super::*;
#[test]
fn rg_type_falls_through() {
assert_eq!(
rewrite_candidate("rg -t rust pattern src/", "lean-ctx"),
Some(expect_wrapped("rg -t rust pattern src/", "lean-ctx"))
);
}
#[test]
fn rg_glob_falls_through() {
assert_eq!(
rewrite_candidate("rg --glob=*.rs pattern src/", "lean-ctx"),
Some(expect_wrapped("rg --glob=*.rs pattern src/", "lean-ctx"))
);
}
#[test]
fn rg_context_falls_through() {
assert_eq!(
rewrite_candidate("rg -A5 pattern file.rs", "lean-ctx"),
Some(expect_wrapped("rg -A5 pattern file.rs", "lean-ctx"))
);
}
#[test]
fn rg_json_falls_through() {
assert_eq!(
rewrite_candidate("rg --json pattern src/", "lean-ctx"),
Some(expect_wrapped("rg --json pattern src/", "lean-ctx"))
);
}
#[test]
fn is_shell_tool_covers_all_ide_variants() {
for name in [
"run_command",
"run_shell_command",
"execute_command",
"exec_command",
"command_exec",
"run_terminal",
"runterminal",
"run",
"exec",
"execute",
"command",
"cmd",
"sh",
] {
assert!(
is_shell_tool(name),
"{name} must be recognized as shell tool"
);
}
}
#[test]
fn andis_real_world_grep_keeps_bre_alternation_on_native_grep() {
let cmd = r#"grep -rn "func\|Interval\|Duration" src/"#;
let rewritten = rewrite_candidate(cmd, "lean-ctx").expect("grep -rn is still wrapped");
assert!(
!rewritten.starts_with("lean-ctx grep"),
"BRE alternation must not be handed to lean-ctx grep: {rewritten}"
);
assert!(
rewritten.starts_with("lean-ctx -c"),
"must fall through to the -c wrap so native grep resolves it: {rewritten}"
);
assert!(
rewritten.contains("func") && rewritten.contains("Interval"),
"pattern must be preserved: {rewritten}"
);
}
#[test]
fn egrep_alternation_still_routes_to_lean_ctx_grep() {
let rewritten = rewrite_candidate(r#"egrep -rn "func|Interval" src/"#, "lean-ctx")
.expect("egrep must be rewritten");
assert!(
rewritten.starts_with("lean-ctx grep"),
"egrep is ERE and maps losslessly: {rewritten}"
);
}
#[test]
fn bare_bre_metachars_are_literals_and_must_not_be_handed_over() {
for pattern in [
r#"grep -n "headroom|HEADROOM" db.py"#,
r#"grep -n "headroom+" db.py"#,
r#"grep -n "set_(headroom)" db.py"#,
r#"grep -n "o{2}" db.py"#,
] {
let rewritten = rewrite_candidate(pattern, "lean-ctx").expect("still wrapped");
assert!(
!rewritten.starts_with("lean-ctx grep"),
"{pattern} must not reach lean-ctx grep: {rewritten}"
);
}
}
#[test]
fn plain_bre_patterns_keep_the_fast_path() {
let rewritten =
rewrite_candidate(r#"grep -rn "headroom" src/"#, "lean-ctx").expect("must be rewritten");
assert!(
rewritten.starts_with("lean-ctx grep"),
"unambiguous BRE must keep the fast path: {rewritten}"
);
}