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 54 55 56 57 58 59 60 61
|
package Pithub::Test;
use strict;
use warnings;
use Import::Into;
use Test::Builder ();
use Test::Differences qw( eq_or_diff );
use Test::More import => [qw( diag is )];
BEGIN {
## no critic (ClassHierarchies::ProhibitExplicitISA, Modules::ProhibitAutomaticExportation)
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(uri_is);
}
sub import {
my $class = shift;
my $caller = caller;
Test::Most->import::into($caller);
$class->export_to_level( 1, @_ );
}
sub uri_is {
my ( $have, $want, $name ) = @_;
local $Test::Builder::Level = $Test::Builder::Level + 1;
$have = _make_uri($have);
$want = _make_uri($want);
for my $method (qw(scheme authority path fragment)) {
my $have_val = $have->$method;
my $want_val = $want->$method;
next if !defined $have_val && !defined $want_val;
if ( ( defined $have_val xor defined $want_val )
|| ( $have_val ne $want_val ) ) {
return is( $have, $want, $name ) || diag "$method does not match";
}
}
my %have_queries = $have->query_form;
my %want_queries = $want->query_form;
return eq_or_diff( \%have_queries, \%want_queries, $name )
|| diag "$have ne $want, queries do not match";
}
sub _make_uri {
my $uri = shift;
return $uri if ref $uri && $uri->isa('URI');
require URI;
return URI->new($uri);
}
1;
|