mirror of
https://github.com/lsd-rs/lsd.git
synced 2026-02-16 20:24:47 +02:00
Add unit tests
This commit is contained in:
@@ -349,17 +349,14 @@ mod tests {
|
||||
assert_eq!(
|
||||
Config {
|
||||
classic: Some(false),
|
||||
blocks: Some(
|
||||
vec![
|
||||
"permission".into(),
|
||||
"user".into(),
|
||||
"group".into(),
|
||||
"size".into(),
|
||||
"date".into(),
|
||||
"name".into(),
|
||||
]
|
||||
.into()
|
||||
),
|
||||
blocks: Some(vec![
|
||||
"permission".into(),
|
||||
"user".into(),
|
||||
"group".into(),
|
||||
"size".into(),
|
||||
"date".into(),
|
||||
"name".into(),
|
||||
]),
|
||||
color: Some(config_file::Color {
|
||||
when: Some(ColorOption::Auto),
|
||||
theme: Some(ThemeOption::Default)
|
||||
|
||||
@@ -114,7 +114,7 @@ fn inner_display_grid(
|
||||
|
||||
// Print block headers
|
||||
if flags.header.0 && flags.layout == Layout::OneLine && !cells.is_empty() {
|
||||
add_header(flags, &cells, &mut grid);
|
||||
add_header(flags, &cells, &mut grid);
|
||||
}
|
||||
|
||||
for cell in cells {
|
||||
@@ -741,4 +741,72 @@ mod tests {
|
||||
|
||||
assert!(output.ends_with("└── two\n"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_grid_all_block_headers() {
|
||||
let argv = vec![
|
||||
"lsd",
|
||||
"--header",
|
||||
"--blocks",
|
||||
"permission,user,group,size,date,name,inode,links",
|
||||
];
|
||||
let matches = app::build().get_matches_from_safe(argv).unwrap();
|
||||
let flags = Flags::configure_from(&matches, &Config::with_none()).unwrap();
|
||||
|
||||
let dir = assert_fs::TempDir::new().unwrap();
|
||||
dir.child("testdir").create_dir_all().unwrap();
|
||||
dir.child("test").touch().unwrap();
|
||||
let metas = Meta::from_path(Path::new(dir.path()), false)
|
||||
.unwrap()
|
||||
.recurse_into(1, &flags)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
let output = grid(
|
||||
&metas,
|
||||
&flags,
|
||||
&Colors::new(color::ThemeOption::NoColor),
|
||||
&Icons::new(icon::Theme::NoIcon, " ".to_string()),
|
||||
);
|
||||
|
||||
dir.close().unwrap();
|
||||
|
||||
assert!(output.contains("Permissions"));
|
||||
assert!(output.contains("User"));
|
||||
assert!(output.contains("Group"));
|
||||
assert!(output.contains("Size"));
|
||||
assert!(output.contains("Date Modified"));
|
||||
assert!(output.contains("Name"));
|
||||
assert!(output.contains("INode"));
|
||||
assert!(output.contains("Links"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_grid_no_header_with_empty_meta() {
|
||||
let argv = vec!["lsd", "--header", "-l"];
|
||||
let matches = app::build().get_matches_from_safe(argv).unwrap();
|
||||
let flags = Flags::configure_from(&matches, &Config::with_none()).unwrap();
|
||||
|
||||
let dir = assert_fs::TempDir::new().unwrap();
|
||||
dir.child("testdir").create_dir_all().unwrap();
|
||||
let metas = Meta::from_path(Path::new(dir.path()), false)
|
||||
.unwrap()
|
||||
.recurse_into(1, &flags)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
let output = grid(
|
||||
&metas,
|
||||
&flags,
|
||||
&Colors::new(color::ThemeOption::NoColor),
|
||||
&Icons::new(icon::Theme::NoIcon, " ".to_string()),
|
||||
);
|
||||
|
||||
dir.close().unwrap();
|
||||
|
||||
assert!(!output.contains("Permissions"));
|
||||
assert!(!output.contains("User"));
|
||||
assert!(!output.contains("Group"));
|
||||
assert!(!output.contains("Size"));
|
||||
assert!(!output.contains("Date Modified"));
|
||||
assert!(!output.contains("Name"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -597,4 +597,18 @@ mod test_block {
|
||||
fn test_context() {
|
||||
assert_eq!(Ok(Block::Context), Block::try_from("context"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_block_headers() {
|
||||
assert_eq!(Block::INode.get_header(), String::from("INode"));
|
||||
assert_eq!(Block::Links.get_header(), String::from("Links"));
|
||||
assert_eq!(Block::Permission.get_header(), String::from("Permissions"));
|
||||
assert_eq!(Block::User.get_header(), String::from("User"));
|
||||
assert_eq!(Block::Group.get_header(), String::from("Group"));
|
||||
assert_eq!(Block::Context.get_header(), String::from("Context"));
|
||||
assert_eq!(Block::Size.get_header(), String::from("Size"));
|
||||
assert_eq!(Block::SizeValue.get_header(), String::from("SizeValue"));
|
||||
assert_eq!(Block::Date.get_header(), String::from("Date Modified"));
|
||||
assert_eq!(Block::Name.get_header(), String::from("Name"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user