File: bom.t

package info (click to toggle)
perl 5.42.0-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 128,392 kB
  • sloc: perl: 534,963; ansic: 240,563; sh: 72,042; pascal: 6,934; xml: 2,428; yacc: 1,360; makefile: 1,197; cpp: 208; lisp: 1
file content (26 lines) | stat: -rw-r--r-- 732 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!./perl

BEGIN {
    chdir 't' if -d 't';
    require "./test.pl";
    set_up_inc('../lib');
    require "./charset_tools.pl";
}

plan(tests => 3);

# It is important that the script contains at least one newline character
# that can be expanded to \r\n on DOSish systems.
fresh_perl_is(byte_utf8a_to_utf8n("\xEF\xBB\xBF") . "print 1;\nprint 2", "12", {}, "script starts with a BOM" );

# Big- and little-endian UTF-16
for my $end (0, 1) {
	my $encoding = $end ? 'UTF-16LE' : 'UTF-16BE';
	my $prog = join '', map chr($_), map {
		$end ? @$_[0, 1] : @$_[1, 0]
	} (
                # Create UTF-16.
		[ 0xFE, 0xFF ], map [ 0, ord($_) ], split //, "print 1;\nprint 2"
	);
	fresh_perl_is($prog, "12", {}, "BOM indicates $encoding");
}