Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use Test;
- multi sub is ($title, :$got, :$expected) {
- is($got, $expected, $title);
- }
- subtest <Array constructor preserves {} Hash if s followed by a comma>, {
- my $array = [ { a => 1, b => 4 }, ];
- # ^ --- notice comma here
- is <created array contains one element>,
- got => $array.elems,
- expected => 1,
- ;
- is <it creates instance of Array class>,
- got => WHAT($array),
- expected => Array,
- ;
- # ... and so on
- #is WHAT($array[0]), Hash;
- #is $array[0]<a>, 1;
- #is $array[0]<b>, 4;
- }
- subtest <Array constructor flattens {} Hash not followed by a comma into unsorted list of Pairs>, {
- my $array = [ { a => 1, b => 4 } ];
- # ^ --- notice missing comma here
- is <created array contains two elements - Pairs of original Hash>,
- got => $array.elems,
- expected => 2,
- ;
- is <it creates instance of Array class>,
- got => WHAT($array),
- expected => Array,
- ;
- # ... and so on
- #is $array.elems, 2;
- #is WHAT($array), Array;
- #is WHAT($array[0]), Pair;
- #is WHAT($array[1]), Pair;
- # Pairs order is not predictable
- #is $array[0]<a> // $array[1]<a>, 1;
- #is $array[0]<b> // $array[1]<b>, 4;
- }
- done-testing;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement