#!/usr/bin/perl
use
t::Common
qw /run_new_tests/;
use
warnings;
BEGIN {$^W = 0
if
$] < 5.006}
my
@open
=
qw [{
(*];
my
@close
=
qw [}
*)];
my
@comments
= (
""
,
"This is a comment"
,
"This is a\nmultiline comment"
,
"\n"
,
"*"
,
"\n*\n"
,
"**"
,
"*****"
,
"** **"
,
"/*"
,
"||"
);
my
%targets
;
my
@tests
;
foreach
my
$start
(
@open
) {
foreach
my
$end
(
@close
) {
my
$lang
=
"Pascal"
;
my
$pass_key
=
"pass_${start}_${end}"
;
my
$fail_key
=
"fail_${start}_${end}"
;
$targets
{
$pass_key
} = {
list
=> \
@comments
,
query
=>
sub
{
$start
.
$_
[0] .
$end
},
wanted
=>
sub
{
$_
,
$start
,
$_
[0],
$end
},
};
my
@bad_comments
;
push
@bad_comments
=>
map
{
"$start$_"
}
@comments
if
$] >= 5.006;
push
@bad_comments
=>
map
{
"$_$end"
}
grep
{
index
(
$_
,
$start
)}
@comments
;
push
@bad_comments
=>
map
{
"$start$_$end$end"
}
@comments
;
push
@bad_comments
=>
map
{
"$start$_$end"
x 2}
@comments
;
my
@bad_open
=
qw [//
/* --];
my
@bad_close
= (
qw [*/
--],
"\n"
);
foreach
my
$close
(
@close
) {
push
@bad_comments
=>
map
{
my
$o
=
$_
;
map
{
"ot$_$close"
}
@comments
}
@bad_open
;
}
foreach
my
$open
(
@open
) {
push
@bad_comments
=>
map
{
my
$c
=
$_
;
map
{
"$open$_$c"
}
@comments
}
@bad_close
;
}
push
@bad_comments
=>
@comments
;
push
@bad_comments
=>
map
{
"Text $start$_$end"
}
@comments
;
push
@bad_comments
=>
"<!-- This is an HTML comment -->"
;
push
@bad_comments
=>
"/* This is a C comment */"
;
$targets
{
$fail_key
} = {
list
=> \
@bad_comments
,
};
no
strict
'refs'
;
push
@tests
=> {
name
=>
$lang
,
regex
=>
$RE
{comment} {
$lang
},
sub
=> \&{
"RE_comment_$lang"
},
pass
=> [
$pass_key
],
fail
=> [
$fail_key
],
}
}
}
run_new_tests
tests
=> \
@tests
,
targets
=> \
%targets
,
version_from
=>
'Regexp::Common::comment'
,