13 my ($enc, $content, $do_bom) = @_;
14 my $template = $templates{$enc};
15 die "Unsupported encoding $enc" unless $template;
16 return pack "$template*", ($do_bom ? 0xFEFF : ()), unpack "U*", $content;
20 my ($enc, $write, $expect, $bom, $nl, $name) = @_;
21 open my $fh, ">", "utf$$.pl" or die "utf.pl: $!";
23 print $fh bytes_to_utf($enc, $write . ($nl ? "\n" : ''), $bom);
25 my $got = do "./utf$$.pl";
28 print "not ok $test # $enc $bom $nl $name; got undef\n";
29 } elsif ($got ne $expect) {
30 print "not ok $test # $enc $bom $nl $name; got '$got'\n";
32 print "ok $test # $enc $bom $nl $name\n";
37 for my $enc (qw(utf16le utf16be utf8)) {
39 for my $value (123, 1234, 12345) {
40 test($enc, $value, $value, $bom, $nl, $value);
42 next if $enc eq 'utf8';
43 # Arguably a bug that currently string literals from UTF-8 file
44 # handles are not implicitly "use utf8", but don't FIXME that
45 # right now, as here we're testing the input filter itself.
47 for my $expect ("N", "\xFF", "\x{100}", "\x{010a}", "\x{0a23}",
49 # A space so that the UTF-16 heuristc triggers - " '" gives two
50 # characters of ASCII.
51 my $write = " '$expect'";
52 my $name = 'chrs ' . join ', ', map {ord $_} split '', $expect;
53 test($enc, $write, $expect, $bom, $nl, $name);
60 1 while unlink "utf$$.pl";