Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add a lot of 'use variables' related testing
  • Loading branch information
lizmat committed Oct 8, 2015
1 parent d3b8702 commit 22e4acc
Showing 1 changed file with 135 additions and 21 deletions.
156 changes: 135 additions & 21 deletions S04-declarations/smiley.t
@@ -1,29 +1,9 @@
use v6;
use Test;

plan 12;

my Int:_ $a; is $a, Int, 'Int:_ without initializer';
my Int:_ $b = Int; is $b, Int, 'Int:_ with initializer (type object)';
my Int:_ $c = 42; is $c, 42, 'Int:_ with initializer (instance)';

throws-like 'my Int:D $d;',
X::Syntax::Variable::MissingInitializer,
type => 'Int:D',
'Int:D without initializer throws';
my Int:D $e = 42; is $e, 42, 'Int:D with initializer';
throws-like 'my Int:D $i = Int',
X::TypeCheck,
'Int:D with wrong initializer';

my Int:U $g; ok $g ~~ Int, 'Int:U without initializer';
my Int:U $h = Int; ok $h ~~ Int, 'Int:U with initializer';
throws-like 'my Int:U $i = 42',
X::TypeCheck,
'Int:U with wrong initializer';
plan 57;

my Int:D $j = 256;

MY::<$j> = 111;
is $j, 111, 'instance assignment to Int:D via MY:: pseudo package works';

Expand All @@ -33,4 +13,138 @@ is $j, 111, 'typeobject assignment to Int:D via MY:: pseudo package fails';
try $j = Int;
is $j, 111, 'typeobject assignment to Int:D fails';

is { my Int $a }(), Int, 'can Int be on its own';
is { my Int $a = Int }(), Int, 'can Int take an Int:U';
is { my Int $a = 42 }(), 42, 'can Int take an Int:D';

is { my Int:_ $a }(), Int, 'can Int:_ be on its own';
is { my Int:_ $a = Int }(), Int, 'can Int:_ take an Int:U';
is { my Int:_ $a = 42 }(), 42, 'can Int:_ take an Int:D';

#?rakudo todo 'type is being set weirdly'
is { my Int:U $a }(), Int, 'can Int:U be on its own';
is { my Int:U $a = Int }(), Int, 'can Int:U take an Int:U';
throws-like { my Int:U $a = 42 },
X::TypeCheck::Assignment,
symbol => '$a', 'can Int:U take an Int:D';

throws-like 'my Int:D $a',
X::Syntax::Variable::MissingInitializer,
type => 'Int:D', 'can Int:D be on its own';
throws-like { my Int:D $a = Int },
X::TypeCheck::Assignment,
symbol => '$a', 'can Int:D take an Int:U';
is { my Int:D $a = 42 }(), 42, 'can Int:D take an Int:D';

{
use variables :_;
is { my Int $a }(), Int, 'with :_, can Int be on its own';
is { my Int $a = Int }(), Int, 'with :_, can Int take an Int:U';
is { my Int $a = 42 }(), 42, 'with :_, can Int take an Int:D';

is { my Int:_ $a }(), Int, 'with :_, can Int:_ be on its own';
is { my Int:_ $a = Int }(), Int, 'with :_, can Int:_ take an Int:U';
is { my Int:_ $a = 42 }(), 42, 'with :_, can Int:_ take an Int:D';

#?rakudo todo 'type is being set weirdly'
is { my Int:U $a }(), Int, 'with :_, can Int:U be on its own';
is { my Int:U $a = Int }(), Int, 'with :_, can Int:U take an Int:U';
throws-like { my Int:U $a = 42 },
X::TypeCheck::Assignment,
symbol => '$a', 'with :_, can Int:U take an Int:D';

throws-like 'my Int:D $a',
X::Syntax::Variable::MissingInitializer,
type => 'Int:D', 'with :_, can Int:D be on its own';
throws-like { my Int:D $a = Int },
X::TypeCheck::Assignment,
symbol => '$a', 'with :_, can Int:D take an Int:U';
is { my Int:D $a = 42 }(), 42, 'with :_, can Int:D take an Int:D';
}

