use Test::More; use utf8; use Data::Dumper; use I22r::Translate; use t::Constants; use strict; use warnings; binmode STDOUT, ':encoding(UTF-8)'; binmode STDERR, ':encoding(UTF-8)'; if (defined $DB::OUT) { # if Perl debugger is running binmode $DB::OUT, ':encoding(UTF-8)'; } ok(1, 'starting test'); t::Constants::skip_remaining_tests() unless $t::Constants::CONFIGURED; t::Constants::basic_config(); my $src = 'en'; my $dest = $ARGV[0] || 'es'; my %INPUT = ( 'entities', 'Inside <pre></pre> tags.', 'no-ent', 'Outside
 tags.',
	      'no-ent2',  'Outside  tags.',
	      'nbsp-no-content',     '( --   -- )' );

my %R = I22r::Translate->translate_hash(
    src => $src, dest => $dest, text => \%INPUT,
    filter => [ 'Literal', 'HTML' ], return_type => 'hash' );

# diag Dumper(\%INPUT,\%R);

ok( scalar keys %R == scalar keys %INPUT,
	'entity output count equals input count' );
ok( $R{entities}{TEXT} !~ /&lt/,
	'< did not become &lt;' );
ok( $R{entities}{TEXT} =~ /</ && $R{entities}{TEXT} =~ />/ ,
	'<> tags preserved' )
	or diag( "translation was: ", $R{entities}{TEXT} );
ok( $R{"no-ent"}{TEXT} !~ /&/,
	'no entities in input => none in output' );
ok( $R{'no-ent'}{TEXT} =~ /
/ && $R{'no-ent'}{TEXT} =~ m!!,
	'no entities preserves 
 and 
' ) or diag Dumper($R{"no-ent"}); ok( $R{"no-ent2"}{TEXT} !~ /&/, 'no entities in input2 => none in output' ); ok( $R{'no-ent2'}{TEXT} =~ // && $R{'no-ent2'}{TEXT} =~ m!!, 'no entities2 preserves and ' ) or diag Dumper($R{'no-ent2'}); ok( $R{'nbsp-no-content'}{TEXT} =~ / /, '  entity preserved in translation' ); done_testing();