/
match.t
49 lines (36 loc) · 1.49 KB
/
match.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use Test;
plan 18;
# L<S05/Substitution/>
my $str = 'hello';
ok $str.match(/h/), 'We can use match';
is $str, 'hello', '.. it does not do side effect';
ok $str.match(/h/)~~Match, '.. it returns a Match object';
#?DOES 6
{
for ('a'..'f') {
my $r = EVAL("rx/$_/");
is $str.match($r), $str~~/$r/, ".. works as ~~ matching '$str' with /$_/";
}
}
# it should work for everything that can be tied to a Str, according to S05
# but possibly it should just be defined in object as an exact alias to ~~ ?
$str = 'food';
my $m = $str.match(/$<x>=[f](o+)/);
ok $m ~~ Match, 'is a Match object';
is $m, 'foo', 'match object stringifies OK';
is $m<x>, 'f', 'match object indexes as a hash';
is $m[0], 'oo', 'match object indexes as an array';
# https://github.com/Raku/old-issue-tracker/issues/6132
{
is-deeply (for 1..10 { 'st' x $_ ~ 'T' ~~ m:i/T/ })».Str,
('T' xx 10), 'can ~~ m:i/T/';
is-deeply (for 1..10 { 'st' x $_ ~ 'T' ~~ /. <( [:i T]/ })».Str,
('T' xx 10), 'can ~~ /. <( [:i T]/';
is-deeply (for 1..10 { ('st' x $_ ~ 'T').match: /:i T/ })».Str,
('T' xx 10), 'can .match: /:i T/';
is-deeply (for 1..10 { S:i/T/Z/ with 'st' x $_ ~ 'T' })».Str,
(for 1..10 { 'st' x $_ ~ 'Z' }), 'can S:i/T/Z/';
is-deeply (for 1..10 { ('st' x $_ ~ 'T').subst: /:i T/, 'Z' })».Str,
(for 1..10 { 'st' x $_ ~ 'Z' }), 'can .subst: /:i T/, "Z"';
}
# vim: expandtab shiftwidth=4