display/tree: 🔍 add test for tree with all not show self

Signed-off-by: zwPapEr <zw.paper@gmail.com>
This commit is contained in:
zwPapEr 2021-02-14 22:02:40 +08:00 committed by Abin Simon
parent 36002a35ac
commit 0ca699ee2f
3 changed files with 49 additions and 0 deletions

View file

@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add support for `TIME_STYLE` environment variable from [999eagle](https://github.com/999eagle)
- Add man page from [edneville](https://github.com/edneville)
### Changed
- Not showing `.` and `..` when `--tree` with `--all` from [zwpaper](https://github.com/zwpaper) [#477](https://github.com/Peltoche/lsd/issues/477)
### Fixed
- Fix handling blocks passed without -l in cli from [meain](https://github.com/meain)

View file

@ -345,11 +345,14 @@ fn get_padding_rules(metas: &[Meta], flags: &Flags) -> HashMap<Block, usize> {
#[cfg(test)]
mod tests {
use super::*;
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 assert_fs::prelude::*;
use std::path::Path;
#[test]
@ -485,4 +488,31 @@ mod tests {
assert_eq!(get_visible_width(&output), *l);
}
}
#[test]
fn test_display_tree_with_all() {
let argv = vec!["lsd", "--tree", "--all"];
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("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)
.unwrap()
.recurse_into(42, &flags)
.unwrap()
.unwrap();
let output = inner_display_tree(
&metas,
&flags,
&Colors::new(color::Theme::NoColor),
&Icons::new(icon::Theme::NoIcon, " ".to_string()),
0,
"",
);
assert_eq!("one.d\n├── .hidden\n└── two\n", output);
}
}

View file

@ -414,6 +414,24 @@ fn test_tree() {
.stdout(predicate::str::is_match("├── one\n└── one.d\n └── two\n$").unwrap());
}
#[test]
fn test_tree_all_not_show_self() {
let tmp = tempdir();
tmp.child("one").touch().unwrap();
tmp.child("one.d").create_dir_all().unwrap();
tmp.child("one.d/two").touch().unwrap();
tmp.child("one.d/.hidden").touch().unwrap();
cmd()
.arg(tmp.path())
.arg("--tree")
.arg("--all")
.assert()
.stdout(
predicate::str::is_match("├── one\n└── one.d\n ├── .hidden\n └── two\n$").unwrap(),
);
}
#[test]
fn test_tree_d() {
let tmp = tempdir();