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 48 lines (33 sloc) 1.263 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
use v6;

use Test;

plan 5;

# L<S05/"Matching against non-strings">

# String-like things...

my $fh = open($?FILE);
regex monster { dr\wgon }; # contrived pattern which does not match itself; we're going to look for it in this file
regex cheese { camembert | cheddar };
my $stream:= cat $fh.lines;

#?pugs todo 'matching against Cat objects'
ok($stream ~~ /<cheese>/, 'rules on streams, positive'); # should match
ok($stream !~~ /<monster>/, 'rules on streams, negative'); # shouldn't match

# And arrays...

class Dog {...}
class Cat {...}
class Fish {...}

my Dog $a;
my Cat $b;
my Fish $c;

my @array = ($a, $b, $c);
regex canine { <.isa(Dog)> }
regex herbivore { <.isa(::Antelope)> };

# does that work? ord does it need a Cat?
ok(@array ~~ /<canine>/, 'rules on an array - positive');
ok(@array !~~ /<herbivore>/, 'rules on an array - negative');
# These seem to be failing for some sort of scoping error rather than a problem with the
# regex matching itself.

# And matching against each element of an array... a different topic really, but it's still in
# that bit of the synopsis.

my @names = ('zaphod', 'ford', 'arthur', 'slartibartfast');
my $arrr = regex { ar };
is(+(@names>>.match($arrr)), 2, 'matching with hyper-operator');

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