File: 06-array.t

package info (click to toggle)
libclone-choose-perl 0.010-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 320 kB
  • sloc: perl: 1,295; makefile: 2
file content (42 lines) | stat: -rw-r--r-- 1,529 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!perl

use strict ("subs", "vars", "refs");
use warnings ("all");

use Scalar::Util qw(refaddr);
use Test::More;

BEGIN
{
    $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} and eval "use $ENV{CLONE_CHOOSE_PREFERRED_BACKEND}; 1;";
    $@ and plan skip_all => "No $ENV{CLONE_CHOOSE_PREFERRED_BACKEND} found.";
}

use Clone::Choose;

my $array = [1, ["two", [3, ["four"],],],];
my $cloned_array = clone $array;

ok(refaddr $array != refaddr $cloned_array,                         "Clone depth 0");
ok(refaddr($array->[1]) != refaddr($cloned_array->[1]),             "Clone depth 1");
ok(refaddr($array->[1][1]) != refaddr($cloned_array->[1][1]),       "Clone depth 2");
ok(refaddr($array->[1][1][1]) != refaddr($cloned_array->[1][1][1]), "Clone depth 3");

ok($array->[0] == $cloned_array->[0],                   "Array value depth 0");
ok($array->[1][0] eq $cloned_array->[1][0],             "Array value depth 1");
ok($array->[1][1][0] == $cloned_array->[1][1][0],       "Array value depth 2");
ok($array->[1][1][1][0] eq $cloned_array->[1][1][1][0], "Array value depth 3");

ok($cloned_array->[0] == 1,               "Array value sanity depth 0");
ok($cloned_array->[1][0] eq "two",        "Array value sanity depth 1");
ok($cloned_array->[1][1][0] == 3,         "Array value sanity depth 2");
ok($cloned_array->[1][1][1][0] eq "four", "Array value sanity depth 3");

my $empty_array        = [];
my $cloned_empty_array = clone $empty_array;

ok(refaddr $empty_array != refaddr $cloned_empty_array, "Empty array clone");

done_testing;