use strict; use warnings; use File::Temp qw/tempdir/; use Test::More tests => 14; use Encode qw/decode/; my $ae = "\N{LATIN SMALL LETTER A WITH DIAERESIS}"; is (length $ae, 1, "The a with diaeresis is one character to Perl,"); ok (utf8::is_utf8($ae), " ...and Perl knows it to be UTF-8 (UTF-8 flag on),"); my $ae2 = $ae; ok(utf8::downgrade($ae2), " ...and it can be downgraded"); ok(! utf8::is_utf8($ae2), " ...so that is no longer stored as UTF-8 (UTF-8 flag off)."); is ($ae,$ae2,"UTF-8 encoded and downgraded versions are equal."); note ("Now we are creating file(s), using the character as a filename."); my $tempdir = tempdir( CLEANUP => 1 ) or BAIL_OUT "No tempdir, demo terminated."; for my $file ($ae,$ae2) { ok (open (my $out,'>',"$tempdir/$file"), "Opening two files with the same (?) name.") or BAIL_OUT "No file written, demo terminated."; close $out; } note ("Now reading the contents of the directory..."); opendir (my $dh,$tempdir); my @files = sort { length $a <=> length $b } grep { /^[^.]/ } # exclude . and .. readdir $dh; is (scalar @files, 2, "We apparently have created TWO files."); is (length $files[0],1,"The first filename is one byte long,"); is (length $files[1],2,"The second filename is TWO bytes long."); ok(! utf8::is_utf8($files[0]), "The first filename is stored as bytes (UTF-8 flag off)."); ok(! utf8::is_utf8($files[1]), "The second filename is ALSO stored as bytes (UTF-8 flag off)."); is ($files[0],$ae,"The first filename is what we provided."); is (decode('UTF-8',$files[1],Encode::FB_CROAK),$ae, "The second filename needs to be decoded to match what we provided."); note("There is silent encoding of path names, but no silent decoding!");