Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 70 additions & 11 deletions Simple-Class/t/Simple-Class.t
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,78 @@ ok(($stdout eq $exp1) || ($stdout eq $exp2), "display() works")
or diag("Got $stdout, expected $exp1 or $exp2");

# Make sure stored data isn't references to *OUR* data
my $dog = 'dog';
{
my $dog = 'dog';

my $obj = Simple::Class->new(
'cat' => $dog,
'bird' => 1,
);
ok($obj, 'Got an object');
isa_ok($obj, 'Simple::Class', 'obj is the correct class');
my $obj = Simple::Class->new(
'cat' => $dog,
'bird' => 1,
);
ok($obj, 'Got an object');
isa_ok($obj, 'Simple::Class', 'obj is the correct class');

$dog = 'not a dog';
$dog = 'not a dog';

# Check hash entries are correct
is($obj->{cat}, 'dog', 'private member cat is correct');
is($obj->{bird}, 1, 'private member bird is correct');
# Check hash entries are correct
is($obj->{cat}, 'dog', 'private member cat is correct');
is($obj->{bird}, 1, 'private member bird is correct');
}

# Make sure stored strings are not terminated with a null
{
my $dog = "Dog \x00 Foo";
my $obj = Simple::Class->new(
$dog => 'Fido',
'bird' => 1,
);
ok($obj, 'Got an object');
isa_ok($obj, 'Simple::Class', 'obj is the correct class');

# Check hash entries are correct
is($obj->{$dog}, $dog, 'private member cat is correct');
}

# Make sure UTF-X strings are stored properly
{
my $dog = "Dog \x{1F415}";
my $obj = Simple::Class->new(
$dog => $dog
);
ok($obj, 'Got an object');
isa_ok($obj, 'Simple::Class', 'obj is the correct class');


is($obj->{$dog}, $dog, 'private member is correct');
}

{
package MyDogNames;
sub TIESCALAR { return bless \(my $i = 0), shift }

sub FETCH {
my ($self) = @_;
return qw(Skip Lassie)[$$self ^= 1];
}
}

# Make sure MAGIC strings are stored properly
{
tie my $name, 'MyDogNames';
my $obj = Simple::Class->new(
$name => "Fido",
);
ok($obj, 'Got an object');
isa_ok($obj, 'Simple::Class', 'obj is the correct class');

# Check hash entries are correct
is($obj->{Lassie}, 'Fido', 'private member is correct');
}

{
use Test::LeakTrace 0.10;
no_leaks_ok {
eval { Simple::Class->new(foo => \1) };
}
}

done_testing;