mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-06-03 16:00:49 +00:00
Merge branch 'sort-tests'
Adds some tests for sorting, and also adds --sort=type functionality. Fixes #113.
This commit is contained in:
commit
22c6fb048f
|
@ -53,7 +53,7 @@ These options are available when running with --long (`-l`):
|
|||
- **--git**: list each file's Git status, if tracked
|
||||
|
||||
- Valid **--color** options are **always**, **automatic**, and **never**.
|
||||
- Valid sort fields are **accessed**, **created**, **extension**, **Extension**, **inode**, **modified**, **name**, **Name**, **size**, and **none**. Fields starting with a capital letter are case-sensitive.
|
||||
- Valid sort fields are **accessed**, **created**, **extension**, **Extension**, **inode**, **modified**, **name**, **Name**, **size**, **type**, and **none**. Fields starting with a capital letter are case-sensitive.
|
||||
- Valid time fields are **modified**, **accessed**, and **created**.
|
||||
|
||||
|
||||
|
|
14
Vagrantfile
vendored
14
Vagrantfile
vendored
|
@ -139,22 +139,22 @@ Vagrant.configure(2) do |config|
|
|||
|
||||
|
||||
# File name extension testcases.
|
||||
# These are tested in grid view, so we don’t need to bother setting
|
||||
# owners or timestamps or anything.
|
||||
# These aren’t tested in details view, but we set timestamps on them to
|
||||
# test that various sort options work.
|
||||
config.vm.provision :shell, privileged: false, inline: <<-EOF
|
||||
set -xe
|
||||
mkdir "#{test_dir}/file-names-exts"
|
||||
|
||||
touch "#{test_dir}/file-names-exts/Makefile"
|
||||
|
||||
touch "#{test_dir}/file-names-exts/image.png"
|
||||
touch "#{test_dir}/file-names-exts/IMAGE.PNG"
|
||||
touch "#{test_dir}/file-names-exts/image.svg"
|
||||
|
||||
touch "#{test_dir}/file-names-exts/video.avi"
|
||||
touch "#{test_dir}/file-names-exts/VIDEO.AVI"
|
||||
touch "#{test_dir}/file-names-exts/video.wmv"
|
||||
|
||||
touch "#{test_dir}/file-names-exts/music.mp3"
|
||||
touch "#{test_dir}/file-names-exts/music.ogg"
|
||||
touch "#{test_dir}/file-names-exts/MUSIC.OGG"
|
||||
|
||||
touch "#{test_dir}/file-names-exts/lossless.flac"
|
||||
touch "#{test_dir}/file-names-exts/lossless.wav"
|
||||
|
@ -163,9 +163,9 @@ Vagrant.configure(2) do |config|
|
|||
touch "#{test_dir}/file-names-exts/crypto.signature"
|
||||
|
||||
touch "#{test_dir}/file-names-exts/document.pdf"
|
||||
touch "#{test_dir}/file-names-exts/document.xlsx"
|
||||
touch "#{test_dir}/file-names-exts/DOCUMENT.XLSX"
|
||||
|
||||
touch "#{test_dir}/file-names-exts/compressed.zip"
|
||||
touch "#{test_dir}/file-names-exts/COMPRESSED.ZIP"
|
||||
touch "#{test_dir}/file-names-exts/compressed.tar.gz"
|
||||
touch "#{test_dir}/file-names-exts/compressed.tgz"
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ _exa()
|
|||
;;
|
||||
|
||||
-s|--sort)
|
||||
COMPREPLY=( $( compgen -W 'name filename Name Filename size filesize extension Extension modified accessed created none inode --' -- "$cur" ) )
|
||||
COMPREPLY=( $( compgen -W 'name filename Name Filename size filesize extension Extension modified accessed created type inode none --' -- "$cur" ) )
|
||||
return
|
||||
;;
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ complete -c exa -s 's' -l 'sort' -x -d "Which field to sort by" -a "
|
|||
Name\t'Sort by filename (case-insensitive)'
|
||||
none\t'Do not sort files at all'
|
||||
size\t'Sort by file size'
|
||||
type\t'Sort by file type'
|
||||
"
|
||||
|
||||
complete -c exa -s 'I' -l 'ignore-glob' -d "Ignore files that match these glob patterns" -r
|
||||
|
|
|
@ -18,7 +18,7 @@ __exa() {
|
|||
{-d,--list-dirs}"[List directories like regular files]" \
|
||||
{-L,--level}"+[Limit the depth of recursion]" \
|
||||
{-r,--reverse}"[Reverse the sort order]" \
|
||||
{-s,--sort}"[Which field to sort by]:(sort field):(accessed created extension Extension filename Filename inode modified name Name none size)" \
|
||||
{-s,--sort}"[Which field to sort by]:(sort field):(accessed created extension Extension filename Filename inode modified name Name none size type)" \
|
||||
{-I,--ignore-glob}"[Ignore files that match these glob patterns]" \
|
||||
{-b,--binary}"[List file sizes with binary prefixes]" \
|
||||
{-B,--bytes}"[List file sizes in bytes, without any prefixes]" \
|
||||
|
|
|
@ -76,7 +76,7 @@ reverse the sort order
|
|||
.TP
|
||||
.B \-s, \-\-sort=\f[I]SORT_FIELD\f[]
|
||||
which field to sort by.
|
||||
Valid fields are name, Name, extension, Extension, size, modified, accessed, created, inode, and none.
|
||||
Valid fields are name, Name, extension, Extension, size, modified, accessed, created, inode, type, and none.
|
||||
Fields starting with a capital letter are case-sensitive.
|
||||
.RS
|
||||
.RE
|
||||
|
|
|
@ -40,8 +40,11 @@ pub type uid_t = u32;
|
|||
/// This type is set entirely by the filesystem, rather than relying on a
|
||||
/// file’s contents. So “link” is a type, but “image” is just a type of
|
||||
/// regular file. (See the `filetype` module for those checks.)
|
||||
///
|
||||
/// Its ordering is used when sorting by type.
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub enum Type {
|
||||
File, Directory, Pipe, Link, Socket, CharDevice, BlockDevice, Special,
|
||||
Directory, File, Link, Pipe, Socket, CharDevice, BlockDevice, Special,
|
||||
}
|
||||
|
||||
impl Type {
|
||||
|
|
|
@ -135,6 +135,11 @@ impl FileFilter {
|
|||
SortField::AccessedDate => a.metadata.atime().cmp(&b.metadata.atime()),
|
||||
SortField::CreatedDate => a.metadata.ctime().cmp(&b.metadata.ctime()),
|
||||
|
||||
SortField::FileType => match a.type_char().cmp(&b.type_char()) { // todo: this recomputes
|
||||
Ordering::Equal => natord::compare(&*a.name, &*b.name),
|
||||
order => order,
|
||||
},
|
||||
|
||||
SortField::Extension(Sensitive) => match a.ext.cmp(&b.ext) {
|
||||
Ordering::Equal => natord::compare(&*a.name, &*b.name),
|
||||
order => order,
|
||||
|
@ -195,6 +200,12 @@ pub enum SortField {
|
|||
/// In original Unix, this was, however, meant as creation time.
|
||||
/// https://www.bell-labs.com/usr/dmr/www/cacm.html
|
||||
CreatedDate,
|
||||
|
||||
/// The type of the file: directories, links, pipes, regular, files, etc.
|
||||
///
|
||||
/// Files are ordered according to the `PartialOrd` implementation of
|
||||
/// `fs::fields::Type`, so changing that will change this.
|
||||
FileType,
|
||||
}
|
||||
|
||||
/// Whether a field should be sorted case-sensitively or case-insensitively.
|
||||
|
@ -226,7 +237,7 @@ impl SortField {
|
|||
|
||||
const SORTS: &[&str] = &[ "name", "Name", "size", "extension",
|
||||
"Extension", "modified", "accessed",
|
||||
"created", "inode", "none" ];
|
||||
"created", "inode", "type", "none" ];
|
||||
|
||||
if let Some(word) = matches.opt_str("sort") {
|
||||
match &*word {
|
||||
|
@ -238,8 +249,9 @@ impl SortField {
|
|||
"mod" | "modified" => Ok(SortField::ModifiedDate),
|
||||
"acc" | "accessed" => Ok(SortField::AccessedDate),
|
||||
"cr" | "created" => Ok(SortField::CreatedDate),
|
||||
"none" => Ok(SortField::Unsorted),
|
||||
"inode" => Ok(SortField::FileInode),
|
||||
"type" => Ok(SortField::FileType),
|
||||
"none" => Ok(SortField::Unsorted),
|
||||
field => Err(Misfire::bad_argument("sort", field, SORTS))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ FILTERING AND SORTING OPTIONS
|
|||
-s, --sort SORT_FIELD which field to sort by:
|
||||
--group-directories-first list directories before other files
|
||||
-I, --ignore-glob GLOBS glob patterns (pipe-separated) of files to ignore
|
||||
Valid sort fields: name, Name, extension, Extension, size,
|
||||
Valid sort fields: name, Name, extension, Extension, size, type,
|
||||
modified, accessed, created, inode, none
|
||||
"##;
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
[38;5;244m#SAVEFILE#[0m
|
||||
[1;4;33mMakefile[0m
|
||||
[38;5;244mbackup~[0m
|
||||
[38;5;137mcompiled.class[0m
|
||||
compiled.coffee
|
||||
|
@ -7,17 +6,18 @@ compiled.coffee
|
|||
[38;5;137mcompiled.o[0m
|
||||
[31mcompressed.tar.gz[0m
|
||||
[31mcompressed.tgz[0m
|
||||
[31mcompressed.zip[0m
|
||||
[31mCOMPRESSED.ZIP[0m
|
||||
[38;5;109mcrypto.asc[0m
|
||||
[38;5;109mcrypto.signature[0m
|
||||
[38;5;105mdocument.pdf[0m
|
||||
[38;5;105mdocument.xlsx[0m
|
||||
[38;5;105mDOCUMENT.XLSX[0m
|
||||
[38;5;244mfile.tmp[0m
|
||||
[38;5;133mimage.png[0m
|
||||
[38;5;133mIMAGE.PNG[0m
|
||||
[38;5;133mimage.svg[0m
|
||||
[38;5;93mlossless.flac[0m
|
||||
[38;5;93mlossless.wav[0m
|
||||
[1;4;33mMakefile[0m
|
||||
[38;5;92mmusic.mp3[0m
|
||||
[38;5;92mmusic.ogg[0m
|
||||
[38;5;135mvideo.avi[0m
|
||||
[38;5;92mMUSIC.OGG[0m
|
||||
[38;5;135mVIDEO.AVI[0m
|
||||
[38;5;135mvideo.wmv[0m
|
||||
|
|
23
xtests/file-names-exts-case
Normal file
23
xtests/file-names-exts-case
Normal file
|
@ -0,0 +1,23 @@
|
|||
[38;5;244m#SAVEFILE#[0m
|
||||
[31mCOMPRESSED.ZIP[0m
|
||||
[38;5;105mDOCUMENT.XLSX[0m
|
||||
[38;5;133mIMAGE.PNG[0m
|
||||
[38;5;92mMUSIC.OGG[0m
|
||||
[1;4;33mMakefile[0m
|
||||
[38;5;135mVIDEO.AVI[0m
|
||||
[38;5;244mbackup~[0m
|
||||
[38;5;137mcompiled.class[0m
|
||||
compiled.coffee
|
||||
[38;5;137mcompiled.js[0m
|
||||
[38;5;137mcompiled.o[0m
|
||||
[31mcompressed.tar.gz[0m
|
||||
[31mcompressed.tgz[0m
|
||||
[38;5;109mcrypto.asc[0m
|
||||
[38;5;109mcrypto.signature[0m
|
||||
[38;5;105mdocument.pdf[0m
|
||||
[38;5;244mfile.tmp[0m
|
||||
[38;5;133mimage.svg[0m
|
||||
[38;5;93mlossless.flac[0m
|
||||
[38;5;93mlossless.wav[0m
|
||||
[38;5;92mmusic.mp3[0m
|
||||
[38;5;135mvideo.wmv[0m
|
23
xtests/file-names-exts-ext
Normal file
23
xtests/file-names-exts-ext
Normal file
|
@ -0,0 +1,23 @@
|
|||
[38;5;244m#SAVEFILE#[0m
|
||||
[38;5;244mbackup~[0m
|
||||
[1;4;33mMakefile[0m
|
||||
[38;5;109mcrypto.asc[0m
|
||||
[38;5;135mVIDEO.AVI[0m
|
||||
[38;5;137mcompiled.class[0m
|
||||
compiled.coffee
|
||||
[38;5;93mlossless.flac[0m
|
||||
[31mcompressed.tar.gz[0m
|
||||
[38;5;137mcompiled.js[0m
|
||||
[38;5;92mmusic.mp3[0m
|
||||
[38;5;137mcompiled.o[0m
|
||||
[38;5;92mMUSIC.OGG[0m
|
||||
[38;5;105mdocument.pdf[0m
|
||||
[38;5;133mIMAGE.PNG[0m
|
||||
[38;5;109mcrypto.signature[0m
|
||||
[38;5;133mimage.svg[0m
|
||||
[31mcompressed.tgz[0m
|
||||
[38;5;244mfile.tmp[0m
|
||||
[38;5;93mlossless.wav[0m
|
||||
[38;5;135mvideo.wmv[0m
|
||||
[38;5;105mDOCUMENT.XLSX[0m
|
||||
[31mCOMPRESSED.ZIP[0m
|
23
xtests/file-names-exts-ext-case
Normal file
23
xtests/file-names-exts-ext-case
Normal file
|
@ -0,0 +1,23 @@
|
|||
[38;5;244m#SAVEFILE#[0m
|
||||
[1;4;33mMakefile[0m
|
||||
[38;5;244mbackup~[0m
|
||||
[38;5;109mcrypto.asc[0m
|
||||
[38;5;135mVIDEO.AVI[0m
|
||||
[38;5;137mcompiled.class[0m
|
||||
compiled.coffee
|
||||
[38;5;93mlossless.flac[0m
|
||||
[31mcompressed.tar.gz[0m
|
||||
[38;5;137mcompiled.js[0m
|
||||
[38;5;92mmusic.mp3[0m
|
||||
[38;5;137mcompiled.o[0m
|
||||
[38;5;92mMUSIC.OGG[0m
|
||||
[38;5;105mdocument.pdf[0m
|
||||
[38;5;133mIMAGE.PNG[0m
|
||||
[38;5;109mcrypto.signature[0m
|
||||
[38;5;133mimage.svg[0m
|
||||
[31mcompressed.tgz[0m
|
||||
[38;5;244mfile.tmp[0m
|
||||
[38;5;93mlossless.wav[0m
|
||||
[38;5;135mvideo.wmv[0m
|
||||
[38;5;105mDOCUMENT.XLSX[0m
|
||||
[31mCOMPRESSED.ZIP[0m
|
|
@ -22,7 +22,7 @@ FILTERING AND SORTING OPTIONS
|
|||
-s, --sort SORT_FIELD which field to sort by:
|
||||
--group-directories-first list directories before other files
|
||||
-I, --ignore-glob GLOBS glob patterns (pipe-separated) of files to ignore
|
||||
Valid sort fields: name, Name, extension, Extension, size,
|
||||
Valid sort fields: name, Name, extension, Extension, size, type,
|
||||
modified, accessed, created, inode, none
|
||||
|
||||
LONG VIEW OPTIONS
|
||||
|
|
|
@ -79,15 +79,30 @@ COLUMNS=80 $exa $testcases/file-names -R 2>&1 | diff -q - $results/file_names_R
|
|||
$exa $testcases/file-names/* 2>/dev/null
|
||||
|
||||
|
||||
# File types
|
||||
$exa $testcases/file-names-exts -1 2>&1 | diff -q - $results/file-names-exts || exit 1
|
||||
$exa $testcases/specials -l 2>&1 | diff -q - $results/specials || exit 1
|
||||
$exa $testcases/specials -F -l 2>&1 | diff -q - $results/specials_F || exit 1
|
||||
# Sorting and extension file types
|
||||
$exa $testcases/file-names-exts -1 2>&1 --sort=Name | diff -q - $results/file-names-exts || exit 1
|
||||
$exa $testcases/file-names-exts -1 2>&1 --sort=name | diff -q - $results/file-names-exts-case || exit 1
|
||||
$exa $testcases/file-names-exts -1 2>&1 --sort=Ext | diff -q - $results/file-names-exts-ext || exit 1
|
||||
$exa $testcases/file-names-exts -1 2>&1 --sort=ext | diff -q - $results/file-names-exts-ext-case || exit 1
|
||||
|
||||
# Pass multiple input arguments because there aren’t enough of different types
|
||||
# in one directory already
|
||||
$exa $testcases/links -1 --sort=type 2>&1 | diff -q - $results/sort-by-type || exit 1
|
||||
|
||||
# We can’t guarantee inode numbers, but we can at least check that they’re in
|
||||
# order. The inode column is the leftmost one, so sort works for this.
|
||||
$exa $testcases/file-names-exts --long --inode --sort=inode | sort --check || exit 1
|
||||
|
||||
|
||||
# Other file types
|
||||
$exa $testcases/specials -l 2>&1 | diff -q - $results/specials || exit 1
|
||||
$exa $testcases/specials -F -l 2>&1 | diff -q - $results/specials_F || exit 1
|
||||
$exa $testcases/specials --sort=type -1 2>&1 | diff -q - $results/specials_sort || exit 1
|
||||
|
||||
|
||||
# Ignores
|
||||
$exa $testcases/file-names-exts/music.* -I "*.ogg" -1 2>&1 | diff -q - $results/ignores_ogg || exit 1
|
||||
$exa $testcases/file-names-exts/music.* -I "*.ogg|*.mp3" -1 2>&1 | diff -q - $results/empty || exit 1
|
||||
$exa $testcases/file-names-exts/music.* -I "*.OGG" -1 2>&1 | diff -q - $results/ignores_ogg || exit 1
|
||||
$exa $testcases/file-names-exts/music.* -I "*.OGG|*.mp3" -1 2>&1 | diff -q - $results/empty || exit 1
|
||||
|
||||
|
||||
# Paths and directories
|
||||
|
|
10
xtests/sort-by-type
Normal file
10
xtests/sort-by-type
Normal file
|
@ -0,0 +1,10 @@
|
|||
some_file
|
||||
[36mbroken[0m [31m->[0m [4;31mnowhere[0m
|
||||
[36mcurrent_dir[0m [38;5;244m->[0m [1;34m.[0m
|
||||
[36mforbidden[0m [31m->[0m [4;31m/proc/1/root[0m
|
||||
[36mitself[0m [31m->[0m [4;31mitself[0m
|
||||
[36mparent_dir[0m [38;5;244m->[0m [1;34m..[0m
|
||||
[36mroot[0m [38;5;244m->[0m [1;34m/[0m
|
||||
[36msome_file_absolute[0m [38;5;244m->[0m [36m/testcases/links/[0msome_file
|
||||
[36msome_file_relative[0m [38;5;244m->[0m some_file
|
||||
[36musr[0m [38;5;244m->[0m [36m/[1;34musr[0m
|
3
xtests/specials_sort
Normal file
3
xtests/specials_sort
Normal file
|
@ -0,0 +1,3 @@
|
|||
[33mnamed-pipe[0m
|
||||
[1;33mchar-device[0m
|
||||
[1;33mblock-device[0m
|
Loading…
Reference in New Issue
Block a user