6 use Test::More tests => 9;
9 my $array = [ qw(1 2 3 4 ) ];
13 "flattening an array returns a list",
16 my $hash = { a => 1, b => 2 };
18 [ sort $hash->flatten ],
20 "flattening a hash returns a list",
27 "flattening a scalar returns the scalar",
30 my $scalar_ref = \$scalar;
32 [ $scalar_ref->flatten ],
34 "flattening a reference to a scalar returns the same scalar reference",
37 # flatten_deep on array
39 [ 1 .. 9 ]->flatten_deep,
41 "default flatten_deep on shallow array returns correct array"
45 [ [ 1 .. 3 ], [[ 4 .. 6 ]], [[[ 7 .. 9 ]]] ]->flatten_deep,
47 "default flatten_deep on array with depth completely flattens array"
51 [ [ 1 .. 3 ], [[ 4 .. 6 ]], [[[ 7 .. 9 ]]] ]->flatten_deep(undef),
53 "flatten_deep with an undef argument on array with depth completely flattens array"
57 [ [ 1 .. 3 ], [[ 4 .. 6 ]], [[[ 7 .. 9 ]]] ]->flatten_deep(0),
58 [ [ 1 .. 3 ], [[ 4 .. 6 ]], [[[ 7 .. 9 ]]] ],
59 "flatten_deep with depth 0 specified on array returns array unchanged"
63 [ [ 1 .. 3 ], [[ 4 .. 6 ]], [[[ 7 .. 9 ]]] ]->flatten_deep(2),
64 [ 1 .. 6, [ 7 .. 9 ] ],
65 "flatten_deep with depth specified returns correct array"