Skip to content

Instantly share code, notes, and snippets.

@labster
Created May 20, 2013 04:34
Show Gist options
  • Save labster/5610434 to your computer and use it in GitHub Desktop.
Save labster/5610434 to your computer and use it in GitHub Desktop.
test file for "my $"
use v6;
use Test;
plan 10;
#bare sigils
lives_ok { my $ }, 'basic bare sigil $';
lives_ok { my @ }, 'basic bare sigil @';
lives_ok { my % }, 'basic bare sigil %';
is (my $ = "foo"), "foo", 'initialized bare sigil scalar $';
ok (my @ = 1, 2, 3), 'initialized bare sigil array @';
ok (my % = baz => "luhrman"), 'initialized bare sigil hash %';
# RT #116521
# 'state' with anonymous scalars works more like 'my' in Rakudo
{
sub f { ++state $ ; }
is (f, f, f), (1, 2, 3), "anonymous 'state' bare sigil scalar retains state";
sub g { ++state $ = 3; }
is (g, g, g), (4, 5, 6), "anonymous 'state' bare sigil scalar is initialized";
}
{
sub d { state $i = 0; (state @).push( $i++ ) }
d;
is +d(), 2, "anonymous 'state' bare sigil array retains state";
is d()[2], 2, "anonymous 'state' bare sigil array can grow";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment