Skip to content

Instantly share code, notes, and snippets.

@samcv
Created September 17, 2018 14:01
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/0a76f1d5b2ef4a8cc4e22dd9c8d9c3f6 to your computer and use it in GitHub Desktop.
Save samcv/0a76f1d5b2ef4a8cc4e22dd9c8d9c3f6 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>
;
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 {
try {
my $fh = open $filename, :enc($enc-name), :r;
my $got = $fh.slurp;
is-deeply $got, $text, "decodestream($enc-name): $filename";
$fh.close if $fh.opened;
CATCH {
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