Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
few tests for interpolation
  • Loading branch information
prakashk committed Jun 8, 2013
1 parent d6b2c23 commit e924567
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions t/001-literals/010-interpolation.t
@@ -0,0 +1,46 @@
use Test::More;

{
# interpolating into double quotes results in a Str
my $a = 3;
ok("$a".isa("Str"), '... "$a" results in a Str');
ok("{3}".isa("Str"), '... "{3}" results in a Str');
}

{
my $w = 'work';
is("this should $w", 'this should work', '... scalar interpolates');
}

{
my @array = 1..3;
is("@array[]", "[1, 2, 3]", "... @array[] interpolates");
is("@array", "@array", '... @array (without brackets) doesnt interpolate');
is("@array[1]", "2", '... @array element interpolates');
}

{
my %hash = {a => 1, b => 2};
ok("%hash{}" ne '%hash{}', '... %hash{} interpolates');
is("%hash", "%hash", '... %hash (without brackets) doesnt interpolate');
is("%hash{'b'}", "2", '... %hash element interpolates');
}

{
sub foo { 42 }
is("&foo()", "42", '... &foo() interpolates');
is("&foo", "&foo", '... &foo (without brackets) doesnt interpolate');
}

{
class A {
has $!foo = 42;
method foo { $!foo }
}

my $a = A.new;
is("$a.foo()", "42", '... method call $a.foo() interpolates');
is("$a.foo", '$a.foo', '... method call $a.foo (without brackets) doesnt interpolate');
}

done_testing();

0 comments on commit e924567

Please sign in to comment.