File: clone.t

package info (click to toggle)
libreadonly-perl 2.050-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 216 kB
  • sloc: perl: 871; makefile: 2
file content (53 lines) | stat: -rw-r--r-- 1,420 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
43
44
45
46
47
48
49
50
51
52
53
# Readonly clone tests
use strict;
use warnings;
use Test::More;
use lib '../../lib';
use Readonly;
#
Readonly::Scalar my $scalar => 13;
Readonly::Array my @array => (1, 2, 3);
Readonly::Hash my %hash => (foo => 'bar');
Readonly::Array my @deep_array => (1, \@array);
Readonly::Hash my %deep_hash => (foo => \@array);
#
my $scalar_clone = Readonly::Clone $scalar;
$scalar_clone++;
is $scalar_clone, 14;
#
my @array_clone = Readonly::Clone @array;
$array_clone[1] = 4;
is $array_clone[1], 4;
#
my %hash_clone = Readonly::Clone %hash;
$hash_clone{foo} = 'baz';
is $hash_clone{foo}, 'baz';
#
my @deep_array_clone = Readonly::Clone @deep_array;
$deep_array_clone[1]->[2] = 4;
is $deep_array_clone[1]->[2], 4;
#
my %deep_hash_clone = Readonly::Clone %deep_hash;
$deep_hash_clone{foo}->[1] = 4;
is $deep_hash_clone{foo}->[1], 4;
#
{
    Readonly::Scalar my $scalar => ['string'];
    my $scalar_clone = Readonly::Clone $scalar;
    push @$scalar_clone, 'foo';
    is_deeply $scalar_clone, [qw[string foo]];
}
{
    Readonly::Scalar my $scalar => {qw[this that]};
    my $scalar_clone = Readonly::Clone $scalar;
    $scalar_clone->{'eh'} = 'foo';
    is_deeply $scalar_clone, {this => 'that', eh => 'foo'};
}
{
    Readonly::Scalar my $scalar => {qw[this that]};
    my %scalar_clone = Readonly::Clone $scalar;
    $scalar_clone{'eh'} = 'foo';
    is_deeply [\%scalar_clone], [{this => 'that', eh => 'foo'}];
}
#
done_testing;