Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Unfudge / fix "of Type" related tests
  • Loading branch information
lizmat committed Aug 19, 2013
1 parent b337aa4 commit 7b2783d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
1 change: 0 additions & 1 deletion S02-types/keybag.t
Expand Up @@ -380,7 +380,6 @@ sub showkv($x) {
#?niecza skip "Trait name not available on variables"
{
my %h of KeyBag;
#?rakudo todo '%h of TypeObject syntax not working yet'
ok %h.of.perl eq 'KeyBag', 'is the hash really a KeyBag';
#?rakudo 2 todo 'in flux'
lives_ok { %h = bag <a b c d c b> }, 'Assigning a Bag to a KeyBag';
Expand Down
43 changes: 24 additions & 19 deletions S09-typed-arrays/arrays.t
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 58;
plan 61;

# L<S09/Typed arrays/>

Expand All @@ -20,26 +20,28 @@ plan 58;
is @x.unshift(2), [2, 2, 3], 'can unshift from typed array';
} #9

#?rakudo skip 'of Int'
{
my @x of Int;
ok @x.of === Int, '@x.of of typed array (my @x of Int)';
lives_ok { @x = 1, 2, 3 }, 'can assign values of the right type (@x of Int)';
lives_ok { @x = 1..3 }, 'can assign range of the right type (@x of Int)';
lives_ok { @x.push: 3, 4}, 'can push values of the right type (@x of Int)';
lives_ok { @x.unshift: 3}, 'can unshift values of the right type (@x of Int)';
lives_ok { @x[0, 2] = 2, 3}, 'can assign values to a slice (@x of Int)';
my Int @x;
ok @x.VAR.of === Int, '@x.VAR.of of typed array (my Int @x)';
lives_ok { @x = 1, 2, 3 }, 'can assign values of the right type (Int @x)';
lives_ok { @x = 1..3 }, 'can assign range of the right type (Int @x)';
lives_ok { @x.push: 3, 4}, 'can push values of the right type (Int @x)';
lives_ok { @x.unshift: 3}, 'can unshift values of the right type (Int @x)';
lives_ok { @x[0, 2] = 2, 3}, 'can assign values to a slice (Int @x)';
@x = 2, 3, 4;
is @x.pop, 4, 'can pop from typed array (@x of Int)';
is @x.unshift(1), [1, 2, 3], 'can unshift from typed array (@x of Int)';
is @x.pop, 4, 'can pop from typed array (Int @x)';
is @x.unshift(1), [1, 2, 3], 'can unshift from typed array (Int @x)';
} #8

# initialization
lives_ok { my @x = 1, 2, 3 }, 'initialization of typed array';
lives_ok { my @x = 1 .. 3 }, 'initialization of typed array from range';
{
lives_ok { my Int @x = 1, 2, 3 }, 'initialization of typed array';
lives_ok { my Int @x = 1 .. 3 }, 'initialization of typed array from range';
} #2

{
my @x of Int;
ok @x.VAR.of === Int, '@x.VAR.of of typed array (my @x of Int)';
lives_ok { @x = 1, 2, 3 }, 'can assign values of the right type (@x of Int)';
lives_ok { @x = 1..3 }, 'can assign range of the right type (@x of Int)';
lives_ok { @x.push: 3, 4}, 'can push values of the right type (@x of Int)';
Expand All @@ -49,10 +51,11 @@ lives_ok { my @x = 1 .. 3 }, 'initialization of typed array from range';
is @x.pop, 4, 'can pop from typed array (@x of Int)';

ok @x.unshift, 'can unshift from typed array (@x of Int)';
} #7
} #8

{
my Array @x;
ok @x.VAR.of === Array, '@x.VAR.of of typed array (my Array @x)';
dies_ok { @x = 1, 2, 3 }, 'can not assign values of the wrong type';
dies_ok { @x = 1..3 }, 'can not assign range of the wrong type';
dies_ok { @x.push: 3, 4}, 'can not push values of the wrong type';
Expand All @@ -61,28 +64,30 @@ lives_ok { my @x = 1 .. 3 }, 'initialization of typed array from range';
'can not assign values of wrong type to a slice';
lives_ok { @x = [1, 2], [3, 4] },
'... but assigning values of the right type is OK';
} #6
} #7

{
my @x of Array;
ok @x.VAR.of === Array, '@x.VAR.of of typed array (my @x of Array)';
dies_ok { @x = 1, 2, 3 }, 'can not assign values of the wrong type';
dies_ok { @x = 1..3 }, 'can not assign range of the wrong type';
#?rakudo 3 todo "no parametrization"
dies_ok { @x.push: 3, 4}, 'can not push values of the wrong type';
dies_ok { @x.unshift: 3}, 'can not unshift values of the wrong type';
dies_ok { @x[0, 2] = 2, 3},
'can not assign values of wrong type to a slice';
lives_ok { @x = [1, 2], [3, 4] },
'... but assigning values of the right type is OK';
} #6
} #7

#?rakudo skip 'Array not parametric'
{
my Array of Int @x;
ok @x.of === Array[Int], 'my Array of Int @x declares a nested array';
#?rakudo skip "nested typechecks are borked"
lives_ok { @x = [2, 3], [5, 6] }, 'assignment works';
#?rakudo todo "nested typechecks are borked"
lives_ok { @x.push: [8, 9] }, 'pushing works';
dies_ok { @x.push: 8 }, 'type constraint is enforced';
#?rakudo todo "nested typechecks are borked"
lives_ok { @x[0].push: 3 }, 'pushing to the inner array is OK';
dies_ok { @x[0].push: 'foo' }, 'inner array enforces the type constraint';
} #6
Expand All @@ -100,7 +105,7 @@ lives_ok { my @x = 1 .. 3 }, 'initialization of typed array from range';
#?rakudo skip 'initialization'
{
my Str @c = <foo bar baz>;
ok @c.keys.of.WHICH eqv Str.WHICH, '@array.keys is typed with Int';
ok @c.keys.of.WHICH eqv Str.WHICH, '@array.keys is typed with Str';
} #1

# test that we can have parametric array return types
Expand Down

0 comments on commit 7b2783d

Please sign in to comment.