From 40f6575989be47f835fc341052703b8f1a5235b9 Mon Sep 17 00:00:00 2001 From: zwPapEr Date: Sat, 13 Mar 2021 11:35:42 +0800 Subject: [PATCH] test: :mag: :hammer: fix tree test without sort Signed-off-by: zwPapEr --- src/display.rs | 17 ++++++++++++++--- src/meta/filetype.rs | 5 ++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/display.rs b/src/display.rs index 37250d98f..88c755548 100644 --- a/src/display.rs +++ b/src/display.rs @@ -85,7 +85,7 @@ fn inner_display_grid( for meta in metas { // Maybe skip showing the directory meta now; show its contents later. if skip_dirs - && (matches!(meta.file_type, FileType::Directory{..}) + && (matches!(meta.file_type, FileType::Directory { .. }) || (matches!(meta.file_type, FileType::SymLink { is_dir: true }) && flags.layout != Layout::OneLine)) { @@ -363,10 +363,10 @@ mod tests { use crate::app; use crate::color; use crate::color::Colors; - use crate::icon; use crate::icon::Icons; use crate::meta::{FileType, Name}; use crate::Config; + use crate::{flags, icon, sort}; use assert_fs::prelude::*; use std::path::Path; @@ -504,6 +504,16 @@ mod tests { } } + fn sort(metas: &mut Vec, sorters: &Vec<(flags::SortOrder, sort::SortFn)>) { + metas.sort_unstable_by(|a, b| sort::by_meta(sorters, a, b)); + + for meta in metas { + if let Some(ref mut content) = meta.content { + sort(content, sorters); + } + } + } + #[test] fn test_display_tree_with_all() { let argv = vec!["lsd", "--tree", "--all"]; @@ -514,11 +524,12 @@ mod tests { dir.child("one.d").create_dir_all().unwrap(); dir.child("one.d/two").touch().unwrap(); dir.child("one.d/.hidden").touch().unwrap(); - let metas = Meta::from_path(Path::new(dir.path()), false) + let mut metas = Meta::from_path(Path::new(dir.path()), false) .unwrap() .recurse_into(42, &flags) .unwrap() .unwrap(); + sort(&mut metas, &sort::assemble_sorters(&flags)); let output = tree( &metas, &flags, diff --git a/src/meta/filetype.rs b/src/meta/filetype.rs index e7c275f8c..0787d14dd 100644 --- a/src/meta/filetype.rs +++ b/src/meta/filetype.rs @@ -81,7 +81,10 @@ impl FileType { } pub fn is_dirlike(self) -> bool { - matches!(self, FileType::Directory { .. } | FileType::SymLink { is_dir: true }) + matches!( + self, + FileType::Directory { .. } | FileType::SymLink { is_dir: true } + ) } }