BEGIN {
use_ok(
'Text::BibTeX'
,
qw(purify_string)
);
my
$common
= getcwd().
"/t/common.pl"
;
require
$common
;
}
$DEBUG
= 1;
my
(
$in1
,
$in2
,
$out
);
$in1
=
'f{\"o}o'
;
$in2
=
$in1
;
$out
=
'clobber me'
;
$out
= purify_string (
$in2
);
is(
$in1
,
$in2
);
is(
$out
,
'foo'
);
is(
length
$in1
, 7);
is(
length
$in2
, 7);
is(
length
$out
, 3);
is(purify_string (
''
),
''
);
ok(!
defined
purify_string (
undef
));
my
@tests
=
(
q[Bl{\"o}w, Jo{\'{e}} Q. and J.~R. R. Tolk{\u e}in and {Fo{\'o} Bar ~ {\aa}nd {\SS}on{\v{s}}, Ltd.}]
=>
[58,
'Blow Joe Q and J R R Tolkein and Foo Bar aand SSonvs Ltd'
],
q[]
=> [0,
''
],
q[G{\"o}del]
=> [5,
'Godel'
],
q[G{\" o}del]
=> [5,
'Godel'
],
q[G{\" o }del]
=> [5,
'Godel'
],
q[G{\"o }del]
=> [5,
'Godel'
],
q[G{\"{o}}del]
=> [5,
'Godel'
],
q[G{\" {o}}del]
=> [5,
'Godel'
],
q[G{\" { o}}del]
=> [5,
'Godel'
],
q[G{\" {o }}del]
=> [5,
'Godel'
],
q[G{\" { o }}del]
=> [5,
'Godel'
],
q[G{\" { o } }del]
=> [5,
'Godel'
],
q[G{\"{o} }del]
=> [5,
'Godel'
],
q[G{\" {o} }del]
=> [5,
'Godel'
],
q[G{\"o foo}del]
=> [8,
'Gofoodel'
],
q[G{\"foo}del]
=> [7,
'Gfoodel'
],
q[G{\"{foo}}del]
=> [7,
'Gfoodel'
],
q[{G\"odel}]
=> [5,
'Godel'
],
q[G{\"o}del]
=> [5,
'Godel'
],
q[G{\"{o}}del]
=> [5,
'Godel'
],
q[{\ss}uper-duper]
=> [12,
'ssuper duper'
],
q[{\ss }uper-duper]
=> [12,
'ssuper duper'
],
q[{ \ss}uper-duper]
=> [13,
' ssuper duper'
],
q[{\ss{}}uper-duper]
=> [12,
'ssuper duper'
],
q[{\ss foo}uper-duper]
=> [15,
'ssfoouper duper'
],
q[{\ss { }}uper-duper]
=> [12,
'ssuper duper'
],
q[{\ss {foo}}uper-duper]
=> [15,
'ssfoouper duper'
],
q[{\ss{foo}}uper-duper]
=> [15,
'ssfoouper duper'
],
q[Tom{\`a}{\v s}]
=> [5,
'Tomas'
],
q[Tom{\`a}{\v{s}}]
=> [5,
'Tomas'
],
q[Tom{\`a}{{\v s}}]
=> [7,
'Tomav s'
],
q[{Tom{\`a}{\v s}}]
=> [7,
'Tomav s'
],
q[{Tom{\`a}{\v{s}}}]
=> [6,
'Tomavs'
],
q[{Tom{\`a}{\v{ s}}}]
=> [7,
'Tomav s'
],
q[{Tom{\`a}{\v{ s }}}]
=> [8,
'Tomav s'
],
q[{\v s}]
=> [1,
's'
],
q[{\x s}]
=> [1,
's'
],
q[{\r s}]
=> [1,
's'
],
q[{\foo s}]
=> [1,
's'
],
q[{\oe}]
=> [2,
'oe'
],
q[{\ae}]
=> [2,
'ae'
],
q[{\aa}]
=> [2,
'aa'
],
q[{\AA}]
=> [2,
'Aa'
],
q[{\o}]
=> [1,
'o'
],
q[{\l}]
=> [1,
'l'
],
q[{\ss}]
=> [2,
'ss'
],
q[{\ae s}]
=> [3,
'aes'
],
q[\TeX]
=> [3,
'TeX'
],
q[{\TeX}]
=> [0,
''
],
q[{{\TeX}}]
=> [3,
'TeX'
],
q[{\foobar}]
=> [0,
''
]
);
while
(
@tests
)
{
my
$str
=
shift
@tests
;
my
(
$exp_length
,
$exp_purified
) = @{
shift
@tests
};
my
$purified
= purify_string (
$str
);
my
$length
=
length
$purified
;
printf
"[%s] -> [%s] (length %d) (expected [%s], length %d)\n"
,
$str
,
$purified
,
$length
,
$exp_purified
,
$exp_length
if
$DEBUG
;
$purified
=~ s/ +$//;
is(
$purified
,
$exp_purified
);
is(
$length
,
$exp_length
);
}