Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added tests for .perl on hashes, explicitely typed or not
  • Loading branch information
lizmat committed Jul 8, 2013
1 parent 1a0d5d1 commit 6127abe
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions S32-hash/perl.t
@@ -0,0 +1,45 @@
use v6;
use Test;

plan 12;

#?pugs todo "cannot roundtrip hashes"
#?niecza todo "cannot roundtrip hashes"
# simple hash
{
my %h = a => 1, b => 2;
is %h.perl, '("a" => 1, "b" => 2).hash',
'can we serialize a simple hash';
my $rh = eval(%h.perl);
is_deeply $rh, %h, 'can we roundtrip simple hash';
ok $rh.of =:= Mu, 'make sure any value can be stored';
ok $rh.keyof =:= Any, 'make sure keys are Any';
} #4

#?pugs todo "cannot roundtrip hashes with constrained values"
#?niecza todo "cannot roundtrip hashes with constrained values"
# hash with constrained values
{
my Int %h = a => 1, b => 2;
is %h.perl, 'Hash[Int].new("a" => 1, "b" => 2)',
'can we serialize a hash with constrained values';
my $rh = eval(%h.perl);
is_deeply $rh, %h, 'can we roundtrip hash constrained values';
ok $rh.of =:= Int, 'make sure roundtripped values are Int';
ok $rh.keyof =:= Any, 'make sure roundtripped keys are Any';
} #4

#?pugs todo "cannot roundtrip hashes with constrained keys & values"
#?niecza todo "cannot roundtrip hashes with constrained keys & values"
# hash with constrained keys & values
{
my Int %h{Str} = a => 1, b => 2;
is %h.perl, 'Hash[Int,Str].new("a" => 1, "b" => 2)',
'can we serialize a hash with constrained keys & values';
my $rh = eval(%h.perl);
is_deeply $rh, %h, 'can we roundtrip hash constrained keys & values';
ok $rh.of =:= Int, 'make sure roundtripped values are Int';
ok $rh.keyof =:= Str, 'make sure roundtripped keys are Str';
} #4

#vim: ft=perl6

0 comments on commit 6127abe

Please sign in to comment.