You've already forked uutils-args
mirror of
https://github.com/uutils/uutils-args.git
synced 2026-06-10 16:13:08 -07:00
add dd test
This commit is contained in:
@@ -63,7 +63,7 @@ impl InitialField {
|
|||||||
|
|
||||||
fn into_expr(self) -> proc_macro2::TokenStream {
|
fn into_expr(self) -> proc_macro2::TokenStream {
|
||||||
let mut default_value = match self.expr {
|
let mut default_value = match self.expr {
|
||||||
Some(val) => quote!(#val.into()),
|
Some(val) => quote!(#val),
|
||||||
None => quote!(::core::default::Default::default()),
|
None => quote!(::core::default::Default::default()),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ mod basename;
|
|||||||
#[path = "coreutils/cat.rs"]
|
#[path = "coreutils/cat.rs"]
|
||||||
mod cat;
|
mod cat;
|
||||||
|
|
||||||
|
#[path = "coreutils/dd.rs"]
|
||||||
|
mod dd;
|
||||||
|
|
||||||
#[path = "coreutils/echo.rs"]
|
#[path = "coreutils/echo.rs"]
|
||||||
mod echo;
|
mod echo;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,161 @@
|
|||||||
|
// spell-checker:ignore noxfer infile outfile iseek oseek conv iflag oflag iflags oflags
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use uutils_args::{Arguments, Initial, Options, Value};
|
||||||
|
|
||||||
|
#[derive(Value, Debug, PartialEq, Eq)]
|
||||||
|
enum StatusLevel {
|
||||||
|
#[value("none")]
|
||||||
|
None,
|
||||||
|
#[value("noxfer")]
|
||||||
|
Noxfer,
|
||||||
|
#[value("progress")]
|
||||||
|
Progress,
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: The bytes arguments should parse sizes
|
||||||
|
#[derive(Arguments)]
|
||||||
|
enum Arg {
|
||||||
|
#[option("if=FILE")]
|
||||||
|
Infile(PathBuf),
|
||||||
|
|
||||||
|
#[option("of=FILE")]
|
||||||
|
Outfile(PathBuf),
|
||||||
|
|
||||||
|
#[option("ibs=BYTES")]
|
||||||
|
Ibs(usize),
|
||||||
|
|
||||||
|
#[option("obs=BYTES")]
|
||||||
|
Obs(usize),
|
||||||
|
|
||||||
|
#[option("bs=BYTES")]
|
||||||
|
Bs(usize),
|
||||||
|
|
||||||
|
#[option("cbs=BYTES")]
|
||||||
|
Cbs(usize),
|
||||||
|
|
||||||
|
#[option("skip=BYTES", "iseek=BYTES")]
|
||||||
|
Skip(u64),
|
||||||
|
|
||||||
|
#[option("seek=BYTES", "oseek=BYTES")]
|
||||||
|
Seek(u64),
|
||||||
|
|
||||||
|
#[option("count=N")]
|
||||||
|
Count(usize),
|
||||||
|
|
||||||
|
#[option("status=LEVEL")]
|
||||||
|
Status(StatusLevel),
|
||||||
|
|
||||||
|
#[option("conv=CONVERSIONS")]
|
||||||
|
Conv(String),
|
||||||
|
|
||||||
|
#[option("iflag=FLAGS")]
|
||||||
|
Iflag(String),
|
||||||
|
|
||||||
|
#[option("oflag=FLAGS")]
|
||||||
|
Oflag(String),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Initial, Debug, PartialEq, Eq)]
|
||||||
|
struct Settings {
|
||||||
|
infile: Option<PathBuf>,
|
||||||
|
outfile: Option<PathBuf>,
|
||||||
|
#[initial(512)]
|
||||||
|
ibs: usize,
|
||||||
|
#[initial(512)]
|
||||||
|
obs: usize,
|
||||||
|
skip: u64,
|
||||||
|
seek: u64,
|
||||||
|
count: usize,
|
||||||
|
_iconv: Vec<String>,
|
||||||
|
_iflags: Vec<String>,
|
||||||
|
_oconv: Vec<String>,
|
||||||
|
_oflags: Vec<String>,
|
||||||
|
status: Option<StatusLevel>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Options<Arg> for Settings {
|
||||||
|
fn apply(&mut self, arg: Arg) {
|
||||||
|
match arg {
|
||||||
|
Arg::Infile(f) => self.infile = Some(f),
|
||||||
|
Arg::Outfile(f) => self.outfile = Some(f),
|
||||||
|
Arg::Ibs(b) => self.ibs = b,
|
||||||
|
Arg::Obs(b) => self.obs = b,
|
||||||
|
Arg::Bs(b) => {
|
||||||
|
self.ibs = b;
|
||||||
|
self.obs = b;
|
||||||
|
}
|
||||||
|
Arg::Cbs(_) => todo!(),
|
||||||
|
Arg::Skip(b) => self.skip = b,
|
||||||
|
Arg::Seek(b) => self.seek = b,
|
||||||
|
Arg::Count(n) => self.count = n,
|
||||||
|
Arg::Status(level) => self.status = Some(level),
|
||||||
|
Arg::Conv(_) => todo!(),
|
||||||
|
Arg::Iflag(_) => todo!(),
|
||||||
|
Arg::Oflag(_) => todo!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn empty() {
|
||||||
|
assert_eq!(Settings::try_parse(["dd"]).unwrap(), Settings::initial())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn infile() {
|
||||||
|
assert_eq!(
|
||||||
|
Settings::try_parse(["dd", "if=hello"]).unwrap(),
|
||||||
|
Settings {
|
||||||
|
infile: Some(PathBuf::from("hello")),
|
||||||
|
..Settings::initial()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn outfile() {
|
||||||
|
assert_eq!(
|
||||||
|
Settings::try_parse(["dd", "of=hello"]).unwrap(),
|
||||||
|
Settings {
|
||||||
|
outfile: Some(PathBuf::from("hello")),
|
||||||
|
..Settings::initial()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn bs() {
|
||||||
|
assert_eq!(
|
||||||
|
Settings::try_parse(["dd", "ibs=1"]).unwrap(),
|
||||||
|
Settings {
|
||||||
|
ibs: 1,
|
||||||
|
obs: 512,
|
||||||
|
..Settings::initial()
|
||||||
|
}
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
Settings::try_parse(["dd", "obs=1"]).unwrap(),
|
||||||
|
Settings {
|
||||||
|
ibs: 512,
|
||||||
|
obs: 1,
|
||||||
|
..Settings::initial()
|
||||||
|
}
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
Settings::try_parse(["dd", "ibs=10", "obs=1"]).unwrap(),
|
||||||
|
Settings {
|
||||||
|
ibs: 10,
|
||||||
|
obs: 1,
|
||||||
|
..Settings::initial()
|
||||||
|
}
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
Settings::try_parse(["dd", "ibs=10", "bs=1"]).unwrap(),
|
||||||
|
Settings {
|
||||||
|
ibs: 1,
|
||||||
|
obs: 1,
|
||||||
|
..Settings::initial()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user