test: add rstest crate, argument parsing tests
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum Arguments {
|
||||
Group(GroupAction),
|
||||
Package(PackageAction),
|
||||
Version,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum GroupAction {
|
||||
Edit(Groups),
|
||||
Export(Groups, OutputDir, Force),
|
||||
@@ -16,13 +16,13 @@ pub enum GroupAction {
|
||||
Show(Groups),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct Files(pub Vec<String>);
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct Groups(pub Vec<String>);
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum PackageAction {
|
||||
Clean(Noconfirm),
|
||||
Review,
|
||||
@@ -31,17 +31,17 @@ pub enum PackageAction {
|
||||
Unmanaged,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct Regex(pub String);
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct Edit(pub bool);
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct Noconfirm(pub bool);
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct Force(pub bool);
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct OutputDir(pub Option<String>);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
mod cli;
|
||||
mod datastructure;
|
||||
mod parsing;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
pub use datastructure::*;
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
use super::cli::build_cli;
|
||||
use super::datastructure::*;
|
||||
use super::parsing::parse;
|
||||
|
||||
use rstest::rstest;
|
||||
|
||||
#[rstest]
|
||||
#[case(vec!["pacdef", "group", "list"],
|
||||
Arguments::Group(GroupAction::List))]
|
||||
#[case(vec!["pacdef", "g", "l"],
|
||||
Arguments::Group(GroupAction::List))]
|
||||
#[case(vec!["pacdef", "version"],
|
||||
Arguments::Version)]
|
||||
#[case(vec!["pacdef", "group", "export", "-o", "/tmp", "--force", "base"],
|
||||
Arguments::Group(GroupAction::Export(Groups(vec!["base".to_string()]), OutputDir(Some("/tmp".to_string())), Force(true))))]
|
||||
#[case(vec!["pacdef", "package", "sync"],
|
||||
Arguments::Package(PackageAction::Sync(Noconfirm(false))))]
|
||||
#[case(vec!["pacdef", "package", "sync", "--noconfirm"],
|
||||
Arguments::Package(PackageAction::Sync(Noconfirm(true))))]
|
||||
#[case(vec!["pacdef", "p", "se", "myregex"],
|
||||
Arguments::Package(PackageAction::Search(Regex("myregex".to_string()))))]
|
||||
fn arg_parsing(#[case] input: Vec<&str>, #[case] expected: Arguments) {
|
||||
let args = build_cli().get_matches_from(input);
|
||||
let parsed = parse(args);
|
||||
|
||||
assert_eq!(parsed, expected);
|
||||
}
|
||||
Reference in New Issue
Block a user