Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrap CORE::readdir to provide UTF-8 filenames
readdir returns filenames as bytes, but that is inconvenient. Now, we wrap readdir and decode the returned filenames so the user is presented with the UTF-8 filenames they expected. Thanks for Leon Timmermans for code review Fixes GH #11
- Loading branch information
Showing
6 changed files
with
98 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,10 +1,45 @@ | |||
use strict; | use strict; | ||
use warnings; | use warnings; | ||
use version 0.77; | use version 0.77; | ||
use Test::More tests => 1; | use Test::More 0.96; | ||
use Test::Fatal; | |||
|
|
||
if ( eval { require autodie; 1 } ) { | if ( eval { require autodie; 1 } ) { | ||
diag "autodie is version $autodie::VERSION, but must be greater than version 2.11" | plan skip_all => "autodie is version $autodie::VERSION, but must be greater than version 2.11" | ||
if (version->parse($autodie::VERSION) < version->parse(2.11)); | if (version->parse($autodie::VERSION) < version->parse(2.11)); | ||
plan tests => 2; | |||
} | } | ||
pass; | else { | ||
plan skip_all => "autodie is required for these tests"; | |||
} | |||
no autodie; | |||
|
|||
subtest 'autodie first' => sub { | |||
plan tests => 2; | |||
use autodie; | |||
use utf8::all; | |||
|
|||
opendir my $dh, 'corpus'; | |||
my @files = grep { !m{^\.} } readdir $dh; | |||
closedir $dh; | |||
|
|||
is_deeply \@files, ["\x{307f}\x{304b}\x{3061}\x{3083}\x{3093}", "testfile"]; | |||
|
|||
my $exception = exception { opendir my $no_dh, 'nonexistent' }; | |||
like $exception => qr/No such file or directory/; | |||
}; | |||
|
|||
subtest 'autodie last' => sub { | |||
plan tests => 2; | |||
use utf8::all; | |||
use autodie; | |||
|
|||
opendir my $dh, 'corpus'; | |||
my @files = grep { !m{^\.} } readdir $dh; | |||
closedir $dh; | |||
|
|||
is_deeply \@files, ["\x{307f}\x{304b}\x{3061}\x{3083}\x{3093}", "testfile"]; | |||
|
|||
my $exception = exception { opendir my $no_dh, 'nonexistent' }; | |||
like $exception, qr/No such file or directory/; | |||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,39 @@ | |||
use strict; | |||
use warnings; | |||
use Test::More 0.96 tests => 2; | |||
|
|||
subtest utf8 => sub { | |||
plan tests => 3; | |||
|
|||
opendir my $dh, 'corpus' | |||
or die "Couldn't open directory 'corpus'"; | |||
|
|||
my @files = grep { $_ ne '.' and $_ ne '..' } readdir $dh; | |||
my @utf8_files; | |||
{ | |||
rewinddir $dh; | |||
use utf8::all; | |||
@utf8_files = grep { $_ ne '.' and $_ ne '..' } readdir $dh; | |||
} | |||
closedir $dh; | |||
|
|||
is_deeply \@utf8_files, ["\x{307f}\x{304b}\x{3061}\x{3083}\x{3093}", "testfile"]; | |||
isnt $files[0] => $utf8_files[0]; | |||
is $files[1] => $utf8_files[1]; | |||
}; | |||
|
|||
subtest context => sub { | |||
plan tests => 1; | |||
|
|||
opendir my $dh, 'corpus' | |||
or die "Couldn't open directory 'corpus'"; | |||
|
|||
use utf8::all; | |||
my $core = CORE::readdir $dh; | |||
rewinddir $dh; | |||
my $utf8 = readdir $dh; | |||
rewinddir $dh; | |||
|
|||
is $utf8 => $core; | |||
closedir $dh; | |||
}; |