-
-
Save aklaswad/217424 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Carp qw( carp ); | |
use Test::Base; | |
plan tests => 6 * blocks; | |
sub escape_mt_export { | |
my ($str) = @_; | |
$str =~ s/^(-+)$/$1$1$1/gm; | |
$str; | |
} | |
sub unescape_mt_export { | |
my ($str) = @_; | |
$str =~ s!^(-+)$! | |
my $sep = $1; | |
my $len = length $sep; | |
carp 'This string looks not Movable Type export format.' | |
if $len % 3; | |
'-' x int($len / 3); | |
!gme; | |
$str; | |
} | |
sub _has_delimiter { | |
my ($str) = @_; | |
my $SEP = qr/^-{8}$/; | |
my $SUBSEP = qr/^-{5}$/; | |
return ( $str =~ /$SEP/m || $str =~ /$SUBSEP/m ); | |
} | |
run { | |
my $block = shift; | |
my ($escaped, $d_escaped); | |
is( $escaped = escape_mt_export($block->input), $block->escaped ); | |
ok( !_has_delimiter($escaped) ); | |
is( unescape_mt_export($escaped), $block->input ); | |
ok( _has_delimiter(unescape_mt_export($escaped)) ); | |
is( $d_escaped = escape_mt_export($escaped), $block->double_escaped ); | |
is( unescape_mt_export(unescape_mt_export($d_escaped)), $block->input ); | |
}; | |
__END__ | |
=== | |
--- input | |
----- | |
<div id="content"> | |
<p>I thought what I'd do was, I'd pretend I was one of those deaf-mutes. | |
----- or should I ?</p> | |
---- | |
-------- The Laughing Man, Nine Stories, J.D.Salinger. | |
</div> | |
-------- | |
--- escaped | |
--------------- | |
<div id="content"> | |
<p>I thought what I'd do was, I'd pretend I was one of those deaf-mutes. | |
----- or should I ?</p> | |
------------ | |
-------- The Laughing Man, Nine Stories, J.D.Salinger. | |
</div> | |
------------------------ | |
--- double_escaped | |
--------------------------------------------- | |
<div id="content"> | |
<p>I thought what I'd do was, I'd pretend I was one of those deaf-mutes. | |
----- or should I ?</p> | |
------------------------------------ | |
-------- The Laughing Man, Nine Stories, J.D.Salinger. | |
</div> | |
------------------------------------------------------------------------ | |
--- LAST |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment