xref: /openbsd-src/gnu/usr.bin/perl/t/io/bom.t (revision eac174f2741a08d8deb8aae59a7f778ef9b5d770)
1#!./perl
2
3BEGIN {
4    chdir 't' if -d 't';
5    require "./test.pl";
6    set_up_inc('../lib');
7    require "./charset_tools.pl";
8}
9
10plan(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.
14fresh_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
17for 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, ord($_) ], split //, "print 1;\nprint 2"
24	);
25	fresh_perl_is($prog, "12", {}, "BOM indicates $encoding");
26}
27