Encode-Wide

 view release on metacpan or  search on metacpan

t/edge_cases.t  view on Meta::CPAN

use Readonly;

# ---------------------------------------------------------------------------
# Constants
# ---------------------------------------------------------------------------

Readonly::Scalar my $MODULE   => 'Encode::Wide';
Readonly::Scalar my $E_ACUTE  => "\x{00E9}";	# U+00E9 e-acute
Readonly::Scalar my $A_GRAVE  => "\x{00E0}";	# U+00A0 a-grave
Readonly::Scalar my $NBSP     => "\x{00A0}";	# U+00A0 non-breaking space
Readonly::Scalar my $BOM      => "\x{FEFF}";	# U+FEFF byte-order mark
Readonly::Scalar my $ELLIPSIS => "\x{2026}";	# U+2026 horizontal ellipsis
Readonly::Scalar my $BULLET   => "\x{25CF}";	# U+25CF black circle
Readonly::Scalar my $LSQUO    => "\x{2018}";	# U+2018 left single quotation mark
Readonly::Scalar my $RSQUO    => "\x{2019}";	# U+2019 right single quotation mark
Readonly::Scalar my $LDQUO    => "\x{201C}";	# U+201C left double quotation mark
Readonly::Scalar my $RDQUO    => "\x{201D}";	# U+201D right double quotation mark
Readonly::Scalar my $PUA      => "\x{E000}";	# U+E000 private-use (unmapped -> BUG die)
Readonly::Scalar my $LARGE_N  => 10_000;	# repeat count for stress tests

use_ok($MODULE, qw(wide_to_html wide_to_xml));

t/edge_cases.t  view on Meta::CPAN


subtest 'DEL character (U+007F) passes through unchanged' => sub {
	my $del = "\x{007F}";
	is(wide_to_html(string => $del), $del, 'html: DEL unchanged');
	is(wide_to_xml(string  => $del), $del, 'xml:  DEL unchanged');
};

# ===========================================================================
# 3. Byte-Order Mark (U+FEFF)
# ---------------------------------------------------------------------------
# BOM is non-ASCII and not in any known byte_map entry.  It should reach the
# HTML::Entities::encode_entities_numeric fallback and become a numeric entity.
# At minimum the output must be pure ASCII.
# ===========================================================================

subtest 'BOM (U+FEFF) is handled per documented pipeline behaviour' => sub {
	# HTML: encode_entities_numeric covers U+FEFF -> numeric entity -> pure ASCII.
	my $html_bom;
	open(local *STDERR, '>', '/dev/null') or die;
	local $SIG{__WARN__} = sub { };
	lives_ok { $html_bom = wide_to_html(string => $BOM) } 'html: BOM does not die';
	unlike($html_bom, qr/[^[:ascii:]]/, 'html: BOM result is pure ASCII');
	diag "html BOM: $html_bom" if $ENV{TEST_VERBOSE};

	# XML: U+FEFF is not in any XML byte_map entry; the documented BUG path fires.
	open(local *STDERR, '>', '/dev/null') or die;
	local $SIG{__WARN__} = sub { };
	throws_ok { wide_to_xml(string => $BOM) }
		qr/BUG: wide_to_xml/,
		'xml: BOM (unmapped in XML maps) triggers documented BUG die';
};

# ===========================================================================
# 4. Hostile reference types
# ---------------------------------------------------------------------------
# Passing ARRAYREF, HASHREF, or CODEREF as string is outside the POD contract.
# The module must not produce non-ASCII output, must not execute injected code,
# and must not hang or corrupt memory.  It may die.
# ===========================================================================



( run in 1.177 second using v1.01-cache-2.11-cpan-8dfa8b56332 )