Skip to content

Instantly share code, notes, and snippets.

@samcv

samcv/test.p6 Secret

Created September 17, 2018 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samcv/fdab5d5b1d0a11ccd5e937fc529337de to your computer and use it in GitHub Desktop.
Save samcv/fdab5d5b1d0a11ccd5e937fc529337de to your computer and use it in GitHub Desktop.
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