Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 62 lines (41 sloc) 2.759 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
#! nqp

plan(33);

my $b := "b+";
my @foo := [ "b+", "c+" ];

ok("ab+d" ~~ /a $b d/, 'plain scalar interpolates as literal 1');
ok(!("abbbbbd" ~~ /a $b d/), 'plain scalar interpolates as literal 2');

ok("ab+d" ~~ /a @foo d/, 'plain array interpolates as alternations of literals 1');
ok("ac+d" ~~ /a @foo d/, 'plain array interpolates as alternations of literals 2');
ok(!("abbbbbd" ~~ /a @foo d/), 'plain array interpolates as alternations of literals 3');
ok(!("acccccd" ~~ /a @foo d/), 'plain array interpolates as alternations of literals 4');

my @ltm := [ "b", "bb", "bbc", "bc" ];

ok(("abd" ~~ / @ltm /) eq 'b', 'array finds longest match 1');
ok(("abbd" ~~ / @ltm /) eq 'bb', 'array finds longest match 2');
ok(("abbcd" ~~ / @ltm /) eq 'bbc', 'array finds longest match 3');
ok(("abccd" ~~ / @ltm /) eq 'bc', 'array finds longest match 4');

ok(!("ab+d" ~~ /a <$b> d/), 'scalar assertion interpolates as regex 1');
ok("abbbbbd" ~~ /a <$b> d/, 'scalar assertion interpolates as regex 2');

ok(!("ab+d" ~~ /a <@foo> d/), 'array assertion interpolates as alternations of regexen 1');
ok(!("ac+d" ~~ /a <@foo> d/), 'array assertion interpolates as alternations of regexen 2');
ok("abbbbbd" ~~ /a <@foo> d/, 'array assertion interpolates as alternations of regexen 3');
ok("acccccd" ~~ /a <@foo> d/, 'array assertion interpolates as alternations of regexen 4');

ok(!("ab+d" ~~ /a <{ "b+" }> d/), 'code assersion interpolates as regex 1');
ok("abbbbd" ~~ /a <{ "b+" }> d/, 'code assersion interpolates as regex 2');

ok("abbbbd" ~~ /a <{ ["b+", "c+"] }> d/, 'code assertion that returns array interpolates as alternations of regexen 1');
ok("accccd" ~~ /a <{ ["b+", "c+"] }> d/, 'code assertion that returns array interpolates as alternations of regexen 2');

my $r := /b+/;

ok(!("ab+d" ~~ /a $r d/), 'plain scalar containing precompiled regex 1');
ok("abbbd" ~~ /a $r d/, 'plain scalar containing precompiled regex 2');

my @r := [ /b+/, "c+" ];

ok("abbbbd" ~~ /a @r d/, 'plain array containing mix of precompiled and literal 1');
ok("ac+d" ~~ /a @r d/, 'plain array containing mix of precompiled and literal 1');

my $xyz := 'xyz';

ok("axyzxyzd" ~~ /a $xyz+ d/, 'Quantified plain scalar 1');
ok("ab+b+b+d" ~~ /a $b+ d/, 'Quantified plain scalar 2');
ok("abbbc+bbbd" ~~ /a @r+ d/, 'Quantified plain array');
ok("abbbcccbbcd" ~~ /a <{ [ "b+", /c+/ ] }>+ d/, 'Quantified code assertion');

ok("ad" ~~ /a { "bc" } d/, "Plain closure doesn't interpolate 1");
ok(!("abcd" ~~ /a { "bc" } d/), "Plain closure doesn't interpolate 2");

ok("ad" ~~ /a <?{ 1 }> d/, 'Zero-width assertions still work 1');
ok(!("ad" ~~ /a <!{ 1 }> d/), 'Zero-width assertions still work 2');

ok("test.h" ~~ /.h$/, 'Do not parse $/ as variable interpolation');

Something went wrong with that request. Please try again.