80 lines
2.2 KiB
Rust
80 lines
2.2 KiB
Rust
use comlexr::cmd;
|
|
use rstest::rstest;
|
|
|
|
#[test]
|
|
fn expression() {
|
|
let command = cmd!("echo", "test");
|
|
|
|
assert_eq!(format!("{command:?}"), r#""echo" "test""#.to_string());
|
|
}
|
|
|
|
#[rstest]
|
|
#[case(false, false, r#""echo" "test""#)]
|
|
#[case(true, false, r#""echo" "test" "single""#)]
|
|
#[case(false, true, r#""echo" "test" "multi" "arg""#)]
|
|
#[case(true, true, r#""echo" "test" "single" "multi" "arg""#)]
|
|
fn if_statement(#[case] single: bool, #[case] multi: bool, #[case] expected: &str) {
|
|
let command = cmd!(
|
|
"echo",
|
|
"test",
|
|
if single => "single",
|
|
if multi => [
|
|
"multi",
|
|
"arg",
|
|
],
|
|
);
|
|
|
|
assert_eq!(format!("{command:?}"), expected.to_string());
|
|
}
|
|
|
|
#[rstest]
|
|
#[case(&[], r#""echo" "test""#)]
|
|
#[case(&["1", "2"], r#""echo" "test" "1" "2""#)]
|
|
fn for_iter(#[case] iter: &[&str], #[case] expected: &str) {
|
|
let command = cmd!(
|
|
"echo",
|
|
"test",
|
|
for iter,
|
|
);
|
|
|
|
assert_eq!(format!("{command:?}"), expected.to_string());
|
|
}
|
|
|
|
#[rstest]
|
|
#[case(&[], &[], r#""echo" "test""#)]
|
|
#[case(&["1", "2"], &[], r#""echo" "test" "1" "2""#)]
|
|
#[case(&[], &["3", "4"], r#""echo" "test" "multi" "3" "multi" "4""#)]
|
|
#[case(&["1", "2"], &["3", "4"], r#""echo" "test" "1" "2" "multi" "3" "multi" "4""#)]
|
|
fn for_in(#[case] single_iter: &[&str], #[case] multi_iter: &[&str], #[case] expected: &str) {
|
|
let command = cmd!(
|
|
"echo",
|
|
"test",
|
|
for arg in single_iter => arg,
|
|
for arg in multi_iter => [
|
|
"multi",
|
|
arg,
|
|
],
|
|
);
|
|
|
|
assert_eq!(format!("{command:?}"), expected.to_string());
|
|
}
|
|
|
|
#[rstest]
|
|
#[case(None, None, r#""echo" "test""#)]
|
|
#[case(Some("arg"), None, r#""echo" "test" "arg""#)]
|
|
#[case(None, Some("arg"), r#""echo" "test" "multi" "arg""#)]
|
|
#[case(Some("1"), Some("2"), r#""echo" "test" "1" "multi" "2""#)]
|
|
fn if_let(#[case] single: Option<&str>, #[case] multi: Option<&str>, #[case] expected: &str) {
|
|
let command = cmd!(
|
|
"echo",
|
|
"test",
|
|
if let Some(arg) = single => arg,
|
|
if let Some(arg) = multi => [
|
|
"multi",
|
|
arg,
|
|
],
|
|
);
|
|
|
|
assert_eq!(format!("{command:?}"), expected.to_string());
|
|
}
|