-
-
Save samcv/fdab5d5b1d0a11ccd5e937fc529337de to your computer and use it in GitHub Desktop.
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
my %enc = | |
utf8 => <sample-UTF-8.txt>, | |
utf16 => <sample-UTF-16LE-bom.txt sample-UTF-16BE-bom.txt sample-UTF-16LE.txt>, | |
utf16le => <sample-UTF-16LE-bom.txt sample-UTF-16LE.txt>, | |
utf16be => <sample-UTF-16BE-bom.txt sample-UTF-16BE.txt> | |
; | |
my $text = parse-names "LATIN CAPITAL LETTER A, LATIN CAPITAL LETTER L WITH STROKE, HANGUL CHOSEONG IEUNG-KIYEOK, CHAKMA DANDA, BUTTERFLY, <control-0000>"; | |
spurt "utf8", $text; | |
use Test; | |
for %enc.kv -> $enc-name, $filenames { | |
for $filenames.list -> $filename { | |
{ | |
my $fh = open $filename, :enc($enc-name), :r; | |
my $got; | |
my $lives-ok = lives-ok { $got = $fh.slurp }, "lives-ok open(:enc<$enc-name>, :r)"; | |
if $lives-ok { | |
is-deeply $got, $text, "decodestream($enc-name): $filename"; | |
} | |
else { | |
skip "decodestream($enc-name): $filename"; | |
} | |
$fh.close if $fh.opened; | |
} | |
my $fh2 = open $filename, :r; | |
my $bin = $fh2.read; | |
my $got-decode = $bin.decode($enc-name); | |
is-deeply $got-decode, $text, "decode($enc-name): $filename"; | |
} | |
} | |
done-testing; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment