Skip to content
This repository
Newer
Older
100644 87 lines (70 sloc) 2.647 kb
877780f9 »
2011-12-25 Some more regex tests... should merge these into roast
1 use Test;
2
3 {
4 "fooxbar" ~~ /x/;
5 is $/.prematch, "foo", ".prematch works";
6 is $/.postmatch, "bar", ".postmatch works";
7
8 is ("foo" ~~ /(f)/).kv.join("|"), '0|f', '.kv sees positional';
9 is ("foo" ~~ /$<x>=[f]/).kv.join("|"), 'x|f', '.kv sees names';
10 is ("foo" ~~ /(f)/).keys.join("|"), '0', '.keys sees positional';
11 is ("foo" ~~ /$<x>=[f]/).keys.join("|"), 'x', '.keys sees names';
12 is ("foo" ~~ /(f)/).values.join("|"), 'f', '.values sees positional';
13 is ("foo" ~~ /$<x>=[f]/).values.join("|"), 'f', '.values sees names';
14
15 "abcdefg" ~~ / b $<x>=[c] d (e) f /;
16 is $/.caps».key.join('|'), 'x|0', '.caps works (keys)';
17 is $/.caps».value.join('|'), 'c|e', '.caps works (values)';
18 is $/.chunks».key.join('|'), '~|x|~|0|~', '.chunks works (keys)';
19 is $/.chunks».value.join('|'), 'b|c|d|e|f', '.chunks works (values)';
20 }
21
22 {
23 "foo" ~~ /./;
24 is "+a+".subst(/\w/, { uc $/ }), '+A+', 'can use $/ in subst() arg';
25 is ~$/, 'f', '$/ restored after subst';
26 $_ = "baa5ar";
27 s/\d//;
28 is ~$/, '5', 's/// resets $/';
29 }
88d20b0c »
2011-12-27 Allow <foo=$bar> to work (fixes #95)
30
31 {
32 my $hello = "'/'hello'/'(<-[\\\\/\\\\.]>+)";
33 my $reg = / ^ <hello=$hello> $/;
34 "/hello/bug" ~~ $reg;
35 is $/<hello>[0], 'bug', '<foo=$bar> works';
36 }
68f80b85 »
2011-12-29 Fix for $<a>=[ <b>+ ] (masak)++
37
38 # http://irclog.perlgeek.de/perl6/2011-12-29#i_4894154
39 {
40 "ab" ~~ / $<a>=[ <alpha>+ ] /;
41 is $<alpha>[1], "b", "<foo>+ inside string capture works";
42 }
ed7ed595 »
2011-12-31 Test for a currently broken MMD case
43
44 # the Rakudo-inherited algorithm failed on this one.
45 {
46 my class A { }
47 my class B is A { }
48 my class C is B { }
49
50 multi foo(A $, A $) { "AA" }
51 multi foo(A $, B $) { "AB" }
52 multi foo(A $, C $) { "AC" }
53 multi foo(B $, A $) { "BA" }
54 multi foo(C $, A $) { "CA" }
55
56 dies_ok { foo(B, C) }, "hard case of catching ambiguous dispatch";
57 }
0d058375 »
2011-12-31 Add parsing support for :_ :U :D :T
58
59 {
6fdfdad6 »
2011-12-31 Implement :D :U :T :_ (fixes #82)
60 sub foo(Any:U $) { } #OK
61 sub bar(Any:D $) { } #OK
62 sub moo(Any:_ $) { } #OK
63 sub cow(Any:T $) { } #OK
0d058375 »
2011-12-31 Add parsing support for :_ :U :D :T
64
65 multi qux(Any:U $) { "U" }
66 multi qux(Any:D $) { "D" }
67
6fdfdad6 »
2011-12-31 Implement :D :U :T :_ (fixes #82)
68 lives_ok { eval "foo(Int)" }, ":U allows type objects";
69 dies_ok { eval "foo(5)" }, ":U denies concrete objects";
0d058375 »
2011-12-31 Add parsing support for :_ :U :D :T
70
6fdfdad6 »
2011-12-31 Implement :D :U :T :_ (fixes #82)
71 lives_ok { eval "bar(5)" }, ":D allows concrete objects";
72 dies_ok { eval "bar(Int)" }, ":D denies type objects";
0d058375 »
2011-12-31 Add parsing support for :_ :U :D :T
73
6fdfdad6 »
2011-12-31 Implement :D :U :T :_ (fixes #82)
74 lives_ok { eval "moo(5)" }, ":_ allows concrete objects";
75 lives_ok { eval "moo(Int)" }, ":_ allows type objects";
0d058375 »
2011-12-31 Add parsing support for :_ :U :D :T
76
6fdfdad6 »
2011-12-31 Implement :D :U :T :_ (fixes #82)
77 lives_ok { eval "cow(Int)" }, ":T allows type objects";
78 dies_ok { eval "cow(5)" }, ":T denies concrete objects";
0d058375 »
2011-12-31 Add parsing support for :_ :U :D :T
79
80 is qux(Int), 'U', 'multi can discriminate on :U/:D (1)';
81 is qux(5), 'D', 'multi can discriminate on :U/:D (2)';
82 }
c8eeefc0 »
2012-01-04 @foo requires Positional, %foo requires Associative (fixes #50)
83
84 {
85 sub foo(%x) { } #OK
86 dies_ok { foo(3) }, '%x needs Associative';
87 }
Something went wrong with that request. Please try again.