mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-06-02 07:20:48 +00:00
Add some tests for the time flags
Apparently I forgot to give the --time flag an argument, and this wasn’t actually covered by any of the xtests! Well, it’s tested now. I’m not sure how to handle multiple --time arguments.
This commit is contained in:
parent
817c7d2318
commit
06157fdedd
|
@ -38,7 +38,7 @@ pub static INODE: Arg = Arg { short: Some(b'i'), long: "inode", takes_
|
|||
pub static LINKS: Arg = Arg { short: Some(b'H'), long: "links", takes_value: TakesValue::Forbidden };
|
||||
pub static MODIFIED: Arg = Arg { short: Some(b'm'), long: "modified", takes_value: TakesValue::Forbidden };
|
||||
pub static BLOCKS: Arg = Arg { short: Some(b'S'), long: "blocks", takes_value: TakesValue::Forbidden };
|
||||
pub static TIME: Arg = Arg { short: Some(b't'), long: "time", takes_value: TakesValue::Forbidden };
|
||||
pub static TIME: Arg = Arg { short: Some(b't'), long: "time", takes_value: TakesValue::Necessary };
|
||||
pub static ACCESSED: Arg = Arg { short: Some(b'u'), long: "accessed", takes_value: TakesValue::Forbidden };
|
||||
pub static CREATED: Arg = Arg { short: Some(b'U'), long: "created", takes_value: TakesValue::Forbidden };
|
||||
pub static TIME_STYLE: Arg = Arg { short: None, long: "time-style", takes_value: TakesValue::Necessary };
|
||||
|
|
|
@ -253,6 +253,8 @@ impl TimeFormat {
|
|||
}
|
||||
|
||||
|
||||
static TIMES: &[&str] = &["modified", "accessed", "created"];
|
||||
|
||||
impl TimeTypes {
|
||||
|
||||
/// Determine which of a file’s time fields should be displayed for it
|
||||
|
@ -282,7 +284,6 @@ impl TimeTypes {
|
|||
return Err(Misfire::Useless(&flags::ACCESSED, true, &flags::TIME));
|
||||
}
|
||||
|
||||
static TIMES: &[&str] = &["modified", "accessed", "created"];
|
||||
if word == "mod" || word == "modified" {
|
||||
Ok(TimeTypes { accessed: false, modified: true, created: false })
|
||||
}
|
||||
|
@ -423,7 +424,8 @@ mod test {
|
|||
use options::parser::{parse, Args, Arg};
|
||||
use std::ffi::OsString;
|
||||
|
||||
static TEST_ARGS: &[&Arg] = &[ &flags::BINARY, &flags::BYTES ];
|
||||
static TEST_ARGS: &[&Arg] = &[ &flags::BINARY, &flags::BYTES,
|
||||
&flags::TIME, &flags::MODIFIED, &flags::CREATED, &flags::ACCESSED ];
|
||||
|
||||
let bits = $inputs.as_ref().into_iter().map(|&o| os(o)).collect::<Vec<OsString>>();
|
||||
let results = parse(&Args(TEST_ARGS), bits.iter());
|
||||
|
@ -432,6 +434,7 @@ mod test {
|
|||
};
|
||||
}
|
||||
|
||||
|
||||
mod size_formats {
|
||||
use super::*;
|
||||
|
||||
|
@ -440,4 +443,36 @@ mod test {
|
|||
test!(bytes: SizeFormat <- ["--bytes"] => Ok(SizeFormat::JustBytes));
|
||||
test!(both: SizeFormat <- ["--binary", "--bytes"] => Err(Misfire::Conflict(&flags::BINARY, &flags::BYTES)));
|
||||
}
|
||||
|
||||
|
||||
mod time_types {
|
||||
use super::*;
|
||||
|
||||
// Default behaviour
|
||||
test!(empty: TimeTypes <- [] => Ok(TimeTypes::default()));
|
||||
test!(modified: TimeTypes <- ["--modified"] => Ok(TimeTypes { accessed: false, modified: true, created: false }));
|
||||
test!(m: TimeTypes <- ["-m"] => Ok(TimeTypes { accessed: false, modified: true, created: false }));
|
||||
test!(time_mod: TimeTypes <- ["--time=modified"] => Ok(TimeTypes { accessed: false, modified: true, created: false }));
|
||||
test!(time_m: TimeTypes <- ["-tmod"] => Ok(TimeTypes { accessed: false, modified: true, created: false }));
|
||||
|
||||
test!(acc: TimeTypes <- ["--accessed"] => Ok(TimeTypes { accessed: true, modified: false, created: false }));
|
||||
test!(a: TimeTypes <- ["-u"] => Ok(TimeTypes { accessed: true, modified: false, created: false }));
|
||||
test!(time_acc: TimeTypes <- ["--time", "accessed"] => Ok(TimeTypes { accessed: true, modified: false, created: false }));
|
||||
test!(time_a: TimeTypes <- ["-t", "acc"] => Ok(TimeTypes { accessed: true, modified: false, created: false }));
|
||||
|
||||
test!(cr: TimeTypes <- ["--created"] => Ok(TimeTypes { accessed: false, modified: false, created: true }));
|
||||
test!(c: TimeTypes <- ["-U"] => Ok(TimeTypes { accessed: false, modified: false, created: true }));
|
||||
test!(time_cr: TimeTypes <- ["--time=created"] => Ok(TimeTypes { accessed: false, modified: false, created: true }));
|
||||
test!(time_c: TimeTypes <- ["-tcr"] => Ok(TimeTypes { accessed: false, modified: false, created: true }));
|
||||
|
||||
// Multiples
|
||||
test!(time_uu: TimeTypes <- ["-uU"] => Ok(TimeTypes { accessed: true, modified: false, created: true }));
|
||||
|
||||
// Overriding
|
||||
test!(time_mc: TimeTypes <- ["-tcr", "-tmod"] => Ok(TimeTypes { accessed: false, modified: true, created: false }));
|
||||
|
||||
// Errors
|
||||
test!(time_tea: TimeTypes <- ["--time=tea"] => Err(Misfire::bad_argument(&flags::TIME, &os("tea"), super::TIMES)));
|
||||
test!(time_ea: TimeTypes <- ["-tea"] => Err(Misfire::bad_argument(&flags::TIME, &os("ea"), super::TIMES)));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user