Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: a842b80582
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 96 lines (74 sloc) 2.742 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 82 83 84 85 86 87 88 89 90 91 92 93 94 95
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/litvar.t.

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

=end pod

plan 30;

# L<S05/Variable (non-)interpolation/The default way in which the engine handles a scalar>

my $var = "a*b";
my @var = <a b c>;
my %var = (a=>1, b=>2, c=>3);
my $aref = \@var;
my $href = \%var;


# SCALARS

# just document ticket test below
#?rakudo skip 'RT 61960'
#?pugs 2 todo 'bug'
ok($var ~~ m/$var/, 'Simple scalar interpolation');
ok("zzzzzz{$var}zzzzzz" ~~ m/$var/, 'Nested scalar interpolation');
ok(!( "aaaaab" ~~ m/$var/ ), 'Rulish scalar interpolation');

#?pugs 6 todo 'feature'
#?niecza todo
ok('a' ~~ m/$aref[0]/, 'Array ref 0');
#?niecza todo
ok('a' ~~ m/$aref.[0]/, 'Array ref dot 0');
#?niecza todo
ok('a' ~~ m/@var[0]/, 'Array 0');

#?niecza todo
ok('1' ~~ m/$href.{'a'}/, 'Hash ref dot A');
#?niecza todo
ok('1' ~~ m/$href{'a'}/, 'Hash ref A');
#?niecza skip 'Only $ and @ variables may be used in regexes for now'
ok('1' ~~ m/%var{'a'}/, 'Hash A');

#?niecza todo
#?pugs todo
ok('1' ~~ m/$href.<a>/, 'Hash ref dot A');
#?niecza todo
#?pugs todo
ok('1' ~~ m/$href<a>/, 'Hash ref A');
#?niecza skip 'Only $ and @ variables may be used in regexes for now'
#?pugs todo
ok('1' ~~ m/%var<a>/, 'Hash A');

ok(!( 'a' ~~ m/$aref[1]/ ), 'Array ref 1');
ok(!( 'a' ~~ m/$aref.[1]/ ), 'Array ref dot 1');
ok(!( 'a' ~~ m/@var[1]/ ), 'Array 1');
ok(!( '1' ~~ m/$href.{'b'}/ ), 'Hash ref dot B');
ok(!( '1' ~~ m/$href{'b'}/ ), 'Hash ref B');
#?niecza skip 'Only $ and @ variables may be used in regexes for now'
ok(!( '1' ~~ m/%var{'b'}/ ), 'Hash B');
ok(!( '1' ~~ m/$href.<b>/ ), 'Hash ref dot B');
ok(!( '1' ~~ m/$href<b>/ ), 'Hash ref B');
#?niecza skip 'Only $ and @ variables may be used in regexes for now'
ok(!( '1' ~~ m/%var<b>/ ), 'Hash B');

# REGEXES
# However, if $var contains a Regex object, instead of attempting to convert it to a string, it is called as a subrule
# A simple test for this
my $rx = rx/foo/;
#?pugs todo
ok('foobar' ~~ /$rx bar/, 'regex object in a regex');
ok('quxbaz' !~~ /$rx baz/, 'nonmatching regex object in a regex');


# ARRAYS
# L<S05/Variable (non-)interpolation/An interpolated array:>

#?pugs 3 todo 'feature'
ok("a" ~~ m/@var/, 'Simple array interpolation (a)');
ok("b" ~~ m/@var/, 'Simple array interpolation (b)');
ok("c" ~~ m/@var/, 'Simple array interpolation (c)');
ok(!( "d" ~~ m/@var/ ), 'Simple array interpolation (d)');
#?pugs 2 todo 'feature'
ok("ddddaddddd" ~~ m/@var/, 'Nested array interpolation (a)');

ok("abca" ~~ m/^@var+$/, 'Multiple array matching');
ok(!( "abcad" ~~ m/^@var+$/ ), 'Multiple array non-matching');

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