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
1 #!./perl
2
3 BEGIN { require "./test.pl"; }
4
5 plan(tests => 18);
6
7 my %templates = (
8                  utf8 => 'C0U',
9                  utf16be => 'n',
10                  utf16le => 'v',
11                 );
12
13 sub 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 }
19
20 sub test {
21     my ($enc, $tag, $bom) = @_;
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 $!;
26     my $got = do "./utf$$.pl";
27     is($got, $tag);
28 }
29
30 for 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 }
37
38 END {
39     1 while unlink "utf$$.pl";
40 }