-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use super::Rule; | ||
use crate::{cli::command::CrabCommand, shell::Shell}; | ||
|
||
pub fn match_rule(command: &mut CrabCommand, system_shell: Option<&dyn Shell>) -> bool { | ||
if let Some(output) = &command.output { | ||
command.script.starts_with("man") && output.contains("command not found") | ||
} else { | ||
false | ||
} | ||
} | ||
|
||
pub fn get_new_command(command: &mut CrabCommand, system_shell: Option<&dyn Shell>) -> Vec<String> { | ||
vec![format!("man {}", &command.script[3..])] | ||
} | ||
|
||
pub fn get_rule() -> Rule { | ||
Rule::new( | ||
"man_no_space".to_owned(), | ||
None, | ||
Some(2000), | ||
None, | ||
match_rule, | ||
get_new_command, | ||
None, | ||
) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::{get_new_command, match_rule}; | ||
use crate::cli::command::CrabCommand; | ||
use crate::shell::Bash; | ||
use rstest::rstest; | ||
|
||
#[rstest] | ||
#[case("mandiff", "mandiff: command not found", true)] | ||
#[case("", "", false)] | ||
fn test_match(#[case] command: &str, #[case] stdout: &str, #[case] is_match: bool) { | ||
let mut command = CrabCommand::new(command.to_owned(), Some(stdout.to_owned()), None); | ||
assert_eq!(match_rule(&mut command, None), is_match); | ||
} | ||
|
||
#[rstest] | ||
#[case("mandiff", "", vec!["man diff"])] | ||
fn test_get_new_command( | ||
#[case] command: &str, | ||
#[case] stdout: &str, | ||
#[case] expected: Vec<&str>, | ||
) { | ||
let system_shell = Bash {}; | ||
let mut command = CrabCommand::new(command.to_owned(), Some(stdout.to_owned()), None); | ||
assert_eq!(get_new_command(&mut command, None), expected); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters