#!/usr/bin/perl
BEGIN {
$| = 1;
$^W = 1;
}
my
$path1
= catdir( rootdir(),
'foo'
);
my
$path2
= catdir( rootdir(),
'foo2'
);
my
$path3
= catfile( rootdir(),
'foo'
,
'foo'
,
'bar.txt'
);
my
$path4
= catdir( rootdir(),
'foo'
,
'foo'
,
'bar'
);
is_normal_location(
$location
);
is(
$location
->path,
$path1
,
'->path gives expected value'
);
isa_ok(
$location
->URI,
'URI'
);
isa_ok(
$location
->__as_URI,
'URI'
);
is( (
$location
->__eq(
$location2
)), 1,
'->__eq returns true correctly'
);
is( (
$location
->__eq(
$location3
)),
''
,
'->__eq returns false correctly'
);
is( (
$location
->__eq(
$location4
)),
''
,
'->__eq returns false correctly'
);
is( (
$location
->__eq(
undef
)),
''
,
'->__eq returns false correctly'
);
is( (
$location
->__eq()),
''
,
'->__eq returns false correctly'
);
is( (
$location
eq
$location2
), 1,
'eq returns true correctly'
);
is( (
$location
eq
$location3
),
''
,
'eq returns false correctly'
);
is( (
$location
eq
$location4
),
''
,
'eq returns false correctly'
);
is( (
$location
eq
undef
),
''
,
'eq returns false correctly'
);
is( (
$location2
eq
$location
), 1,
'eq returns true correctly'
);
is( (
$location3
eq
$location
),
''
,
'eq returns false correctly'
);
is( (
$location4
eq
$location
),
''
,
'eq returns false correctly'
);
is( (
undef
eq
$location
),
''
,
'eq returns false correctly'
);
is(
$location
,
$location
,
'Two locations match'
);
my
$clone
=
$location
->clone;
is_normal_location(
$clone
);
is(
$clone
->path,
$path1
,
'->path gives expected value'
);
isnt( refaddr(
$clone
), refaddr(
$location
),
'Clone is different to original'
);
my
$param1
= HTML::Location->param(
$location
);
isa_ok(
$param1
,
'HTML::Location'
);
is( refaddr(
$param1
), refaddr(
$location
),
'->param(Location) returns the same location'
);
is_deeply(
$param1
,
$location
,
'Locations match'
);
isa_ok(
$param2
,
'HTML::Location'
);
is_deeply(
$param2
,
$location
,
'Locations match'
);
isa_ok(
$param3
,
'HTML::Location'
);
is_deeply(
$param3
,
$location
,
'Locations match'
);
my
$file
=
$location
->catfile(
'foo'
,
'bar.txt'
);
is_normal_location(
$file
);
isnt( refaddr(
$location
), refaddr(
$file
),
'->catfile returns a new object'
);
is(
$file
->path,
$path3
,
'->path gives expected value'
);
is_normal_location(
$location
);
is(
$location
->path,
$path1
,
'->path gives expected value'
);
my
$dir
=
$location
->catdir(
'foo'
,
'bar'
);
is_normal_location(
$file
);
isnt( refaddr(
$location
), refaddr(
$dir
),
'->catfile returns a new object'
);
is(
$dir
->path,
$path4
,
'->path gives expected value'
);
is_normal_location(
$location
);
is(
$location
->path,
$path1
,
'->path gives expected value'
);
exit
();
sub
is_normal_location {
my
$object
=
shift
;
ok(
defined
$object
,
'->new returns defined'
);
ok(
$object
,
'->new returns true'
);
isa_ok(
$object
,
'HTML::Location'
);
ok(
defined
$object
->path,
'->path returns defined'
);
ok( !
ref
$object
->path,
"->path doesn't return a reference"
);
ok(
length
$object
->path,
"->path doesn't return a zero length string"
);
ok(
defined
$object
->URI,
"->URI returns defined"
);
ok(
ref
$object
->URI,
"->URI returns a reference"
);
isa_ok(
$object
->URI,
'URI'
);
isnt( refaddr(
$object
->URI), refaddr(
$object
->URI),
'->URI returns a clone'
);
ok(
defined
$object
->uri,
'->uri returns defined'
);
ok( !
ref
$object
->uri,
"->uri doesn't return a reference"
);
ok(
length
$object
->uri,
"->uri doesn't return a null string"
);
ok(
length
"$object"
,
"Location stringifies to a non-null string"
);
is(
$object
->uri,
"$object"
,
"Location stringifies to the ->uri value"
);
}
1;