Skip to content

Commit

Permalink
Test that a content change doesn't alter the ID.
Browse files Browse the repository at this point in the history
  • Loading branch information
schwern committed May 9, 2010
1 parent 244c92c commit 66e7266
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 21 deletions.
3 changes: 2 additions & 1 deletion lib/perl5i/Meta.pm
Expand Up @@ -69,10 +69,11 @@ name.
Returns an identifer for $object.
The identifier is guaranteed to be
The identifier is guaranteed to be:
* unique to the object for the life of the process
* a true value
* independent of changes to the object's contents
=head2 class
Expand Down
59 changes: 39 additions & 20 deletions t/Meta/id.t
Expand Up @@ -21,26 +21,45 @@ sub id_ok {
}

# Double up everything to make sure the ID is not based on content
my @objs = (
bless({}, "Foo"),
bless({}, "Foo"),
qr/foo/,
qr/foo/,
sub { 42 },
sub { 42 },
\"string",
\"string",
["foo"],
["foo"],
42,
42,
"string",
"string",
);

for my $obj (@objs) {
my $id = id_ok( $obj );
is $obj->mo->id, $id, " second call the same";
{
my @objs = (
bless({}, "Foo"),
bless({}, "Foo"),
qr/foo/,
qr/foo/,
sub { 42 },
sub { 42 },
\"string",
\"string",
["foo"],
["foo"],
42,
42,
"string",
"string",
);

for my $obj (@objs) {
my $id = id_ok( $obj );
is $obj->mo->id, $id, " second call the same";
}
}


# Test that the id is independent of content
{
my $thing = 42;
my $id = $thing->mo->id;
$thing = 23;
is $thing->mo->id, $id, "ID remains the same for a scalar with changed content";
}

{
my $obj = bless {}, "Foo";
my $id = $obj->mo->id;
$obj->{key} = "value";
is $obj->mo->id, $id, "ID remains the same even if an object's contents change";
}


done_testing();

0 comments on commit 66e7266

Please sign in to comment.