BOM-marked and (BOMless) UTF-16 scripts not working
[p5sagit/p5-mst-13.2.git] / t / comp / utf.t
1 #!./perl
2
3 BEGIN {
4     chdir 't' if -d 't';
5     @INC = '../lib';
6     unless (find PerlIO::Layer 'perlio') {
7         print "1..0 # Skip: not perlio\n";
8         exit 0;
9     }
10 }
11
12 require "./test.pl";
13
14 plan(tests => 15);
15
16 my $BOM = chr(0xFEFF);
17
18 sub test {
19     my ($enc, $tag, $bom) = @_;
20     open(UTF_PL, ">:encoding($enc)", "utf.pl")
21         or die "utf.pl($enc,$tag,$bom): $!";
22     print UTF_PL $BOM if $bom;
23     print UTF_PL "$tag\n";
24     close(UTF_PL);
25     my $got = do "./utf.pl";
26     is($got, $tag);
27 }
28
29 test("utf16le",    123,   1);
30 test("utf16le",    1234,  1);
31 test("utf16le",    12345, 1);
32 test("utf16be",    123,   1);
33 test("utf16be",    1234,  1);
34 test("utf16be",    12345, 1);
35 test("utf8",       123,   1);
36 test("utf8",       1234,  1);
37 test("utf8",       12345, 1);
38
39 test("utf16le",    123,   0);
40 test("utf16le",    1234,  0);
41 test("utf16le",    12345, 0);
42 test("utf16be",    123,   0);
43 test("utf16be",    1234,  0);
44 test("utf16be",    12345, 0);
45
46 END {
47     1 while unlink "utf.pl";
48 }