our
$cqp
= new CWB::CQP
"-r data/registry"
,
"-I data/files/init.cqp"
;
isa_ok(
$cqp
,
"CWB::CQP"
)
or BAIL_OUT(
"failed to start up CQP backend"
);
$cqp
->set_error_handler(
'ignore'
);
$cqp
->
exec
(
"VSS"
);
ok(
$cqp
->ok,
"activate VSS corpus"
)
or BAIL_OUT(
"failed to activate VSS corpus"
);
sub
syntax_error {
my
(
$query
,
$label
,
$regex
) =
@_
;
$cqp
->
exec
(
$query
);
my
$ok
= !
$cqp
->ok;
if
(
$ok
&&
$regex
) {
$ok
= 0
unless
join
(
" "
,
$cqp
->error_message) =~
$regex
;
}
ok(
$ok
,
$label
);
}
syntax_error(
"A = 'the' ()* 'elephant'"
,
"empty parentheses"
,
qr/syntax error/
i);
syntax_error(
"A = 'the' [pos='NNS?']?? 'elephant'"
,
"double quantifier"
,
qr/syntax error/
i);
syntax_error(
"A = 'the' (?: [pos='NNS?'])* 'elephant'"
,
"non-capturing group"
,
qr/syntax error/
i);
for
my
$R
(-1, -2, -42) {
syntax_error(
"A = 'the' []{$R} 'elephant'"
,
"negative repetition count {$R}"
,
qr/non-negative/
i);
}
for
my
$R
(-1, -2) {
syntax_error(
"A = 'the' []{0,$R} 'elephant'"
,
"invalid endpoint of repetition range {0,$R}"
,
qr/non-negative/
i);
}
for
my
$R
(1, 2, 3) {
my
$R1
=
$R
- 1;
syntax_error(
"A = 'the' []{$R,$R1} 'elephant'"
,
"invalid repetition range {$R,$R1}"
,
qr/invalid.*range/
i);
}
for
my
$R
(-1, -2, -42) {
syntax_error(
"A = TAB 'the' []{$R} 'elephant'"
,
"negative distance {$R} in TAB query"
,
qr/non-negative/
i);
}
for
my
$R
(-1, -2) {
syntax_error(
"A = TAB 'the' []{0,$R} 'elephant'"
,
"invalid endpoint of distance range {0,$R} in TAB query"
,
qr/non-negative/
i);
}
for
my
$R
(-1, -2) {
syntax_error(
"A = TAB 'the' []{,$R} 'elephant'"
,
"invalid endpoint of distance range {,$R} in TAB query"
,
qr/non-negative|invalid.*range/
i);
}
for
my
$R
(1, 2, 3) {
my
$R1
=
$R
- 1;
syntax_error(
"A = TAB 'the' []{$R,$R1} 'elephant'"
,
"invalid distance range ($R,$R1) in TAB query"
,
qr/invalid.*range/
i);
}
syntax_error(
"A = [lemma >= 'elephant']"
,
"inequality comparison >= for p-attribute"
,
qr/inequality/
i);
syntax_error(
"A = [lemma < 'elephant']"
,
"inequality comparison < for p-attribute"
,
qr/inequality/
i);
syntax_error(
"A = [lemma > 'el.*' \%c]"
,
"inequality comparison > for regular expression"
,
qr/inequality/
i);
syntax_error(
"A = [lemma = 'elephant'] :: match.story_title <= 'ACME'"
,
"inequality comparison <= for s-attribute"
,
qr/inequality/
i);
syntax_error(
"A = [lemma < word]"
,
"inequality comparison < between p-attributes"
,
qr/inequality/
i);
syntax_error(
"A = [normalize(lemma, 'c') >= normalize(word, 'c')]"
,
"inequality comparison >= between strings"
,
qr/inequality/
i);