{
use variables :U;
#?rakudo todo 'type is being set weirdly'
is { my Int $a }(), Int, 'with :U, can Int be on its own';
is { my Int $a = Int }(), Int, 'with :U, can Int take an Int:U';
throws-like { my Int $a = 42 },
X::TypeCheck::Assignment,
symbol => '$a', 'with :U, can Int take an Int:D';

is { my Int:_ $a }(), Int, 'with :U, can Int:_ be on its own';
is { my Int:_ $a = Int }(), Int, 'with :U, can Int:_ take an Int:U';
is { my Int:_ $a = 42 }(), 42, 'with :U, can Int:_ take an Int:D';

#?rakudo todo 'type is being set weirdly'
is { my Int:U $a }(), Int, 'with :U, can Int:U be on its own';
is { my Int:U $a = Int }(), Int, 'with :U, can Int:U take an Int:U';
throws-like { my Int:U $a = 42 },
X::TypeCheck::Assignment,
symbol => '$a', 'with :U, can Int:U take an Int:D';

throws-like 'use variables :U; my Int:D $a', # XXX pragma's not seen in EVAL
X::Syntax::Variable::MissingInitializer,
type => 'Int:D', 'with :U, can Int:D be on its own';
throws-like { my Int:D $a = Int },
X::TypeCheck::Assignment,
symbol => '$a', 'with :U, can Int:D take an Int:U';
is { my Int:D $a = 42 }(), 42, 'with :U, can Int:D take an Int:D';
}

{
use variables :D;
throws-like 'use variables :D; my Int $a', # XXX pragma's not seen in EVAL
X::Syntax::Variable::MissingInitializer,
type => 'Int (with implicit :D)',
'with :D, can Int be on its own';
throws-like { my Int $a = Int },
X::TypeCheck::Assignment,
symbol => '$a', 'with :D, can Int take an Int:U';
is { my Int $a = 42 }(), 42, 'with :D, can Int take an Int:D';

is { my Int:_ $a }(), Int, 'with :D, can Int:_ be on its own';
is { my Int:_ $a = Int }(), Int, 'with :D, can Int:_ take an Int:U';
is { my Int:_ $a = 42 }(), 42, 'with :D, can Int:_ take an Int:D';

#?rakudo todo 'type is being set weirdly'
is { my Int:U $a }(), Int, 'with :D, can Int:U be on its own';
is { my Int:U $a = Int }(), Int, 'with :D, can Int:U take an Int:U';
throws-like { my Int:U $a = 42 },
X::TypeCheck::Assignment,
symbol => '$a', 'with :D, can Int:U take an Int:D';

throws-like 'use variables :D; my Int:D $a', # XXX pragma's not seen in EVAL
X::Syntax::Variable::MissingInitializer,
type => 'Int:D', 'with :D, can Int:D be on its own';
throws-like { my Int:D $a = Int },
X::TypeCheck::Assignment,
symbol => '$a', 'with :D, can Int:D take an Int:U';
is { my Int:D $a = 42 }(), 42, 'with :D, can Int:D take an Int:D';
}

throws-like 'my Int:foo $a',
X::InvalidTypeSmiley, 'does Int:foo fail';

throws-like 'use variables',
X::Pragma::MustOneOf,
name => "variables",
'does use variables fail';
throws-like 'no variables',
X::Pragma::CannotNo,
name => "variables",
'does no variables fail';
throws-like 'use variables "bar"',
X::Pragma::UnknownArg,
name => "variables",
arg => "bar",
'does use variables "bar" fail';
throws-like 'use variables :U, :D',
X::Pragma::OnlyOne,
name => 'variables',
'does use variables :U, :D fail';
throws-like 'use variables :foo',
X::InvalidTypeSmiley,
name => 'foo',
'does use variables :foo fail';

# vim: ft=perl6

0 comments on commit 22e4acc

Please sign in to comment.