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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl Encode-LaTeX.t'
#########################
# change 'tests => 1' to 'tests => last_test_to_print';
use Test::More tests => 32;
use Encode;
BEGIN { use_ok('TeX::Encode') };
#########################
# Insert your test code below, the Test::More module is use()ed here so read
# its man page ( perldoc Test::More ) for help writing this test script.
# decode of an encode should be equivalent
my $str = "eacute = '" . chr(0xe9) . "'";
is(encode('LaTeX', $str), "eacute = '\\'e'", "eacute => '\\'e'");
is(decode('latex', "eacute = '\\'e'"), $str, $str);
# General decode tests
my @DECODE_TESTS = (
'foo x^2 bar' => 'foo x'.chr(0xb2).' bar',
'xxx \\texttt{\char92} yyy' => 'xxx \\ yyy',
'\\sqrt{2}' => (chr(0x221a) . "2"),
'hyper-K\\"ahler background' => ('hyper-K'.chr(0xe4).'hler background'),
'$0<\\sigma\\leq{}2$' => ('0<'.chr(0x3c3).chr(0x2264).'2'),
'foo \\{ bar' => 'foo { bar', # Unescaping Tex escapes
'foo \\\\ bar' => "foo \n bar", # Tex newline
'foo $mathrm$ bar' => 'foo mathrm bar', # Math mode test (strictly should eat spaces inside math mode too)
'{\\L}' => chr(0x141), # Polish suppressed-L
'\\ss' => chr(0xdf), # German sharp S
'\\oe' => chr(0x153), # French oe
'\\OE' => chr(0x152), # French OE
'\\ae' => chr(0xe6), # Scandinavian ligature ae
"consist of \$\\sim{}260,000\$ of subprobes \$\\sim{}4\\\%\$ of in \$2.92\\cdot{}10^{8}\$ years. to \$1.52\\cdot{}10^{7}\$ years." =>
"consist of ".chr(0x223c)."260,000 of subprobes ".chr(0x223c)."4% of in 2.92".chr(0x22c5)."10".chr(0x2078)." years. to 1.52".chr(0x22c5)."10".chr(0x2077)." years.", # Should remove empty braces too
'\\ensuremath{\\alpha}' => ('\\ensuremath'.chr(0x3b1)), # Math mode by ensuremath
);
# General encode tests
my @ENCODE_TESTS = (
'underscores _ should be escaped' => "underscores \\_ should be escaped",
'#$%&_' => '\\#\\$\\%\\&\\_',
'\\' => '\\texttt{\\char92}',
'^' => '\\^{ }',
'~' => '\\texttt{\\char126}',
'<>' => '\ensuremath{<}\ensuremath{>}',
chr(0xe6) => '\\ae',
chr(0xe6).'foo' => '\\ae{}foo',
chr(0x3b1) => '\\ensuremath{\\alpha}',
chr(0xe6).' foo' => '\\ae foo',
'abcd'.chr(0xe9).'fg' => 'abcd\\\'e{}fg',
chr(0x107) => '\\\'c',
);
while( my( $in, $out ) = splice(@DECODE_TESTS,0,2) ) {
is( decode('latex', $in), $out );
}
while( my( $in, $out ) = splice(@ENCODE_TESTS,0,2) ) {
is( encode('latex', $in), $out );
}
# Check misquoting of tex strings ({})
$str = 'mathrm $\\mathrm{E}$';
is(decode('latex', $str), 'mathrm \\mathrmE');
ok(1);
|