Use require.t's bytes_to_utf() in place of PerlIO layers in utf.t
[p5sagit/p5-mst-13.2.git] / t / comp / utf.t
CommitLineData
7aa207d6 1#!./perl
2
768fd157 3BEGIN { require "./test.pl"; }
7aa207d6 4
9ef34c7a 5plan(tests => 18);
7aa207d6 6
5c7da53c 7my %templates = (
8 utf8 => 'C0U',
9 utf16be => 'n',
10 utf16le => 'v',
11 );
12
13sub bytes_to_utf {
14 my ($enc, $content, $do_bom) = @_;
15 my $template = $templates{$enc};
16 die "Unsupported encoding $enc" unless $template;
17 return pack "$template*", ($do_bom ? 0xFEFF : ()), unpack "C*", $content;
18}
7aa207d6 19
20sub test {
21 my ($enc, $tag, $bom) = @_;
5c7da53c 22 open my $fh, ">", "utf$$.pl" or die "utf.pl: $!";
23 binmode $fh;
24 print $fh bytes_to_utf($enc, "$tag\n", $bom);
25 close $fh or die $!;
2d90ac95 26 my $got = do "./utf$$.pl";
7aa207d6 27 is($got, $tag);
28}
29
386ac4df 30for my $bom (0, 1) {
31 for my $enc (qw(utf16le utf16be utf8)) {
32 for my $value (123, 1234, 12345) {
33 test($enc, $value, $bom);
34 }
35 }
36}
7aa207d6 37
38END {
2d90ac95 39 1 while unlink "utf$$.pl";
7aa207d6 40}