Skip to content

Commit 48d0448

Browse files
committed
[t/p6eregex] add first shot of regex test runner
1 parent de3220e commit 48d0448

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

t/p6regex/01-regex.t

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#! nqp
2+
my @files := [
3+
'rx_basic',
4+
'rx_metachars',
5+
# contains /<xaaaay @ 0>/ - style things, NYI
6+
# 'rx_quantifiers',
7+
'rx_backtrack',
8+
'rx_charclass',
9+
# contains /mob <alnum>: <0 @ 35>/ - style things, NYI
10+
# 'rx_subrules',
11+
# 'rx_lookarounds',
12+
# 'rx_captures',
13+
# 'rx_modifiers',
14+
'rx_goal',
15+
];
16+
17+
sub test_line($line) {
18+
my @chunks := match($line, /\T+/, :global);
19+
my $regex := ~@chunks[0];
20+
my $string := ~@chunks[1];
21+
my $expected := ~@chunks[2];
22+
my $description := ~@chunks[3];
23+
24+
my $expected_error := 0;
25+
26+
if $expected ~~ /^\// {
27+
$expected_error := pir::substr($expected, 1, pir::length($expected) - 2);
28+
}
29+
$string := '' if $string eq "''";
30+
31+
my $error := 0;
32+
try {
33+
my $result := $string ~~ /<$regex>/;
34+
CATCH {
35+
$error := 1;
36+
if $expected_error {
37+
my $m := "$_" ~~ /<$expected_error>/;
38+
ok($m, $description);
39+
unless $m {
40+
say("# got: $_");
41+
say("# expected: $expected_error");
42+
}
43+
} else {
44+
ok(0, $description);
45+
say("# ERROR: $_");
46+
}
47+
}
48+
unless $error {
49+
if $expected_error {
50+
ok(0, $description);
51+
say("# expected error /$expected_error/, but no exception thrown");
52+
} elsif ($expected eq 'y') {
53+
ok($result, $description);
54+
} else {
55+
ok(!$result, $description);
56+
}
57+
58+
}
59+
}
60+
}
61+
62+
for @files -> $fn {
63+
say("# file: $fn");
64+
my $contents := slurp('t/p6regex/' ~ $fn);
65+
my @lines := pir::split("\n", $contents);
66+
67+
# trailing newlines
68+
pir::pop(@lines);
69+
70+
for @lines -> $l {
71+
my $m := $l ~~ /'# todo' .*? ':pge<' (.*?) '>'/;
72+
if $m {
73+
todo(~$m[0], 1);
74+
} else {
75+
next if $l ~~ /^'#'/;
76+
next unless $l ~~ /\S/;
77+
test_line($l);
78+
}
79+
}
80+
say("# done with file $fn");
81+
}
82+

0 commit comments

Comments
 (0)