File: 10args.t

package info (click to toggle)
libio-socket-ip-perl 0.16-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 232 kB
  • sloc: perl: 1,087; makefile: 2
file content (68 lines) | stat: -rw-r--r-- 2,469 bytes parent folder | download
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
62
63
64
65
66
67
68
#!/usr/bin/perl -w

use strict;
use Test::More;

use IO::Socket::IP;

sub arguments_is {
   my ($arg, $exp, $name) = @_;

   $arg = [$arg]
   unless ref $arg;

   $name ||= join ' ', map { defined $_ ? $_ : 'undef' } @$arg;

   my $got = do {
      no warnings 'redefine';
      my $args;

      local *IO::Socket::IP::_configure = sub {
         $args = $_[1];
         return $_[0];
      };

      IO::Socket::IP->new(@$arg);

      $args;
   };

   is_deeply($got, $exp, $name);
}

my @tests = (
   [ [ '[::1]:80'               ], { PeerHost  => '::1',           PeerService => '80'    } ],
   [ [ '[::1]:http'             ], { PeerHost  => '::1',           PeerService => 'http'  } ],
   [ [ '[::1]'                  ], { PeerHost  => '::1',                                  } ],
   [ [ '[::1]:'                 ], { PeerHost  => '::1',                                  } ],
   [ [ '127.0.0.1:80'           ], { PeerHost  => '127.0.0.1',     PeerService => '80'    } ],
   [ [ '127.0.0.1:http'         ], { PeerHost  => '127.0.0.1',     PeerService => 'http'  } ],
   [ [ '127.0.0.1'              ], { PeerHost  => '127.0.0.1',                            } ],
   [ [ '127.0.0.1:'             ], { PeerHost  => '127.0.0.1',                            } ],
   [ [ 'localhost:80'           ], { PeerHost  => 'localhost',     PeerService => '80'    } ],
   [ [ 'localhost:http'         ], { PeerHost  => 'localhost',     PeerService => 'http'  } ],
   [ [ PeerHost  => '[::1]:80'  ], { PeerHost  => '::1',           PeerService => '80'    } ],
   [ [ PeerHost  => '[::1]'     ], { PeerHost  => '::1'                                   } ],
   [ [ LocalHost => '[::1]:80'  ], { LocalHost => '::1',           LocalService => '80'   } ],
   [ [ LocalHost => undef       ], { LocalHost => undef                                   } ],
);

plan tests => 4 + scalar(@tests);

is_deeply( [ IO::Socket::IP->split_addr( "hostname:http" ) ],
           [ "hostname",  "http" ],
           "split_addr hostname:http" );

is_deeply( [ IO::Socket::IP->split_addr( "192.0.2.1:80" ) ],
           [ "192.0.2.1", "80"   ],
           "split_addr 192.0.2.1:80" );

is_deeply( [ IO::Socket::IP->split_addr( "[2001:db8::1]:80" ) ],
           [ "2001:db8::1", "80" ],
           "split_addr [2001:db8::1]:80" );

is_deeply( [ IO::Socket::IP->split_addr( "something.else" ) ],
           [ "something.else", undef ],
           "split_addr something.else" );

arguments_is(@$_) for @tests;