File: Test.pm

package info (click to toggle)
libpithub-perl 0.01033-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 928 kB
  • ctags: 321
  • sloc: perl: 3,282; makefile: 7
file content (56 lines) | stat: -rw-r--r-- 1,212 bytes parent folder | download | duplicates (3)
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
package Pithub::Test;

use Import::Into;
use Test::Most;

BEGIN {
    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;