Skip to content

Commit bc2ac2f

Browse files
committed
When testing regex for errors surround the error with []
1 parent c12153c commit bc2ac2f

File tree

3 files changed

+40
-35
lines changed

3 files changed

+40
-35
lines changed

t/qregex/01-qregex.t

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ sub test_line($line) {
4242
$target := '' if $target eq "''";
4343
$target := unescape($target);
4444

45-
my $expect_substr := nqp::eqat($expect, '<', 0)
45+
my $expect_error := nqp::eqat($expect, '[', 0);
46+
my $expect_substr := (nqp::eqat($expect, '<', 0) || nqp::eqat($expect, '[', 0))
4647
?? nqp::substr($expect, 1, nqp::chars($expect) - 2)
4748
!! '';
4849

@@ -51,7 +52,11 @@ sub test_line($line) {
5152
my $rxsub := $rxcomp.compile($regex);
5253
my $cursor := NQPCursor."!cursor_init"($target, :c(0));
5354
my $match := $rxsub($cursor).MATCH;
54-
if $expect_substr {
55+
56+
if $expect_error {
57+
ok(0, "$desc - expected an error");
58+
}
59+
elsif $expect_substr {
5560
my $got := ~$match."!dump_str"('mob');
5661
my $m := nqp::index($got, $expect_substr) >= 0;
5762
ok($m, $desc);
@@ -61,10 +66,10 @@ sub test_line($line) {
6166
ok($expect eq 'y' ?? $match !! !$match, $desc);
6267
}
6368
CATCH {
64-
if $expect_substr {
69+
if $expect_error {
6570
my $m := nqp::index(~$_, $expect_substr) >= 0;
6671
ok($m, $desc);
67-
say("# got: $_\n# expected: $expect") unless $m;
72+
say("# got error: $_\n# expected error: $expect_substr") unless $m;
6873
}
6974
else {
7075
ok(0, $desc);

t/qregex/rx_charclass

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
<-[b..d]> abcdef y negated character range
1919
<- [b..d]> abcdef y negated allows ws
2020
<-[b..d]> bbccdd n negated character range
21-
<-[d..b]> bbccdd <Illegal reversed character range in regex> illegal character range
22-
<[x-z]> ab-def <Unsupported> perl5 range
21+
<-[d..b]> bbccdd [Illegal reversed character range in regex] illegal character range
22+
<[x-z]> ab-def [Unsupported] perl5 range
2323
<[-]> ab-def y unescaped hyphen, the only thing
2424
<[ - ]> ab-def y unescaped hyphen, the only thing w spaces
2525
<[x-]> ab-def y unescaped hyphen, at the end
@@ -43,7 +43,7 @@
4343
<["\\]> \\ y escaped backslash
4444
<[\]]> ] y escaped close bracket
4545
# todo :any<backslash escapes in char classes>
46-
<[\]> \\]] /error/ unescaped backslash (or no closing brace)
46+
<[\]> \\]] [error] unescaped backslash (or no closing brace)
4747
^\><[<]> >< y lt character class
4848
^<[>]>\< >< y gt character class
4949
^<[><]>**2 >< y gt, lt character class

t/qregex/rx_metachars

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ a\N+f abcdef y not logical newline (\N)
5555
c \N d abc\n\rdef n not logical newline (\N)
5656
c \N d abc\r\ndef n not logical newline (\N)
5757
b \N \n abc\ndef y not logical newline (\N)
58-
\Aabc Aabc <Unsupported> retired metachars (\A)
59-
\Aabc abc\ndef <Unsupported> retired metachars (\A)
60-
abc\Z abcZ <Unsupported> retired metachars (\Z)
61-
abc\Z abc\ndef <Unsupported> retired metachars (\Z)
62-
abc\z abcz <Unsupported> retired metachars (\z)
63-
def\z abc\ndef <Unsupported> retired metachars (\z)
58+
\Aabc Aabc [Unsupported] retired metachars (\A)
59+
\Aabc abc\ndef [Unsupported] retired metachars (\A)
60+
abc\Z abcZ [Unsupported] retired metachars (\Z)
61+
abc\Z abc\ndef [Unsupported] retired metachars (\Z)
62+
abc\z abcz [Unsupported] retired metachars (\z)
63+
def\z abc\ndef [Unsupported] retired metachars (\z)
6464
abc # def abc#def y comments (#)
6565
abc # xyz abc#def y comments (#)
6666
abc # def \n \$ abc#def y comments (#)
@@ -84,13 +84,13 @@ $$ \n \n y line beginnings and endings ($$)
8484
^ [ <[a..c]>+ | <[b..e]>+ ] $ bcd y alternation (|)
8585
^ [ <[a..d]>+ | <[c..e]>+ ] $ bcd y alternation (|)
8686
# todo :any<feature>
87-
b| bcd <Null pattern> alternation (|) - null right arg illegal
87+
b| bcd [Null pattern] alternation (|) - null right arg illegal
8888
|b bcd y alternation (|) - null left arg ignored
8989
# todo :any<feature>
90-
| bcd <Null pattern> alternation (|) - null both args illegal
90+
| bcd [Null pattern] alternation (|) - null both args illegal
9191
\| | y alternation (|) - literal must be escaped
9292
# todo :any<feature>
93-
| | <Null pattern> alternation (|) - literal must be escaped
93+
| | [Null pattern] alternation (|) - literal must be escaped
9494
<[a..d]> && <[b..e]> c y conjunction (&&)
9595
<[a..d]> && <[d..e]> c n conjunction (&&)
9696
<[a..b]> && <[b..e]> c n conjunction (&&)
@@ -100,36 +100,36 @@ b| bcd <Null pattern> alternation (|) - null right arg illegal
100100
<[a..c]>+ && <[b..e]>+ bcd y conjunction (&&)
101101
<[a..d]>+ && <[c..e]>+ bcd y conjunction (&&)
102102
# todo :any<&-conjunciton>
103-
b& bcd <rule error> conjunction (&) - null right arg illegal
103+
b& bcd [rule error] conjunction (&) - null right arg illegal
104104
# todo :any<&-conjunciton>
105-
&b bcd <rule error> conjunction (&) - null left arg illegal
105+
&b bcd [rule error] conjunction (&) - null left arg illegal
106106
# todo :any<&-conjunciton>
107-
& bcd <rule error> conjunction (&) - null both args illegal
107+
& bcd [rule error] conjunction (&) - null both args illegal
108108
\& & y conjunction (&) - literal must be escaped
109109
# todo :any<&-conjunciton>
110-
& & <rule error> conjunction (&) - literal must be escaped
110+
& & [rule error] conjunction (&) - literal must be escaped
111111
# todo :any<leading |>
112-
a&|b a&|b <rule error> alternation and conjunction (&|) - parse error
112+
a&|b a&|b [rule error] alternation and conjunction (&|) - parse error
113113
# todo :any<&-conjunciton>
114-
& & <rule error> conjunction (&) - literal must be escaped
114+
& & [rule error] conjunction (&) - literal must be escaped
115115
# todo :any<&-conjunciton>
116-
a|&b a|&b <rule error> alternation and conjunction (|&) - parse error
116+
a|&b a|&b [rule error] alternation and conjunction (|&) - parse error
117117
|d|b abc y leading alternation ignored
118118
|d|b abc y leading alternation ignored
119119
|d |b abc y leading alternation ignored
120120
| d | b abc y leading alternation ignored
121-
\pabc pabc <Unrecognized> retired metachars (\p)
122-
\p{InConsonant} a <Unrecognized> retired metachars (\p)
123-
\Pabc Pabc <Unrecognized> retired metachars (\P)
124-
\P{InConsonant} a <Unrecognized> retired metachars (\P)
125-
\Labc\E LabcE <Unrecognized> retired metachars (\L...\E)
126-
\LABC\E abc <Unrecognized> retired metachars (\L...\E)
127-
\Uabc\E UabcE <Unrecognized> retired metachars (\U...\E)
128-
\Uabc\E ABC <Unrecognized> retired metachars (\U...\E)
129-
\Qabc\E QabcE <Unsupported> retired metachars (\Q...\E)
130-
\Qabc d?\E abc d <Unsupported> retired metachars (\Q...\E)
131-
\Gabc Gabc <Unrecognized> retired metachars (\G)
132-
\1abc 1abc <Unrecognized> retired metachars (\1)
121+
\pabc pabc [Unrecognized] retired metachars (\p)
122+
\p{InConsonant} a [Unrecognized] retired metachars (\p)
123+
\Pabc Pabc [Unrecognized] retired metachars (\P)
124+
\P{InConsonant} a [Unrecognized] retired metachars (\P)
125+
\Labc\E LabcE [Unrecognized] retired metachars (\L...\E)
126+
\LABC\E abc [Unrecognized] retired metachars (\L...\E)
127+
\Uabc\E UabcE [Unrecognized] retired metachars (\U...\E)
128+
\Uabc\E ABC [Unrecognized] retired metachars (\U...\E)
129+
\Qabc\E QabcE [Unsupported] retired metachars (\Q...\E)
130+
\Qabc d?\E abc d [Unsupported] retired metachars (\Q...\E)
131+
\Gabc Gabc [Unrecognized] retired metachars (\G)
132+
\1abc 1abc [Unrecognized] retired metachars (\1)
133133
^ \s+ $ \x0009\x0020\x00a0\x000a\x000b\x000c\x000d\x0085 y 0-255 whitespace (\s)
134134
^ \h+ $ \x0009\x0020\x00a0 y 0-255 horizontal whitespace (\h)
135135
^ \V+ $ \x0009\x0020\x00a0 y 0-255 horizontal whitespace (\V)

0 commit comments

Comments
 (0)