Fix unrecognized files count and colorization

A *file* is assigned a generic icon / glyph in `files.yaml`, so looking up
`:file` in the corresponding hash always succeeds, but `:file` is also used as
the fallback key if a file's extension is not recognized.

First determining the color and group of a given file before falling back to
the `:file` key fixes this issue.
This commit is contained in:
Claudio Bley 2020-09-07 19:47:45 +02:00
parent c36ed1a78b
commit 52b8c3489d
2 changed files with 9 additions and 1 deletions

View file

@ -328,9 +328,9 @@ module ColorLS
else
key = content.name.split('.').last.downcase.to_sym
key = @file_aliases[key] unless @files.key? key
key = :file if key.nil?
color = file_color(content, key)
group = @files.key?(key) ? :recognized_files : :unrecognized_files
key = :file if key.nil?
end
[key, color, group]

View file

@ -300,4 +300,12 @@ RSpec.describe ColorLS::Flags do
expect { subject }.to output(/setlocale error/).to_stderr.and output.to_stdout
end
end
context 'with unrecognized files' do
let(:args) { ['--report', FIXTURES] }
it 'should show a report with unrecognized files' do
expect { subject }.to output(/Unrecognized files\s+: 3/).to_stdout
end
end
end