This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Make cmp() work on EBCDIC with both UTF-8 operands
[perl5.git] / t / io / bom.t
1 #!./perl
2
3 BEGIN {
4     chdir 't' if -d 't';
5     @INC = '../lib';
6 }
7
8 BEGIN { require "./test.pl"; require "./charset_tools.pl"; }
9
10 plan(tests => 3);
11
12 # It is important that the script contains at least one newline character
13 # that can be expanded to \r\n on DOSish systems.
14 fresh_perl_is(byte_utf8a_to_utf8n("\xEF\xBB\xBF") . "print 1;\nprint 2", "12", {}, "script starts with a BOM" );
15
16 # Big- and little-endian UTF-16
17 for my $end (0, 1) {
18         my $encoding = $end ? 'UTF-16LE' : 'UTF-16BE';
19         my $prog = join '', map chr($_), map {
20                 $end ? @$_[0, 1] : @$_[1, 0]
21         } (
22                 # Create UTF-16.
23                 [ 0xFE, 0xFF ], map [ 0, utf8::native_to_unicode(ord($_)) ],
24                                                     split //, "print 1;\nprint 2"
25         );
26         fresh_perl_is($prog, "12", {}, "BOM indicates $encoding");
27 }