use crate::utils::long_command::{Detach, classify, is_known_long};
#[test]
fn known_long_matches_the_named_cases() {
assert!(is_known_long("cargo test --all-features"));
assert!(is_known_long("cd ~/proj && cargo build --release"));
assert!(is_known_long("npx remotion render Main out/x.mp4"));
assert!(is_known_long("gh run watch 12345"));
assert!(!is_known_long("ls -la"));
assert!(!is_known_long("git status"));
assert!(!is_known_long("cat README.md"));
}
#[test]
fn markers_in_command_position_still_background() {
assert!(is_known_long("cargo test --all-features --lib plan_tool"));
assert!(is_known_long("cargo fmt; echo done; cargo clippy --locked"));
assert!(is_known_long("W=$(cargo clippy --all-features 2>&1)"));
assert!(is_known_long("cargo fmt\ncargo test --lib"));
assert!(is_known_long("for f in a b; do cargo test --lib; done"));
assert!(is_known_long("time cargo build --release"));
}
#[test]
fn a_marker_that_is_only_mentioned_runs_inline() {
assert!(!is_known_long(
"cat > /tmp/note.md <<'EOF'\nRun cargo test --all-features to verify.\nEOF"
));
assert!(!is_known_long(
"cat >> src/tests/x.rs <<'RUST'\ncargo test --lib\nRUST"
));
assert!(!is_known_long(
"grep -c -i \"cargo test\\|cargo clippy\" src/tests/x.rs"
));
assert!(!is_known_long(
"python3 - <<'PY'\ns = \"cargo clippy --all-features\"\nPY"
));
assert!(!is_known_long("cat > x <<EOF\ncargo build --release\nEOF"));
assert!(!is_known_long("echo \"cargo build --release\""));
}
#[test]
fn a_here_string_is_not_a_heredoc() {
assert!(is_known_long("cat <<< hello\ncargo test --lib"));
}
#[test]
fn classify_reports_why_a_command_ran_inline() {
assert_eq!(
classify("cargo test --lib"),
Detach::Yes {
marker: "cargo test"
}
);
assert_eq!(
classify("echo \"cargo test --lib\""),
Detach::Mentioned {
marker: "cargo test"
}
);
assert_eq!(classify("git status"), Detach::No);
}