Align tables in "ls -f" (#2105)

* Stuff column with nothing if we have nothing

* Stuff columns at the very start

Remove unnecessary else clauses.
Add the unix cfg portion

* Added some tests and cfg windows

Not sure how I feel about these tests but it's better than nothing
This commit is contained in:
Arash Outadi
2020-07-04 13:17:36 -07:00
committed by GitHub
parent e75c44c95b
commit efd8a633f2
2 changed files with 92 additions and 23 deletions

View File

@ -1,5 +1,5 @@
use nu_test_support::fs::Stub::EmptyFile;
use nu_test_support::playground::Playground;
use nu_test_support::playground::{Dirs, Playground};
use nu_test_support::{nu, pipeline};
#[test]
@ -154,3 +154,60 @@ fn list_files_from_two_parents_up_using_multiple_dots() {
assert_eq!(actual.out, "5");
})
}
#[test]
fn list_all_columns() {
Playground::setup(
"ls_test_all_columns",
|dirs: Dirs, sandbox: &mut Playground| {
sandbox.with_files(vec![
EmptyFile("Leonardo.yaml"),
EmptyFile("Raphael.json"),
EmptyFile("Donatello.xml"),
EmptyFile("Michelangelo.txt"),
]);
// Normal Operation
let actual = nu!(
cwd: dirs.test(),
"ls | get | to md"
);
let expected = ["name", "type", "size", "modified"].join("");
assert_eq!(actual.out, expected, "column names are incorrect for ls");
// Symbolic Links
let actual = nu!(
cwd: dirs.test(),
"ls -w | get | to md"
);
let expected = ["name", "type", "target", "size", "modified"].join("");
assert_eq!(actual.out, expected, "column names are incorrect for ls -w");
// Full
let actual = nu!(
cwd: dirs.test(),
"ls -f | get | to md"
);
let expected = {
#[cfg(unix)]
{
[
"name", "type", "target", "readonly", "mode", "uid", "group", "size",
"created", "accessed", "modified",
]
.join("")
}
#[cfg(windows)]
{
[
"name", "type", "target", "readonly", "size", "created", "accessed",
"modified",
]
.join("")
}
};
assert_eq!(
actual.out, expected,
"column names are incorrect for ls full"
);
},
);
}