Skip to content

Commit

Permalink
Test for Hash LoL assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
Mouq committed Feb 4, 2015
1 parent 99bfd5a commit 31571a4
Showing 1 changed file with 44 additions and 8 deletions.
52 changes: 44 additions & 8 deletions S09-subscript/multidim-assignment.t
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
use Test;
plan 15;
plan 10;

{
my @fifties-novels;
@fifties-novels[2 ; 2,3] = "Charlotte's Web", "The Voyage of the Dawn Treader";
is_deeply @fifties-novels,
Array.new(Any, Any, [Any, Any, "Charlotte's Web", "The Voyage of the Dawn Treader"]),
"Autovivifying LoL assignment with multiple final indices";
"Autovivifying LoL assignment on Array with multiple final indices";
}

{
my @fifties-novels;
@fifties-novels[2, 4; 1] = "Charlotte's Web", "The Lord of the Rings";
is_deeply @fifties-novels,
Array.new(Any, Any, [Any, "Charlotte's Web"], Any, [Any, "The Lord of the Rings"]),
"Autovivifying LoL assignment with multiple starting indices";
"Autovivifying LoL assignment on Array with multiple starting indices";
}

{
Expand All @@ -25,23 +25,59 @@ plan 15;
is_deeply @fifties-novels,
Array.new(Any, Any, [Any, Any, "Charlotte's Web", "The Voyage of the Dawn Treader"],
Any, [Any, Any, "The Lord of the Rings", "I Am Legend"]),
"Autovivifying LoL assignment with multiple starting indices and multiple final indices";
"Autovivifying LoL assignment on Array with multiple starting indices and multiple final indices";
}

{
my @lmao-matrix; # an LoL-accessed-Array (obviously)
@lmao-matrix[*; 2] = "";
@lmao-matrix[*; 2] = "whatever";
is_deeply @lmao-matrix, Array.new(),
"Assignment to * slices do nothing on empty, unshaped arrays";
"Assignment on Array to * slices do nothing on empty, unshaped arrays";

@lmao-matrix = [<lists don't>], [<end here>];
@lmao-matrix[*-1, *-2; 1] = <of are>;
is_deeply @lmao-matrix, Array.new([<lists are>], [<end of>]),
"LoL assignment with WhateverCode indices";
"LoL assignment on Array with WhateverCode indices";

@lmao-matrix[*; {$_}; 0, 1] = <appended to each list>;
is_deeply @lmao-matrix, Array.new([<lists are>, [<appended to>]], [<end of>, [<each list>]]),
"Autovivifying LoL assignment with Whatever/Code indices";
"Autovivifying LoL assignment on Array with Whatever/Code indices";
}

{
my %weather;
%weather{<Philadelphia Paris>;<description>} = "Mostly cloudy", "Clear";
is_deeply %weather, {
"Philadelphia" => {"description" => "Mostly cloudy"},
"Paris" => {"description" => "Clear"}
}, "Autovivifying LoL assignment on Hash with multiple starting indices";
}

{
my %weather;
%weather{<Philadelphia>;<tempurature humidity description>} =
7, .54, "Mostly cloudy";
is_deeply %weather, {
"Philadelphia" => {"tempurature" => 7, "humidity" => 0.54, "description" => "Mostly cloudy"},
}, "Autovivifying LoL assignment on Hash with multiple final indices";
}

{
my %weather;
%weather{<Philadelphia Paris>;<tempurature humidity description>} =
7, .54, "Mostly cloudy",
2, .67, "Clear";
is_deeply %weather, {
"Philadelphia" => {"tempurature" => 7, "humidity" => 0.54, "description" => "Mostly cloudy"},
"Paris" => {"tempurature" => 2, "humidity" => 0.67, "description" => "Clear"}
}, "Autovivifying LoL assignment on Hash with multiple starting indices and multiple final indices";
}

{
my %rofl-mapping; # an LoL-accessed-Hash (obviously)
%rofl-mapping{*; <unreachable>} = "whatever";
is_deeply %rofl-mapping, {},
"Assignment on Hash to * slices do nothing on empty, unshaped arrays";
}

# vim: ft=perl6

0 comments on commit 31571a4

Please sign in to comment.