#!/usr/bin/perl use strict; use warnings; use Test::More; use Test::Exception; use lib "blib/lib"; use CPAN::Forum::Markup; my $TEXT = '
<' => $TEXT . 'apple' . $END . $CODE . '<' . $END,
'apple' => $TEXT . 'apple' . $END . $CODE . '<code>' . $END,
'x234567890' x 7 => $TEXT . 'x234567890' x 7 . $END,
'x234567890' x 100 => $TEXT . 'x234567890' x 100 . $END,
'Hello world' => $TEXT . 'Hello world' . $END,
'program' => $CODE . 'program' . $END,
'' => $CODE . '<STD>' . $END,
'Hello world' => $TEXT . 'Hello world' . $END,
' World' => $TEXT . ' World' . $END,
'applebob' => $TEXT . 'apple' . $END . $CODE . 'bob' . $END,
'program' => $CODE . 'program' . $END,
'apple<' => $TEXT . 'apple' . $END . $CODE . '<' . $END,
' $x < $y ' => $CODE . ' $x < $y ' . $END,
'' => $CODE . '<STD>' . $END,
'some; strange $%^& text' => $TEXT . 'some; strange $%^& text' . $END,
'bold more text' => $TEXT . 'bold more text' . $END,
'acxd' => $TEXT . 'ac' . $END . $CODE . 'x' . $END . $TEXT . 'd' . $END,
'acxdy' => $TEXT . 'ac' . $END . $CODE . 'x' . $END . $TEXT . 'd' . $END . $CODE . 'y' . $END,
'acxdy' => $TEXT . 'ac' . $END . $CODE . 'x' . $END . $TEXT . 'd' . $END . $CODE . 'y' . $END,
'acdxf' => $TEXT . 'acdxf' . $END,
'acdxf' => $TEXT . 'acdxf' . $END,
'<' => $TEXT . '<' . $END,
'text
' => $TEXT . 'text
' . $END,
'text
' => $TEXT . 'text
' . $END,
'text
' => $TEXT . 'text
' . $END,
'
' => $TEXT . '
' . $END,
'
hello' => $TEXT . '
hello' . $END,
'
hello' => $TEXT . '
hello' . $END,
'
hello' => $TEXT . '
hello' . $END,
'' => $CODE . '<P>' . $END,
'text' => $TEXT . 'text' . $END,
'text' => $TEXT . 'text' . $END,
'text' => $TEXT . 'text' . $END,
'text' => $TEXT . 'text' . $END,
'addr' => $TEXT . 'addr' . $END,
'bright new world
' => $TEXT . 'bright new world
' . $END,
);
my %fails = (
'apple' => qr(^ERR no_less_sign$),
'apple' => qr(^ERR no_less_sign$),
'apple< sd' => qr(^ERR no_less_sign$),
'apple<' => qr(^ERR no_less_sign$),
'apple qr(^ERR no_less_sign$),
'xyz' => qr(^ERR no_less_sign$),
# '1234567890' x 7 . "x" => qr(^ERR line_too_long$),
'applesd' => qr(^ERR open_code_without_closing$),
"" => qr(^ERR open_code_without_closing$),
"Hello" => qr(^ERR open_code_without_closing$),
'' => undef,
'Hello' => undef,
'' => undef,
'ac' => undef,
'ac' => undef,
'ac' => undef,
'apple<' => undef,
'text' => undef,
'text' => undef,
'text' => undef,
);
plan tests => 6 + (2 * keys %cases) + (1 * keys %fails) + (2 * 3);
is(CPAN::Forum::Markup->get_nextmark(), '+');
is(CPAN::Forum::Markup->set_nextmark('|'), '|');
is(CPAN::Forum::Markup->get_nextmark(), '|');
is(CPAN::Forum::Markup::split_rows('some text', 60), 'some text');
TODO: {
local $TODO = 'fix split_rows';
is(CPAN::Forum::Markup::split_rows('some text with more content', 10), "some text\n|with more\n|content");
is(CPAN::Forum::Markup::split_rows('some text with morecontent', 10), "some text\n|with\n|morecontent");
}
my $markup = CPAN::Forum::Markup->new();
foreach my $c (sort keys %cases) {
lives_ok {f($c)} 'Expected to live';
is(f($c), $cases{$c}, $c);
}
foreach my $c (sort keys %fails) {
my $ret = eval {f($c)};
ok(not(defined $ret), "OK");
#throws_ok {f($c)} $fails{$c}, "OK";
}
my $data = join "", ;
foreach my $code (split /CODE/, $data) {
#print STDERR $code;
my $out = $markup->posting_process($code);
ok(defined($out), "BIG CODE");
ok(length($out) > length ($code)) or print STDERR $out;
}
sub f {
$markup->posting_process(@_);
}
__DATA__
#!/usr/bin/perl
open my $fh, ">>", "filename";
while (<$fh>) {
print $x . 'sss';
xxl
}
CODE
some
#!/usr/bin/perl
while () {
more todo
}
1;
CODE
I am using Parse::RecDescent to validate the input on this forum. Right now it can give OK/NOT OK but I'd like to be a bit more specific. E.g.I'd like to give differen error messages
if there is a not approved HTML tag such as <img> in the text
or if there is an opening tag withou a closing tag
or just a single < mark somewhere