2020-12-22 14:33:53 +01:00
|
|
|
# frozen_string_literal: false
|
|
|
|
|
2020-10-31 21:54:45 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe ColorLS::Core do
|
2020-11-25 22:35:58 +01:00
|
|
|
subject { described_class.new(colors: Hash.new('black')) }
|
2020-10-31 21:54:45 +01:00
|
|
|
|
2020-11-25 22:35:58 +01:00
|
|
|
context 'ls' do
|
2020-10-31 21:54:45 +01:00
|
|
|
it 'works with Unicode characters' do
|
2020-12-22 14:33:53 +01:00
|
|
|
camera = 'Cámara'.force_encoding(ColorLS.file_encoding)
|
|
|
|
imagenes = 'Imágenes'.force_encoding(ColorLS.file_encoding)
|
2020-10-31 21:54:45 +01:00
|
|
|
|
2020-12-22 14:33:53 +01:00
|
|
|
dir_info = instance_double(
|
2022-04-26 22:06:50 +02:00
|
|
|
ColorLS::FileInfo,
|
2020-12-22 14:33:53 +01:00
|
|
|
group: 'sys',
|
|
|
|
mtime: Time.now,
|
|
|
|
directory?: true,
|
|
|
|
owner: 'user',
|
|
|
|
name: imagenes,
|
2020-12-23 22:30:41 +01:00
|
|
|
path: '.',
|
2020-12-22 14:33:53 +01:00
|
|
|
show: imagenes,
|
|
|
|
nlink: 1,
|
|
|
|
size: 128,
|
|
|
|
blockdev?: false,
|
|
|
|
chardev?: false,
|
|
|
|
socket?: false,
|
|
|
|
symlink?: false,
|
2023-06-07 14:10:15 +02:00
|
|
|
hidden?: false,
|
2022-05-13 21:47:03 +02:00
|
|
|
stats: instance_double(File::Stat,
|
|
|
|
mode: 0o444, # read for user, owner, other
|
|
|
|
setuid?: false,
|
|
|
|
setgid?: false,
|
|
|
|
sticky?: false),
|
2020-12-22 14:33:53 +01:00
|
|
|
executable?: true
|
2020-10-31 21:54:45 +01:00
|
|
|
)
|
|
|
|
|
2020-12-22 14:33:53 +01:00
|
|
|
file_info = instance_double(
|
2022-04-26 22:06:50 +02:00
|
|
|
ColorLS::FileInfo,
|
2020-12-22 14:33:53 +01:00
|
|
|
group: 'sys',
|
|
|
|
mtime: Time.now,
|
|
|
|
directory?: false,
|
|
|
|
owner: 'user',
|
|
|
|
name: camera,
|
|
|
|
show: camera,
|
|
|
|
nlink: 1,
|
|
|
|
size: 128,
|
|
|
|
blockdev?: false,
|
|
|
|
chardev?: false,
|
|
|
|
socket?: false,
|
|
|
|
symlink?: false,
|
2023-06-07 14:10:15 +02:00
|
|
|
hidden?: false,
|
2022-05-13 21:47:03 +02:00
|
|
|
stats: instance_double(File::Stat,
|
|
|
|
mode: 0o444, # read for user, owner, other
|
|
|
|
setuid?: false,
|
|
|
|
setgid?: false,
|
|
|
|
sticky?: false),
|
2020-12-22 14:33:53 +01:00
|
|
|
executable?: false
|
2020-10-31 21:54:45 +01:00
|
|
|
)
|
|
|
|
|
2023-01-25 21:08:12 +01:00
|
|
|
allow(Dir).to receive(:entries).and_return([camera])
|
2020-10-31 21:54:45 +01:00
|
|
|
|
2020-12-23 22:30:41 +01:00
|
|
|
allow(ColorLS::FileInfo).to receive(:new).and_return(file_info)
|
2020-10-31 21:54:45 +01:00
|
|
|
|
2020-12-23 22:30:41 +01:00
|
|
|
expect { subject.ls_dir(dir_info) }.to output(/mara/).to_stdout
|
2020-10-31 21:54:45 +01:00
|
|
|
end
|
2021-01-29 10:21:24 +01:00
|
|
|
|
|
|
|
it 'works for `...`' do
|
|
|
|
file_info = instance_double(
|
2022-04-26 22:06:50 +02:00
|
|
|
ColorLS::FileInfo,
|
2021-01-29 10:21:24 +01:00
|
|
|
group: 'sys',
|
|
|
|
mtime: Time.now,
|
|
|
|
directory?: false,
|
|
|
|
owner: 'user',
|
|
|
|
name: '...',
|
|
|
|
show: '...',
|
|
|
|
nlink: 1,
|
|
|
|
size: 128,
|
|
|
|
blockdev?: false,
|
|
|
|
chardev?: false,
|
|
|
|
socket?: false,
|
|
|
|
symlink?: false,
|
2023-06-07 14:10:15 +02:00
|
|
|
hidden?: true,
|
2021-01-29 10:21:24 +01:00
|
|
|
executable?: false
|
|
|
|
)
|
|
|
|
|
|
|
|
expect { subject.ls_files([file_info]) }.to output(/[.]{3}/).to_stdout
|
|
|
|
end
|
2020-10-31 21:54:45 +01:00
|
|
|
end
|
|
|
|
end
|