Created
September 17, 2018 14:01
-
-
Save samcv/0a76f1d5b2ef4a8cc4e22dd9c8d9c3f6 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> | |
; | |
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