Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 82 lines (64 sloc) 2.835 kb
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
use v6;

use Test;

=begin pod

This file was derived from the perl5 CPAN module Perl6::Rules,
version 0.3 (12 Apr 2004), file t/repeat.t.

It has (hopefully) been, and should continue to be, updated to
be valid perl6.

=end pod

# Note: single-quotes.t tests repetition on single quoted items in regexes.

plan 24;

# L<S05/Bracket rationalization/The general repetition specifier is now>

# Exact repetition
#?pugs todo
ok("abcabcabcabcd" ~~ m/'abc'**4/, 'Fixed exact repetition');
#?pugs todo
is $/, 'abc' x 4, '...with the correct capture';
ok(!("abcabcabcabcd" ~~ m/'abc'**5/), 'Fail fixed exact repetition');
#?pugs todo force_todo
#?rakudo 2 skip 'closure repetition'
ok("abcabcabcabcd" ~~ m/'abc'**{4}/, 'Fixed exact repetition using closure');
ok(!( "abcabcabcabcd" ~~ m/'abc'**{5}/ ), 'Fail fixed exact repetition using closure');

# Closed range repetition
#?pugs todo
ok("abcabcabcabcd" ~~ m/'abc'**2..4/, 'Fixed range repetition');
ok(!( "abc" ~~ m/'abc'**2..4/ ), 'Fail fixed range repetition');
#?pugs todo force_todo
#?rakudo 2 skip 'closure repetition'
ok("abcabcabcabcd" ~~ m/'abc'**{2..4}/, 'Fixed range repetition using closure');
ok(!( "abc" ~~ m/'abc'**{2..4}/ ), 'Fail fixed range repetition using closure');

# Open range repetition
#?pugs todo
ok("abcabcabcabcd" ~~ m/'abc'**2..*/, 'Open range repetition');
ok(!( "abcd" ~~ m/'abc'**2..*/ ), 'Fail open range repetition');
#?pugs todo force_todo
#?rakudo 2 skip 'closure repetition'
ok("abcabcabcabcd" ~~ m/'abc'**{2..*}/, 'Open range repetition using closure');
ok(!( "abcd" ~~ m/'abc'**{2..*}/), 'Fail open range repetition using closure');

# It is illegal to return a list, so this easy mistake fails:
#?pugs todo
eval_dies_ok('"foo" ~~ m/o{1,3}/', 'P5-style {1,3} range mistake is caught');
#?pugs todo
eval_dies_ok('"foo" ~~ m/o{1,}/', 'P5-style {1,} range mistake is caught');

#?pugs todo
is(~('foo,bar,baz,' ~~ m/[<alpha>+]+ % ','/), 'foo,bar,baz', '% with a term worked');
#?pugs todo
is(~('foo,bar,baz,' ~~ m/[<alpha>+]+ %% ','/), 'foo,bar,baz,', '%% with a term worked');
#?pugs todo
is(~('foo, bar,' ~~ m/[<alpha>+]+ % [','\s*]/), 'foo, bar', '% with a more complex term');

ok 'a, b, c' !~~ /:s^<alpha>+%\,$/, 'with no spaces around %, no spaces can be matched';
#?pugs todo
ok 'a, b, c' ~~ /:s^ <alpha> +% \, $/, 'with spaces around %, spaces can be matched';
#?pugs todo
ok 'a , b ,c' ~~ /:s^ <alpha> +% \, $/, 'same, but with leading spaces';

# RT #76792
#?pugs todo
ok ('a b,c,d' ~~ token { \w \s \w+ % \, }), 'can combine % with backslash character classes';

# RT #119513
#?pugs 2 todo
#?niecza 2 todo 'underscore in quantifier numeral'
{
    ok ("a" x 1_0 ~~ /a ** 1_0/, 'underscore in quantifier numeral (1)' );
    ok ( "a_0" !~~ /a ** 1_0/, 'underscore in quantifier numeral (2)' );
}

# vim: ft=perl6
Something went wrong with that request. Please try again.