Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 114 lines (85 sloc) 3.126 kB
808f7c2 [t/spec] S05 - Moved P5/Perl5 modifier tests into spec (rakudo can't …
unobe authored
1 use v6;
2
3 use Test;
4
b6ba504 @coke pugs fudges
coke authored
5 plan 24;
808f7c2 [t/spec] S05 - Moved P5/Perl5 modifier tests into spec (rakudo can't …
unobe authored
6
7 # Really really really minimal s:P5//// and m:P5 tests. Please add more!!
8
9 #L<S05/Modifiers/"The extended syntax">
10
11 unless "a" ~~ m:P5/a/ {
cf81ec2 @coke kebab case skip-rest
coke authored
12 skip-rest "skipped tests - P5 regex support appears to be missing";
808f7c2 [t/spec] S05 - Moved P5/Perl5 modifier tests into spec (rakudo can't …
unobe authored
13 exit;
14 }
15
16 my $foo = "foo";
17 $foo ~~ s:Perl5{f}=q{b};
18 is($foo, "boo", 'substitute regexp works');
19 unless $foo eq "boo" {
20 skip_rest "Skipping test which depend on a previous failed test";
21 }
22
23 my $bar = "barrrr";
24 $bar ~~ s:Perl5:g{r+}=q{z};
25 is($bar, "baz", 'substitute regexp works with :g modifier');
26
27 my $path = "/path//to///a//////file";
28 $path ~~ s:Perl5:g{/+} = '/';
29 is($path, "/path/to/a/file", 'substitute regexp works with :g modifier');
30
31 my $baz = "baz";
32 $baz ~~ s:Perl5{.(a)(.)}=qq{$1$0p};
33 is($baz, "zap", 'substitute regexp with capturing variables works');
34
35 my $bazz = "bazz";
36 $bazz ~~ s:Perl5:g{(.)}=qq{x$0};
37 is($bazz, "xbxaxzxz", 'substitute regexp with capturing variables works with :g');
38
39 my $bad = "1 ";
40 $bad ~~ s:Perl5:g/\s*//;
41 is($bad, "1", 'Zero width replace works with :g');
42
43 {
44 my $r;
45 temp $_ = 'heaao';
46 s:Perl5 /aa/ll/ && ($r = $_);
ba8e84a [t/spec] Change more Pugs todo flags to fudge commands
kyle authored
47 is $r, 'hello', 's/// in boolean context properly defaults to $_';
808f7c2 [t/spec] S05 - Moved P5/Perl5 modifier tests into spec (rakudo can't …
unobe authored
48 }
49
50 my $str = "http://foo.bar/";
51 ok(($str ~~ m:Perl5/http:\/\//), "test the regular expression escape");
52
53 # returns the count of matches in scalar
54 my $vals = "hello world" ~~ m:P5:g/(\w+)/;
9c40515 @dnmfarrell fixed appended RT number to be within quoted string
dnmfarrell authored
55 #?rakudo todo 'NYI RT #125036'
808f7c2 [t/spec] S05 - Moved P5/Perl5 modifier tests into spec (rakudo can't …
unobe authored
56 is($vals, 2, 'returned two values in the match');
57
58 # return all the strings we matched
59 my @vals = "hello world" ~~ m:P5:g/(\w+)/;
60 is(+@vals, 2, 'returned two values in the match');
61 is(@vals[0], 'hello', 'returned correct first value in the match');
62 is(@vals[1], 'world', 'returned correct second value in the match');
63
8ed5f61 [t/spec] many small improvements:
moritz authored
64 {
65 "a" ~~ m:Perl5/a|(b)/;
2544bcf @jdhore Remove most remaining .notdef's.
jdhore authored
66 nok($0.defined, 'An unmatched capture should be undefined.');
8ed5f61 [t/spec] many small improvements:
moritz authored
67 my $str = "http://foo.bar/";
68 ok(($str ~~ m:Perl5 {http{0,1}}));
69
70 my $rule = '\d+';
fd42eb1 @coke rakudo fudge
coke authored
71 #?rakudo todo 'NYI'
8ed5f61 [t/spec] many small improvements:
moritz authored
72 ok('2342' ~~ m:P5/$rule/, 'interpolated rule applied successfully');
73
74 my $rule2 = 'he(l)+o';
fd42eb1 @coke rakudo fudge
coke authored
75 #?rakudo todo 'NYI'
8ed5f61 [t/spec] many small improvements:
moritz authored
76 ok('hello' ~~ m:P5/$rule2/, 'interpolated rule applied successfully');
77
78 my $rule3 = 'r+';
79 my $subst = 'z';
80 my $bar = "barrrr";
81 $bar ~~ s:P5:g{$rule3}=qq{$subst};
fd42eb1 @coke rakudo fudge
coke authored
82 #?rakudo todo 'NYI'
8ed5f61 [t/spec] many small improvements:
moritz authored
83 is($bar, "baz", 'variable interpolation in substitute regexp works with :g modifier');
84
85 my $a = 'a:';
86 $a ~~ s:P5 [(..)]=qq[{uc $0}];
87 is($a, 'A:', 'closure interpolation with qq[] as delimiter');
88
89 my $b = 'b:';
90 $b ~~ s:P5{(..)} = uc $0;
91 is($b, 'B:', 'closure interpolation with no delimiter');
92 }
808f7c2 [t/spec] S05 - Moved P5/Perl5 modifier tests into spec (rakudo can't …
unobe authored
93
94 {
95 diag "Now going to test numbered match variable.";
96 "asdfg/" ~~ m:P5 {^(\w+)?/(\w+)?}; $1 ?? "true" !! "false";
97
98 ok !$1, "Test the status of non-matched number match variable (1)";
99 }
100
101 {
102 "abc" ~~ m:P5/^(doesnt_match)/;
103
104 ok !$1, "Test the status of non-matched number match variable (2)";
105 }
106
107 my $rule = rx:P5/\s+/;
bb0a8fa @lizmat Use isa-ok instead of isa_ok
lizmat authored
108 isa-ok($rule, 'Regex');
808f7c2 [t/spec] S05 - Moved P5/Perl5 modifier tests into spec (rakudo can't …
unobe authored
109
110 ok("hello world" ~~ $rule, '... applying rule object returns true');
111 ok(!("helloworld" ~~ $rule), '... applying rule object returns false (correctly)');
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
112
113 # vim: ft=perl6
Something went wrong with that request. Please try again.